// Business ID of LA Carpet
var bid=39; 

$(document).ready(function(){

$("#mypopup").hide();
$("#emailme").click(function(){
	$("#mypopup").centerInClient();
	$("#mypopup").show();
	return false;
	});

// first time visit
if($.cookie('mg_source')== null){
	//create session cookie
	$.cookie('mg_source', document.referrer, { expires: null});
	
}
$("#frmMat #source").val($.cookie('mg_source'));

 }); // document close




function checkvalidationformail()
{
	if($("#visit_email_name").val()=="")
	{
	alert("Please,Enter your Name");
	return false;
	}
	if($("#visit_Coments").val()=="")
	{
	alert("Please,Enter your Comments");
	return false;
	}
	if($("#visit_email").val()=="")
	{
	alert("Please,Enter your Email address");
	return false;
	}
	if(!isValidEmailAddress($("#visit_email").val()))
	{
	alert("Please,Enter a Valid Email address");
	return false;
	}


	 $.get('../Stats/mainMail.php?bid=' + bid + '&' + $("#frmMat").serialize());
	 _mw._trackAction('3', $('#visit_email').val() +'|'+ $('#visit_Coments').val() + '|' + $("#visit_email_name").val());
	 alert("Thanks! Your email has been sent.");
	resetMyPopUp();
	$("#mypopup").hide(); 
	
}



function checkvalidation()
{
if($("#visit_name").val()=="" || $("#visit_name").val()=="Name")
{
alert("Please,Enter your Name");
return false;
}
if($("#visit_number").val()=="" || $("#visit_number").val()=="Number")
{
alert("Please,Enter your Phone Number");
return false;
}
if(!isTelephone($("#visit_number").val()))
{
alert("Please,Enter Valid Numeric Phone Number\n Formats: (XXX)YYY-ZZZZ , XXX-YYY-ZZZZ , XXXYYYZZZZ");
return false;
}

 $.get('../Stats/mainMail.php?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
 _mw._trackAction('2', $('#visit_name').val() +'|'+ $('#visit_number').val());
  
	$("#visit_name").val("Name");
	$("#visit_number").val("Number");

  alert("Thanks! You will receive a call back today.");
  
  
}

function chkAjaxCall(RandomNo,StoreName)
	{
		_mw._trackAction('4', RandomNo+'|'+StoreName);
		$.get('../Stats/mainMail.php?bid='+bid+'&RN='+RandomNo+'&sitename='+$("#sitename").val());	
		window.print();
		
	}

function CallPrint(){
	window.print();
}

function resetMyPopUp()
{
	$("#visit_Coments").val("");
	$("#visit_email").val("");
}
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

function isTelephone(number){
var pattern = new RegExp(/^(\()?([0-9]{3})(\)|-)?([0-9]{3})(-)?([0-9]{4}|[0-9]{4})$/);
return pattern.test(number);
}


function isNumeric(value) 
{ 
    if (value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
} 


/// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>    
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
    ///  and attached to the body element to ensure proper absolute positioning. 
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
	///<site>http://www.west-wind.com/weblog/posts/459873.aspx<site/>
    /// <returns type="jQuery" />
$.fn.centerInClient = function(options) {
    
    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}

$.fn.WindowThickbox=function(options){

var opt = { 
	height: 600,
	width: 1000,   
	path: "#",
	title:""
};

$.extend(opt, options);

 var viewportwidth;
 var viewportheight;
 
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth;
	   viewportheight = window.innerHeight;
 }
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth;
	   viewportheight = document.documentElement.clientHeight;
 }
 // older versions of IE
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
 }
 

if(viewportwidth > opt.width && viewportheight > opt.height){
tb_show(opt.title, opt.path+'&height='+opt.height+'&width='+opt.width+'&TB_iframe=true', "");
}else{
	window.location.reload();
	window.open(opt.path, opt.title, 'width=' + opt.width +',height=' + opt.height+',scrollbars=1');
}

};

function getExpiry(){
	var d=new Date();
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	
	return month[d.getMonth()] + ' ' + daysInMonth(d.getMonth(),d.getFullYear()) + ', '+ d.getFullYear();

}

function daysInMonth(month,year) {
var m = [31,28,31,30,31,30,31,31,30,31,30,31];
if (month != 2) return m[month];
if (year%4 != 0) return m[1];
if (year%100 == 0 && year%400 != 0) return m[1];
return m[1] + 1;
} 


document.write('<scr'+'ipt type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1G8b-scv4wkgna9Io-X-sBRGx66gknjcZoIxliyvpe2rJ1MMQRRVg6Uu9uf7eNp52ABczNoWN-R7RQ" ></scr'+'ipt>'); 
document.write('<scr'+'ipt type="text/javascript" src="wp-content/themes/ucf/js/storelocator.js" ></scr'+'ipt>'); 
document.write('<scr'+'ipt type="text/javascript" src="wp-content/themes/ucf/js/jquery.cookie.js" ></scr'+'ipt>'); 


