function setupCalendar(destination, source){
	Zapatec.Calendar.setup({
		firstDay          : 1,
		weekNumbers       : false,
		electric          : false,
		inputField        : destination,
		button            : source,
		ifFormat          : "%Y-%m-%d",
		daFormat          : "%Y/%m/%d"
	});
}


function numeros_conpunto(e){
	var key;
	key=e.which?e.which:e.keyCode;
	if((key >= 48 && key <= 57)||(key == 8)||(key == 46)||(key == 9)){
	 return false;
	}
	else{
		var browser=navigator.appName;
		if(browser.indexOf("Netscape")!=-1){
		return e.preventDefault();
		}
		if(browser.indexOf("Microsoft")!=-1){
		return e.returnValue = false;
		}
	}
}


function valida_step1(){

	var msg=""; 
	if(document.form1.Fname.value==""){
		msg+="- Name \n";
	}	
	if(document.form1.Lname.value==""){
		msg+="- Last name \n";
	}
	if(document.form1.email.value==""){
		msg+="- E-mail \n";
	}
	
	if (document.form1.email.value!=""){
		var cadena = document.form1.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.form1.zip.value==""){
		msg+="- Zip \n";
	}
	
	if(document.form1.userName.value==""){
		msg+="- Username \n";
	}else if(document.form1.userName.value.length >0 && document.form1.pass.value.length< 5){
		msg+="- Username must be more bigger than 5 characters \n";
	}
	if(document.form1.pass.value==""){ 
		msg+="- Password \n";
	}else if(document.form1.pass.value.length >0 && document.form1.pass.value.length< 5){
		msg+="- Password must be more bigger than 5 characters \n";
	}
	
	if(msg!=""){
		var message="Next fields are required: \n" + msg;
		alert(message);
		return false
	}	
}


function valida_step2(){
	var msg=""; 
	if(document.form1.price.value==""){
		msg+="- Price \n";
	}	
	if(document.form1.pcategory.value=="0"){
		msg+="- Primary Category \n";
	}
	if(document.form1.manufacturer.value==""){
		msg+="- Manufacturer \n";
	}
	if(document.form1.model.value==""){
		msg+="- Model \n";
	}
	if(document.form1.caliber.value==""){
		msg+="- Caliber \n";
	}
	if(msg!=""){
		var message="Next fields are required: \n" + msg;
		alert(message);
		return false;
	}	
}

function go_step3(){
	if(document.form1.price.value!="" || document.form1.pcategory.value!="0" || document.form1.manufacturer.value!="" || document.form1.model.value!="" || document.form1.caliber.value!=""){
		var msg=""; 
		if(document.form1.price.value==""){
			msg+="- Price \n";
		}	
		if(document.form1.pcategory.value=="0"){
			msg+="- Primary Category \n";
		}
		if(document.form1.manufacturer.value==""){
			msg+="- Manufacturer \n";
		}
		if(document.form1.model.value==""){
			msg+="- Model \n";
		}
		if(document.form1.caliber.value==""){
			msg+="- Caliber \n";
		}
		if(msg==""){
			document.form1.cmd.value='insert_payment10';	//Misael
			//document.form1.submit();
		}
		else{
			var message="Next fields are required: \n" + msg;
			alert(message);
			return false;
		}
	}else{
		window.location='signupstep3.php';
		return false;
	}
}

function valida_step3(){
	var msg=""; 

		if(document.formstep3.agreeterms.checked == false){
			alert("Please check the box to agree to terms and conditions");
			return false;
		}
	
}


function go_step3_verify(){
	if(document.form1.price.value!="" || document.form1.pcategory.value!="0" || document.form1.manufacturer.value!="" || document.form1.model.value!="" || document.form1.caliber.value!=""){//Misael
			var msg=""; 
			if(document.form1.price.value==""){
				msg+="- Price \n";
			}	
			if(document.form1.pcategory.value=="0"){
				msg+="- Primary Category \n";
			}
			if(document.form1.manufacturer.value==""){
				msg+="- Manufacturer \n";
			}
			if(document.form1.model.value==""){
				msg+="- Model \n";
			}
			if(document.form1.caliber.value==""){
				msg+="- Caliber \n";
			}
			if(msg==""){
				document.form1.cmd.value='insert_payment11';
				//document.form1.submit();
			}
			else{
				var message="Next fields are required: \n" + msg;
				alert(message);
				return false;
			}
	}else{
		document.form1.cmd.value='verify_payment';	//Misael
		document.form1.submit();					//Misael
	}
}

function valida_add_item(){
	var msg=""; 
	if(document.form1.price.value==""){
		msg+="- Price \n";
	}	
	if(document.form1.pcategory.value=="0"){
		msg+="- Primary Category \n";
	}
	if(document.form1.manufacturer.value==""){
		msg+="- Manufacturer \n";
	}
	if(document.form1.model.value==""){
		msg+="- Model \n";
	}
	if(document.form1.caliber.value==""){
		msg+="- Caliber \n";
	}
	if(msg!=""){
		var message="Next fields are required: \n" + msg;
		alert(message);
		return false;
	}else{
		document.forms['form1'].elements['cmd'].value="insert_item_2";
	}
	

}

