// JavaScript Document

var trim=function(str){
	return str.replace(/^\s+|\s+$/g,''); 
}

var vemail=function(str)	{
 var reg = /^([A-Za-z0-9_\-\.]+)\@([A-Za-z0-9_\-\.]+)\.([A-Za-z]{2,4})$/;
 return reg.test(str);
}

var textbox_defaultword=function(obj,searchword,replaceword)	{
	var textbox=obj.value;
		if(textbox==searchword)
			obj.value=replaceword;
}



function rce(obj)	{
	input=trim(obj.value);
	obj.value=input.replace(/\s{2,}/g,' ');
}

jQuery(document).ready(function()	{

jQuery.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return jQuery(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   //this.selectedIndex = -1;
   this.selectedIndex = 0;
  });
};

jQuery.fn.ajaxForms = function(url,type,data,errorlistid,errortable,successtableid,formname) {
		 return jQuery.ajax({
	                url: url,
	                type: type,
	                data: data,
	                success: function(resp) {
					
					if(resp!='success')	{
						jQuery("#"+errorlistid).html(resp);
						jQuery("#"+errortable).show(200);
						jQuery("#"+successtableid).hide();
						
						return 'fail';
						
					}	else	{
						//alert(formname);
						if(formname!='giftform')	{
						jQuery("#"+errortable).hide();
						jQuery("#"+successtableid).show(200);
						jQuery("#"+formname).clearForm();
						}
						if(formname=='giftform')	{
							
							jQuery('#viamail').attr('checked', true);	
							
							//trim(jQuery("#hiddenpage").val())+"/payment.php?action=pay";
							var paymenturl=trim(jQuery("#hiddenpage").val())+'/payment.php?action=pay';
							//alert(paymenturl);
							window.location.href = paymenturl;
							//$(location).attr('href', paymenturl);

						}



						return 'success';
					}
					
					
				alert(resp);
				
	              //$('#ajaxResponse').append(result);
                 }
	       });
		  
		  return 'none';

};


/*  Contact Form Utility          */
jQuery('#contactsubmit').click(function(){
										
var err='';
var msg='';
var contact_name=trim(jQuery("#contact_name").val());
//var company_name=trim(jQuery("#company_name").val());
var email=trim(jQuery("#email").val());
var phone=trim(jQuery("#phone").val());
var city=trim(jQuery("#city").val());
var state=trim(jQuery("#state").val());
var comments=trim(jQuery("#comments").val());
var hiddenurl=trim(jQuery("#hiddenpage").val());
if (contact_name.length<1)	{
	err+='<li>Contact Name: Please enter valid Contact Name</li>';
}
if (email.length<1 || vemail(email)!=true)	{
	err+='<li>Email Address: Please enter valid Email Address</li>';
}
if (phone.length<1)	{
	err+='<li>Phone Number: Please enter valid Phone Number</li>';
}
if (comments.length<1)	{
	err+='<li>Questions/Comments: Please enter valid Questions/Comments</li>';
}

if(err!='')	{
						jQuery('#contacterror').html(err);
						jQuery('#contact_err_table').show(200);
						jQuery('#contact_success_table').hide();
						 return false;
}	else	{

//jQuery("#lightbox_wp").fadeIn(300);
hiddenurl=hiddenurl+"/sidebar_ajaxpage.php";

data="formtype=contactform&contact_name="+contact_name+"&phone="+phone+"&email="+email+"&state="+state+"&city="+city+"&comments="+comments+"&sid="+Math.random();
jQuery("#lightbox_wp").fadeIn(300);
msg=jQuery(this).ajaxForms(hiddenurl,"POST",data,"contacterror","contact_err_table","contact_success_table",'contactfrm');
//alert(msg);
if(msg!='')
	jQuery("#lightbox_wp").fadeOut(300);
return false;
}


})
/*  End Contact Form Utility          */

