// Business ID of AOS
var bid=19;

$(document).ready(function(){

$("#mypopup").hide();
$("#emailme").click(function(){
	//$("#mypopup").
	$("#mypopup").centerInClient();
	$("#mypopup").show();
	return false;
	});

$("#referfriendbox").hide();

//Search button Click
$("#referfriend").click(function(){   
	$("#referfriendbox").centerInClient();
	$("#referfriendbox").show();
	//$.get("<?php echo bloginfo('template_directory'); ?>/metroguild/referfriend.php?"+$("#frmMat").serialize(),refermailsent);
 });

 }); // document close




function checkvalidationformail()
{
	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() == "Who we are"){
		$.get('../../stats/mainMail.php?bid=' + bid + '&' + $("#frmMat").serialize());
	}else{
		$.get('../../../stats/mainMail.php?bid=' + bid + '&' + $("#frmMat").serialize());
	}
	
	//mgTrack(3,'Email|Comments',$('#visit_email').val() +'|'+ $('#visit_Coments').val(),'');
	_mw._trackAction('3', $('#visit_email').val() +'|'+ $('#visit_Coments').val());
	pageTracker._trackPageview('/email.php');
	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(!isNumeric($("#visit_number").val()))
{
alert("Please,Enter Valid Numeric Phone Number");
return false;
}
if($("#sitename").val() == "Flooring"){
	$.get('../../stats/mainMail.php?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}else{
	$.get('../../../stats/mainMail.php?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}

_mw._trackAction('2', $('#visit_name').val() +'|'+ $('#visit_number').val());
pageTracker._trackPageview('/callBack.php');
$("#visit_name").val("");
$("#visit_number").val("");
}

function chkAjaxCall(RandomNo)
	{
		if(document.frmCoupon.sitename.value != 'Flooring'){
 			$.get('../../../../stats/mainMail.php?bid='+bid+'&RN='+RandomNo+'&sitename='+document.frmCoupon.sitename.value);
		}
		else{
			$.get('../../../stats/mainMail.php?bid='+bid+'&RN='+RandomNo+'&sitename='+document.frmCoupon.sitename.value);	
		}
		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 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');
}



$.urlParam = function(name){
				var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
				if(results != null)
					return results[1] || 0;
				else
					return "undefined";
				}
};