// pageTracker._trackEvent("Send Email Cancel", "click", "Home Page", ""); put this in reset call 
// Business ID of Tel Us
var bid=26;//26; 

$(document).ready(function(){
	$("#mypopup").hide();
	$("#emailme").click(function(){
		$("#mypopup").centerInClient();
		$("#mypopup").show();
		return false;
	});
	$(window).scroll(function(){
		if($("#mypopup").is(':visible')){
			$("#mypopup").centerInClient();
		}
	});
	
}); // 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;
	}
	var othervariables='&visit_email_name='+$("#visit_email_name").val()+
	'&visit_Coments='+$("#visit_Coments").val()+
	'&visit_email='+$("#visit_email").val();
	if($("#sitename").val() == "Home"){
		$.get('../../stats/mainMail.php?bid=' + bid + '&' + $("#frmMat").serialize()+othervariables);
	}else{
		$.get('../../../stats/mainMail.php?bid=' + bid + '&' + $("#frmMat").serialize()+othervariables);
	}
	
	alert("Thanks! Your email has been sent.");
 	 _mw._trackAction('3', $('#visit_email').val() +'|'+ $('#visit_Coments').val() + '|' + $("#visit_email_name").val());
	//pageTracker._trackPageview('/email.php'); 
	resetMyPopUp();
}

function checkvalidation()
{
if($("#visit_name").val()=="" || $("#visit_name").val().match("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;
}
$("#inputboxes").hide();
$("#messagebox").show();

if($("#sitename").val() == "Home"){
	$.get('../../stats/mainMail.php?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}else{
	$.get('../../../stats/mainMail.php?bid='+bid+'&cb=1&'+ $("#frmMat").serialize());
}

 //pageTracker._trackPageview('/callBack.php');
_mw._trackAction('2', $('#visit_name').val() +'|'+ $('#visit_number').val());
setTimeout('thanksmsg()',5000);

}

function thanksmsg(){
$("#visit_name").val("Name");
$("#visit_number").val("Number");
$("#messagebox").hide();
$("#inputboxes").show();
}


function chkAjaxCall(RandomNo,StoreName)
	{

		//_mw._trackAction('4', RandomNo+'|'+StoreName);
		if($("#sitename").val() != 'Home'){
 			$.get('../../../../stats/mainMail.php?bid='+bid+'&RN='+RandomNo+'&sitename='+$("#sitename").val());
		}
		else{
			$.get('../../../stats/mainMail.php?bid='+bid+'&RN='+RandomNo+'&sitename='+$("#sitename").val());	
		}
		window.print();
		
	}





function resetMyPopUp()
{
	$("#visit_Coments").val("");
	$("#visit_email").val("");
	$("#visit_email_name").val("");	
	$("#mypopup").hide();
}
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: true,
                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);
    });
}