/*  Estimate Form Utility          */
jQuery('#estimatesubmit').click(function(){
										
var err='';
var msg='';
var name=trim(jQuery("#name").val());
var email=trim(jQuery("#email").val());
var phone=trim(jQuery("#phone").val());
var address=trim(jQuery("#address").val());
var city=trim(jQuery("#city").val());
var square_footage_space=trim(jQuery("#square_footage_space").val());

var no_of_bedrooms=trim(jQuery("#no_of_bedrooms").val());
var no_of_3piece_bathroom=trim(jQuery("#no_of_3piece_bathroom").val());
var no_of_2piece_bathroom=trim(jQuery("#no_of_2piece_bathroom").val());

var hiddenurl=trim(jQuery("#hiddenpage").val());

if (name.length<1)	{
	err+='<li>Name: Please enter valid Name</li>';
}
if (email.length<1 || vemail(email)!=true)	{
	err+='<li>Email Address: Please enter valid Email Address</li>';
}
if (phone.length<1)	{
	err+='<li>Phone Number: Please enter valid Phone Number</li>';
}
if (address.length<1)	{
	err+='<li>Street Address: Please enter valid Street Address</li>';
}
if (city.length<1)	{
	err+='<li>City: Please enter valid City</li>';
}
if (square_footage_space.length<1)	{
	err+='<li>Square footage of space: Please enter valid Square footage of space</li>';
}

if (no_of_bedrooms.length<1)	{
	err+='<li># of bedrooms: Please enter valid # of bedrooms</li>';
}
if (no_of_3piece_bathroom.length<1)	{
	err+='<li># of 3 piece bathrooms: Please enter valid # of 3 piece bathrooms</li>';
}
if (no_of_2piece_bathroom.length<1)	{
	err+='<li># of 2 piece bathrooms: Please enter valid # of 2 piece bathrooms</li>';
}

if(err!='')	{
						jQuery('#estimateerror').html(err);
						jQuery('#estimate_err_table').show(200);
						jQuery('#estimate_success_table').hide();
						 return false;
}	else	{

//jQuery("#lightbox_wp").fadeIn(300);
hiddenurl=hiddenurl+"/sidebar_ajaxpage.php";

data="formtype=estimateform&name="+name+"&phone="+phone+"&email="+email+"&address="+address+"&city="+city+"&square_footage_space="+square_footage_space+"&no_of_bedrooms="+no_of_bedrooms+"&no_of_3piece_bathroom="+no_of_3piece_bathroom+"&no_of_2piece_bathroom="+no_of_2piece_bathroom+"&sid="+Math.random();
jQuery("#lightbox_wp").fadeIn(300);
msg=jQuery(this).ajaxForms(hiddenurl,"POST",data,"estimateerror","estimate_err_table","estimate_success_table",'estimatefrm');
//alert(msg);
if(msg!='')
	jQuery("#lightbox_wp").fadeOut(300);
return false;
}


})

/*  End Estimate Form Utility          */


