// Cookie Javascript//

function SetCookie(name, value)
{
    var exp = new Date();
    
    exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));    
	document.cookie = name + "=" + value + "; path=/" + ((exp == null) ? "" : "; expires=");
}

function GetCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		
		while (c.charAt(0) == " ") c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	
	return null;
}

function DelCookie(name)
{
    document.cookie = name + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
}

//			Cookie End 			//

// 			Email Subscription 		//

function subscribey(){
	if(document.frmSubscribe.txtemail.value == "" || document.frmSubscribe.txtemail.value == "Email Address" || echeck(document.frmsubscribe.txtemail.value) == false)
		alert("Por favor revise su direcci\u00F3n de correo electr\u00F3nico.");
	else{
		document.frmSubscribe.action = document.frmSubscribe.url.value + "?subscribey=yes";
		document.frmSubscribe.submit();
	}
}


/*function subscribey(){
	if(document.frmSubscribe.txtemail.value == "" || document.frmSubscribe.txtemail.value == "Email Address" || echeck(document.frmsubscribe.txtemail.value) == false)
		alert("Por favor revise su dirección de correo electrónico. Please check your email address");
	else{
		document.frmSubscribe.action = document.frmSubscribe.url.value + "?subscribey=yes";
		document.frmSubscribe.submit();
	}
}
function subscriben(){
	if(document.frmSubscribe.txtemail.value == "" || document.frmSubscribe.txtemail.value == "Email Address" || echeck(document.frmSubscribe.txtemail.value) == false)
		alert("Por favor revise su dirección de correo electrónico. Please check your email address");
	else{
		document.frmSubscribe.action = document.frmSubscribe.url.value + "?subscriben=no";
		document.frmSubscribe.submit();
	}
}
*/

function noPrice(){
alert ("El producto no est\u00E1 disponible todav\u00EDa. Por favor, permanezca atento a las actualizaciones. Gracias!");
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
	
	function subscribe(){
	if(document.frmSubscribe.txtemail.value == "" || CheckEmail(document.frmSubscribe.txtemail.value) == false )
		alert("Por favor revise su direcci\u00F3n de correo electr\u00F3nico.");
	else{
		//alert("Thank you for signing up!");		
		document.frmSubscribe.action = "index.php?act=subscribe"; 
		document.frmSubscribe.submit();  
					
		}
	
}


// End //



//Send to Friend Bookmark Us

function bookmarksite(){
var myloc = location.href;
var title = "Freeport Bible Center";
// check if active
// alert (title+"\r\n"+myloc);
if (document.all)
window.external.AddFavorite(myloc,title);
else if (window.sidebar)
window.sidebar.addPanel(title, myloc,"")
}



function sendtofriend() {
	// alert (URL);
	var URL 
	URL = location.href;
	window.open('sendtofriend.php?page='+URL, 'EmailWindow', 'scrollbars=yes,width=650,height=355');
}


// END//

//	Contact Form

function submitForm() {
	var cForm = document.contactForm;
	var ctr = 0;
	
	if (cForm.txtname.value=="") {
		alert("Por favor escriba su nombre.");
		cForm.txtname.focus();
		var ctr = 1;
	}
	
	else if(cForm.txtemail.value=="") {
		alert("Por favor escriba su correo electronico.");
		cForm.txtemail.focus();
		var ctr = 1;
	}
		
	else if (CheckEmail(cForm.txtemail.value)==false) {
		alert("Por favor revise su correo electronico.");
		cForm.txtemail.focus();
		var ctr = 1;
	}
	
	else if(cForm.txtphone.value=="") {
		alert("Por favor escriba su numero de telefono");
		cForm.txtphone.focus();
		var ctr = 1;
	}
	
	
	else if (cForm.txtmessage.value=="") {
		alert("Por favor, escribe tu mensaje.");
		cForm.txtmessage.focus();
		var ctr = 1;
	}
	
	if(ctr == 0){
	cForm.msgsent.value="sent";
	cForm.submit();
	
	}
}

///////////////////////// Check out Form ////////////////////////

function submitCheckF() {
	var chForm = document.frmCheckout;
	var ctr = 0;
	
	if (chForm.txtFName.value=="") {
		alert("Por favor escriba su nombre.");
		chForm.txtFName.focus();
		var ctr = 1;
	}

	else if (chForm.txtLName.value=="") {
		alert("Por favor escriba su apellido.");
		chForm.txtLName.focus();
		var ctr = 1;
	}

	else if (chForm.txtAddress1.value=="") {
		alert("Por favor escriba su direcci\u00F3n.");
		chForm.txtAddress1.focus();
		var ctr = 1;
	}

	else if (chForm.txtCity.value=="") {
		alert("Por favor escriba su ciudad.");
		chForm.txtCity.focus();
		var ctr = 1;
	}

	else if (chForm.cmbCountry.value=="") {
		alert("Por favor escriba su pa\u00EDs.");
		chForm.cmbCountry.focus();
		var ctr = 1;
	}
	
	else if (chForm.txtZip.value=="") {
		alert("Por favor escriba su c\u00F3digo postal.");
		chForm.txtZip.focus();
		var ctr = 1;
	}
	
	else if (chForm.txtPhone.value=="") {
		alert("Por favor escriba su n\u00FAmero de tel\u00E9fono.");
		chForm.txtPhone.focus();
		var ctr = 1;
	}

	else if(chForm.txtEmail.value=="") {
		alert("Por favor escriba su correo electronico.");
		chForm.txtEmail.focus();
		var ctr = 1;
	}
		
	else if (CheckEmail(chForm.txtEmail.value)==false) {
		alert("Por favor revise su correo electronico.");
		chForm.txtEmail.focus();
		var ctr = 1;
	}

	if(ctr == 0){
	chForm.submit();
	
	}
}

///////////////////////////////////////////////////////////////////

//################################################
//				To Check the Email
//################################################

function CheckEmail(Email){
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Email)) {
  return true
 }
 
 return (false)
}
