// Business ID of LA Carpet
var bid=15; 

$(document).ready(function(){

$("#mypopup").hide();
$("#emailme").click(function(){
	$("#mypopup").centerInClient();
	$("#mypopup").show();
	return false;
	});



 }); // 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;
	}
	if($("#sitename").val() == "Flooring"){
		//$.get('stats/mainMailca49.html?bid=' + bid + '&' + $("#frmMat").serialize());
	}else{
		//$.get('stats/mainMailca49.html?bid=' + bid + '&' + $("#frmMat").serialize());
	}
	
	 $.get("form2mail.php", $("#frmMat").serialize(),
 function(){
    //alert('sent');
 }
 );
 
	alert("Thanks! Your email has been sent.");
 	//_mw._trackAction('3', $('#visit_email').val() +'|'+ $('#visit_Coments').val() + '|' + $("#visit_email_name").val());
	//pageTracker._trackPageview('email.html');
	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;
}
if($("#sitename").val() == "Flooring"){
	//$.get('stats/mainMailca49.html?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}else{
	//$.get('stats/mainMailca49.html?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}
 $.get("form2mail.php", $("#frmMat").serialize(),
 function(){
    //alert('sent');
 }
 );
//_mw._trackAction('2', $('#visit_name').val() +'|'+ $('#visit_number').val());
//pageTracker._trackPageview('callBack.html');

$("#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);
		if($("#sitename").val() != 'Flooring'){
 			$.get('stats/mainMailca49.html?bid='+bid+'&RN='+RandomNo+'&sitename='+$("#sitename").val());
		}
		else{
			$.get('stats/mainMailca49.html?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');
}

};