/*  Gift Form Utility          */
jQuery('#giftsubmit').click(function()	{
										
var err='';
var msg='';
var name=trim(jQuery("#name").val());


var street=trim(jQuery("#street").val());

var city=trim(jQuery("#city").val());
var province=trim(jQuery("#province").val());
var postal_code=trim(jQuery("#postal_code").val());
var phone=trim(jQuery("#phone").val());
var email=trim(jQuery("#email").val());

//Receipient
var recipient_name=trim(jQuery("#recipient_name").val());
var recipient_street=trim(jQuery("#recipient_street").val());
var recipient_city=trim(jQuery("#recipient_city").val());
var recipient_province=trim(jQuery("#recipient_province").val());
var recipient_postal_code=trim(jQuery("#recipient_postal_code").val());
var recipient_phone=trim(jQuery("#recipient_phone").val());
var recipient_email=trim(jQuery("#recipient_email").val());
//gift info
var amount=trim(jQuery("#amount").val());
var special_note=trim(jQuery("#special_note").val());
//Check email
var viaemail=(jQuery('#viaemail').is(':checked'))?jQuery('#viaemail').val():'';
var viamail=(jQuery('#viamail').is(':checked'))?jQuery('#viamail').val():'';




var hiddenpageurl=trim(jQuery("#hiddenpage").val());

if (name.length<1)	{
	err+='<li>Name: Please enter valid Name</li>';
}
if (street.length<1)	{
	err+='<li>Street: Please enter valid Street</li>';
}
if (city.length<1)	{
	err+='<li>City: Please enter valid City</li>';
}
if (province.length<1)	{
	err+='<li>Province: Please enter valid Province</li>';
}

if (postal_code.length<1)	{
	err+='<li>Postal Code: Please enter valid Postal Code</li>';
}
if (phone.length<1)	{
	err+='<li>Phone Number: Please enter valid Phone Number</li>';
}

if (email.length<1 || vemail(email)!=true)	{
	err+='<li>Email Address: Please enter valid Email Address</li>';
}
//rerr
if (recipient_name.length<1)	{
	err+='<li>Recipient\'s Name: Please enter valid Recipient\'s Name</li>';
}
if (recipient_street.length<1)	{
	err+='<li>Recipient\'s Street: Please enter valid Recipient\'s Street</li>';
}
if (recipient_city.length<1)	{
	err+='<li>Recipient\'s City: Please enter valid Recipient\'s City</li>';
}
if (recipient_province.length<1)	{
	err+='<li>Recipient\'s Province: Please enter valid Recipient\'s Province</li>';
}

if (recipient_postal_code.length<1)	{
	err+='<li>Recipient\'s Postal Code: Please enter valid Recipient\'s Postal Code</li>';
}
if (recipient_phone.length<1)	{
	err+='<li>Recipient\'s Phone: Please enter valid Recipient\'s Phone</li>';
}
if (recipient_email.length<1 || vemail(recipient_email)!=true)	{
	err+='<li>Recipient\'s Email: Please enter valid Recipient\'s Email</li>';
}
if (amount.length<1)	{
	err+='<li>Amount: Please enter valid Amount</li>';
}
//alert(parseFloat(amount));
else if (parseFloat(amount)==null || parseFloat(amount)=='NaN')	{
	err+='<li>Amount: Please enter valid Amount</li>';
}
/*
}else if (parseInt(amount)<1)	{
	err+='<li>Amount: Please enter valid Amount</li>';
}
*/
if ((viaemail.length<1 && viamail.length<1) || (viaemail.length>0 && viamail.length>0) )	{
	err+='<li>Email or Mail: Please check  one gift certificate options</li>';
}
//alert(amount);
if(err!='')	{
	
						jQuery('#gifterror').html(err);
						jQuery('#gift_err_table').show(200);
						jQuery('#gift_success_table').hide();
						 return false;
						 
}	else	{
//jQuery("#lightbox_wp").fadeIn(300);
hiddenurl=hiddenpageurl+"/sidebar_ajaxpage.php";

hiddenpayurl=hiddenpageurl+"/payment.php";




data="formtype=giftform&name="+name+"&street="+street+"&province="+province+"&city="+city+"&postal_code="+postal_code+"&phone="+phone+"&email="+email+"&recipient_name="+recipient_name+"&recipient_street="+recipient_street+"&recipient_province="+recipient_province+"&recipient_city="+recipient_city+"&recipient_postal_code="+recipient_postal_code+"&recipient_phone="+recipient_phone+"&recipient_email="+recipient_email+"&amount="+amount+"&special_note="+special_note+"&viaemail="+viaemail+"&viamail="+viamail+"&sid="+Math.random();




//return true;

jQuery("#lightbox_wp").fadeIn(300);
msg=jQuery(this).ajaxForms(hiddenurl,"POST",data,"gifterror","gift_err_table","gift_success_table",'giftform');

//if(msg!='')
	//jQuery("#lightbox_wp").fadeOut(300);
	
return false;
}

})

/*  End Estimate Form Utility          */


})

