
var thisLoc = location.host;
var sep = thisLoc.indexOf(".");
var pre = thisLoc.substr(0,sep);

function removeCal(){
    $(this).text('Re-attach').siblings('.datepicker').datepick('destroy');
}
function sendEmail(form1)
{
	jsform=form1;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var dob=document.frmFeedback.dob.value;
    var quest=document.frmFeedback.question.value;
    var emailFrom=document.frmFeedback.email.value;
    var fromName=document.frmFeedback.name.value;
    var dobVal = /(0[1-9]|1[012])+\/(0[1-9]|[12][0-9]|3[01])+\/(19|20)\d\d/;
    if(dob== "" || dob== null ||
    quest =="" || quest== null ||
    emailFrom =="" || emailFrom== null)
    {
    	$("#errorMes").html("Please fill out all the form elements to send Email.");
    	return false;
    }
	else if(reg.test(emailFrom) == false)
    {
    	$("#errorMes").html("The email address is not valid.");
    	$("#email").focus();
    	return false;
    }else if (dobVal.test(dob) == false) {
        $("#errorMes").html("Please enter a valid date. (MM/DD/YYYY)");
        $("#dob").focus();
    }else    {   
        //$("#errorMes").html("Email Sent");
//     	var subject=emailFrom+' just emailed you from the feeback form.';
//     	var requestUrl='http://'+pre+'.agkizone.com/send_mail.action?emailFrom=share@agkidzone.com&emailTo=jvanarsdale@ag.com&emailTemplate=mb_sendto_friend_email&subject='+subject+'&targetUrl=http://'+pre+'.agkidzone.com&receiverName=CustomerService&senderName=JohnVanArsdale';
//    	sendFeedback(requestUrl);
    	var target="feedback";
     	var subject='Inquiry from '+fromName+'!';
        var requestUrl='http://'+pre+'.madballs.com/send_mail.action?emailFrom='+emailFrom+'&emailTemplate=mb_customer_service&subject='+subject+'&senderName='+fromName+'&question='+quest+'&dob='+dob+'&prefix='+pre+'&target='+target+'&targetUrl=http://'+pre+'.agkidzone.com';        

        //alert("requestUrl=="+requestUrl);
        sendFeedback(requestUrl)
        
    }
    
}

function sendFeedback(requestUrl)
{
    var emailStr="";
    jQuery.post(requestUrl, function(data) {
    	var temp = new Array();
		temp = data.split(' ');
        if(temp[1].charAt(0) == "P")

    	{        		
    		$("#errorMes").html("Error sending email. Please try again");
    	}
    	else
    	{        		
    		$("#errorMes").html("Email sent successfully. Thank you.");
    		document.frmFeedback.question.value="";
		    document.frmFeedback.email.value="";	 
		    document.frmFeedback.name.value="";	 
		    document.frmFeedback.dob.value="";
		    setTimeout ('$.facebox.close();', 2500 );

    	}
			 	   		
    })     
}
//$(document).ready(function(){
//    $('a[href*=#]').click(function() {
//        if (location.pathname.replace("/^\//,''") == this.pathname.replace("/^\//,''")
//        && location.hostname == this.hostname) {
//        var $target = $(this.hash);
//        $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
//            if ($target.length) {
//                var targetOffset = $target.offset().top;
//                $('html,body')
//                .animate({scrollTop: targetOffset}, 1000);
//                return false;
//            }
//        }
//    });
//});




function showCOPA(){
    
    $("#copa").slideDown("slow")
    $("#copa").css({display:"block"});
    
}
function closeDiv(){
    $("#copa").slideUp("medium")
}
// swap image functions for button mouseovers
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
};
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
};
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
};