function valida_step1A(){

	var msg=""; 
	if(document.form1.Fname.value==""){
		msg+="- Name \n";
	}	
	if(document.form1.Lname.value==""){
		msg+="- Last name \n";
	}
	if(document.form1.email.value==""){
		msg+="- E-mail \n";
	}
	
	if (document.form1.email.value!=""){
		var cadena = document.form1.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.form1.userName.value==""){
		msg+="- Username \n";
	}	
	if(document.form1.pass.value==""){ 
		msg+="- Password \n";
	}
	if(msg==""){
		document.form1.submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}



function change_charge(val){
	document.formstep3.charge.value = val;
}

function disabled_ext(){
	document.formstep3.items_ext.value = "";
	document.formstep3.items_ext.disabled = true;
}
function enabled_ext(){
	document.formstep3.items_ext.disabled = false;
}
function calcula_charge(items){
	charge = 5.99;
	charge+= items * 1.99;
	document.formstep3.charge.value = charge;
}


function activate_item(id_item, id_payment){
	if(id_item > 0 && id_payment > 0){
		document.items_activate.id_payment.value = id_payment;
		document.items_activate.id_art.value = id_item;
//		document.items_activate.submit();
	}
	else{
		alert("You must select a payment");	
	}
}



function validate_search1(){
	flag = false;
	if(document.form1.search1.value!=""){
		flag = true;
	}	
	if(document.form1.zip.value!=""){
		flag = true;
	}
	if(flag){
		document.form1.cmd.value = "search1";
		//alert("Messaje.. some... i dunno... do you want tell me something?")
		document.form1.submit();
	}
	else{
		alert("Search fields are required");
	}
}

function validate_search2(){
	flag = false;
	if(document.form1.manufacturer.value!=""){
		flag = true;
	}	
	if(document.form1.model.value!=""){
		flag = true;
	}
	if(document.form1.caliber.value!=""){
		flag = true;
	}	
	if(document.form1.keywords.value!=""){
		flag = true;
	}	
	if(document.form1.zip2.value!=""){
		flag = true;
	}
	if(flag){
		document.form1.cmd.value = "search2";
		//alert("Messaje.. some... i dunno... do you want tell me something?")
		document.form1.submit();
	}
	else{
		alert("Detailed search fields are required");
	}
}

//no se esta usando
function login(){
	flag = false;
	if(document.form_login.user.value!=""){
		alert("sdfsdfsdf");
		flag = true;
	}	
	if(document.form_login.pass.value!=""){
		flag = true;
	}
	if(flag){
		document.form_login.cmd.value = "user_login";
		document.form_login.submit();
	}
	else{
		alert("Login fields are required");
	}
}

function validate_change_pass(){
	var msg=""; 
	
	if(document.changePass.userok.value!="ok"){
		msg+="- Username invalid \n";	
	}	
	if(document.changePass.oldpass.value!=""){
		if(document.changePass.passok.value!="ok"){
			msg+="- Old Pass incorrect \n";
		}
		if(document.changePass.newpass.value!=document.changePass.repass.value){
			msg+="- New password incorrect \n";
		}	
	}else{
			msg+="- You must type your password \n";
	}

	if(msg==""){
		document.changePass.submit();
	}
	else{
		var message="Next errors ocurred: \n" + msg;
		alert(message);
	}
}


function valida_update_info(){

	var msg=""; 
	var band=0;
	if(document.form1.Fname.value==""){
		msg+="- Name \n";
	}	
	if(document.form1.Lname.value==""){
		msg+="- Last name \n";
	}
	if(document.form1.email.value==""){
		msg+="- E-mail \n";
	}
	
	if (document.form1.email.value!=""){
		var cadena = document.form1.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.form1.userName.value==""){
		msg+="- Username \n";
	}
	//Validamos los checkbox
	if (document.forms['form1'].elements['check[2]'].checked || document.forms['fomacheck'].elements['check[3]'].checked)	band=1;
	
	if (band!=1){
		msg+="- You Must Select at way to contact (Phone or Email)";
	}
	
	if(msg==""){
		document.form1.submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}


//inconclusa
function valida_update_item(){
//	alert("Working on it");
	
	var msg=""; 
	if(document.form1.price.value==""){
		msg+="- Price \n";
	}	
	if(document.form1.pcategory.value=="0"){
		msg+="- Primary Category \n";
	}
	if(document.form1.manufacturer.value==""){
		msg+="- Manufacturer \n";
	}
	if(document.form1.model.value==""){
		msg+="- Model \n";
	}
	if(document.form1.caliber.value==""){
		msg+="- Caliber \n";
	}
	
	if(msg==""){
	//document.form1.cmd.value="post_user";
	document.form1.submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	

}

function sub_send(){
	var msg=""; 
	if(document.form1.Fname.value==""){
		msg+="- First Name \n";
	}	
	if(document.form1.Lname.value==""){
		msg+="- Last Name \n";
	}
	if (document.form1.email.value!=""){
		var cadena = document.form1.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.form1.email.value==""){
		msg+="- Email \n";
	}
	
	if(document.form1.select1.value=="0"){
		msg+="- Category \n";
	}
	
	if(document.form1.msg.value==""){
		msg+="- Message \n";
	}
	
	if(msg==""){
	document.form1.cmd.value="send_email";
	document.form1.submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}

function sub_notify(){
	var msg=""; 
	if(document.form1.Fname.value==""){
		msg+="- First Name \n";
	}	
	if(document.form1.Lname.value==""){
		msg+="- Last Name \n";
	}
	if (document.form1.email.value!=""){
		var cadena = document.form1.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.form1.email.value==""){
		msg+="- Email \n";
	}
	
	if(document.form1.caliber.value=="0"){
		msg+="- Caliber \n";
	}
	
	if(document.form1.model.value==""){
		msg+="- Model \n";
	}
	
	if(document.form1.manu.value==""){
		msg+="- Manufacturer \n";
	}
	
	if(msg==""){
	document.form1.cmd.value="send-notify";
	document.form1.submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}

function delete_item(id_item){
	if(confirm('Are you sure you want to DELETE?')){
		location.href = 'validate.php?cmd=delete_item&id_item='+id_item;
	}
}	

function delete_pic(id_photo, id_item){
	if(confirm('Are you sure you want to DELETE?')){
		location.href = 'validate.php?cmd=delete_pic&id_photo='+id_photo+'&id_item='+id_item;
	}
}	

function valida_premium(){
	
	var msg=""; 
	if(document.premium.bussines.value==""){
		msg+="- Business \n";
	}	
	if(document.premium.street_biz.value==""){
		msg+="- Street \n";
	}
	if(document.premium.city_biz.value==""){
		msg+="- City \n";
	}
	
	if(document.premium.state_biz.value==""){
		msg+="- State \n";
	}
	
	if(document.premium.zip_biz.value==""){
		msg+="- Zip \n";
	}
	if(isNaN(document.premium.zip_biz.value)){
		msg+="- Zip must be only numbers \n";
	}
	if(document.premium.phone.value==""){
		msg+="- Phone \n";
	}
	
	if(document.premium.years.value==""){ 
		msg+="- Years \n";
	}
	if(isNaN(document.premium.years.value)){
		msg+="- Years must be only numbers \n";
	}
	
	if(msg==""){
		document.forms['premium'].action='membership.php';
		document.forms['premium'].submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}

function valida_membership(){
	
	var msg=""; 
	if(document.formstep3.name.value==""){
		msg+="- First Name \n";
	}
	if(document.formstep3.lname.value==""){
		msg+="- Last Name \n";
	}
	if(document.formstep3.phone.value==""){
		msg+="- Phone \n";
	}
	if (document.formstep3.email.value!=""){
		var cadena = document.formstep3.email.value;
		var arroba = cadena.indexOf('@');
		var punto = cadena.indexOf('.',arroba); 
		
		if (arroba== -1 || punto==-1) 
		{msg+="- E-mail incorrect format. \n";}
	}
	
	if(document.formstep3.email.value==""){
		msg+="- Email \n";
	}
	if(document.formstep3.address.value==""){
		msg+="- Street \n";
	}
	if(document.formstep3.city.value==""){
		msg+="- City \n";
	}
	if(document.formstep3.state.value==""){
		msg+="- State \n";
	}
	if(document.formstep3.zip.value==""){
		msg+="- Zip \n";
	}
	if(isNaN(document.formstep3.zip.value)){
		msg+="- Zip must be only numbers \n";
	}
	if(document.formstep3.method.value=="0"){ 
		msg+="- Method \n";
	}
	
	if(document.formstep3.cardnumber.value==""){ 
		msg+="- Cardnumber \n";
	}else{
		if(document.formstep3.cardnumber.value.length < 4){
			msg+="- Card Number incorrect format \n";
		}
	}
	if(isNaN(document.formstep3.cardnumber.value)){
		msg+="- Cardnumber must be only numbers \n";
	}
	if(document.formstep3.ccv.value==""){ 
		msg+="- Ccv \n";
	}
	if(document.formstep3.meses.value==0 || document.formstep3.anios.value==0){
		msg+="- EXP Date \n";
	}
	if(document.formstep3.charge.value==""){ 
		msg+="- Charge \n";
	}
	
	if(msg==""){
		document.forms['formstep3'].submit();
	}
	else{
		desplegarErrores(msg);
	}
	function desplegarErrores(msg){
		var message="Next fields are required: \n" + msg;
		alert(message);
	}	
}

