/* all script functions of this site defined in this file */

function validate_category()
{

var msg="";

if(document.category_frm.name.value.length == 0)
	msg+="Enter Name\n";

if(msg.length > 0)
{
	alert(msg);

	return false;

}
else
{
	return true;
}

}


function confirm_on_del(val)
{

	if(val.length==0)
		val = "Are you sure?";

		if(confirm(val))
			return true;
		else
			return false;

}

function alert_delete(val1,val2,val3)
{

if(confirm_on_del(''))
{

str=val2+"&id="+val1+"&type="+val3;

//alert(str);

window.location.href=str;

}

}

function validate_items(id)
{

var msg="";

var dc=document.items_frm;

	for(i=0;i<dc.elements.length;i++)
	{
		if(dc.elements[i].name=="category[]")
			{
				if(dc.elements[i].value==-1 || dc.elements[i].value.length==0)
				 {	
					msg+="Choose a Product category\n";	
					break;
				 }
			}			
	}

if(dc.code.value.length == 0)

	msg+="Enter Code\n";

if(dc.name.value.length == 0)

	msg+="Enter Name\n";

if(id.length==0 && 1==2)//only for new product..
{
	if(dc.option_name.value==0)
		msg+="Select Option Name\n";
	
	if(dc.price.value.length==0)
		msg+="Enter Price\n";

}

	for(i=0;i<dc.elements.length;i++)
	{
	
		if(dc.elements[i].name=="option_ids[1]")
		{	
			if(dc.elements[i].value==0)
				msg+="Select Option1\n";
		}			
	}


if(msg.length > 0)
{
	alert(msg);

	return false;
}
else
{
	return true;
}

}


function validate_options()
{

	var msg="";

	dc=document.option_frm;

	if(dc.option_name.value==0)
		msg+="Select Option Name\n";
	
	if(dc.price.value.length==0)
		msg+="Enter Price\n";

	if(msg.length > 0)
	{	
		alert(msg);
		return false;
	}

	return true;		

}



function validate_discount()
{

	var msg="";

	dc=document.discount_frm;

	if(dc.code.value.length==0)
		msg+="Enter Code\n";
	
	if(dc.discount.value.length==0)
		msg+="Enter Discount\n";
		
	if(dc.discounttype.value==0)
		msg+="Select Discount Type\n";
		
	if(dc.expirydate.value.length==0)
		msg+="Enter Expiry Date\n";
		
		
	if(msg.length > 0)
	{	
		alert(msg);
		return false;
	}

	return true;		

}

function chk_signup()
{

	var msg="";

	dc = document.signup_frm;

  if(dc.email.value.length==0)

	msg+="Enter Email\n";

  else if(!chk_email(dc.email))

	{

		msg+="Enter valid email\n";

	}				





	if(dc.user_pass.value.length==0 && dc.submit_action.value!="guest")

		msg+="Enter Password\n";

		

  if(dc.firstname.value.length==0)

	msg+="Enter First Name\n";



  if(dc.lastname.value.length==0)

	msg+="Enter Last Name\n";





  if(dc.address.value.length==0)

	msg+="Enter Address\n";



  if(dc.state.value.length==0)

	msg+="Enter State\n";



  if(dc.zipcode.value.length<5 || isNaN(dc.zipcode.value))

	msg+="Enter Zip Code\n";


/*
  if(dc.country.value.length==0)

	msg+="Enter Country\n";
*/


  if(dc.phone1.value.length!=3 || dc.phone2.value.length!=3 || dc.phone3.value.length!=4)

	msg+="Enter Phone\n";



  if(dc.ship_firstname.value.length==0)

	msg+="Enter shipping First Name\n";



  if(dc.ship_lastname.value.length==0)

	msg+="Enter shipping Last Name\n";



  if(dc.ship_address.value.length==0)

	msg+="Enter shipping Address\n";



  if(dc.ship_state.value.length==0 )

	msg+="Enter shipping State\n";


  if((dc.ship_zip.value.length)<5 || isNaN(dc.ship_zip.value))

	msg+="Enter shipping Zip Code\n";



/*
  if(dc.ship_country.value.length==0)

	msg+="Choose shipping Country\n";
*/



  if(dc.ship_phone1.value.length!=3 || dc.ship_phone2.value.length!=3 || dc.ship_phone3.value.length!=4)

	msg+="Enter shipping Phone\n";


  if(dc.shipping_method.value==0)

	msg+="Choose Shipping Method\n";




	if(msg.length > 0)

	{

		alert(msg);

		return false;

	}

	

	return true;

	



}



function chk_email(fldname)

{



	var bool=true;



	email = fldname.value;



	var len = email.length;              



	if(len<5){

		bool=false;

	}	else	{



	var index1 = email.indexOf('@');



	var subind = email.substring(0,index1);



	var indlen = subind.length;



	var index2 = email.indexOf('.');



	var subind1=email.substring(indlen+1,index2);



	var indlen1 = subind1.length;



	var index3 = email.indexOf(' ');



	var subind3=email.substring(index2+1,len)



	var indlen2 = subind3.length;



	if((index1!= -1)&&(index2!= -1)&&(index3==-1))



	{	



		if((indlen!=0)&&(indlen1!=0)&&(indlen2!=0))



		{



		} 



        else



		{



		}



	}



	else



	{



			bool=false;



	}		



	} // end of else if len<5







	return(bool);







}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function validate_cart()
{
	var msg="";

	if(document.cart_form.product_id.value==0)
	{
		alert("Please select a Color / Size");
		return false;
	}

	for(i=0;i<document.cart_form.elements.length;i++)
	{
		if(document.cart_form.elements[i].name.substring(0,3)=="qty")
		{
			
			if(document.cart_form.elements[i].value > 0)
			{
				
				msg="ok";
			}
		}
	}
	
	if(msg!="ok")
	{
		alert("Please enter a qty");
		return false;
	}
	
	
	return true;
}

function chk_cc()
{
		var msg="";
		
		/*
		if(document.order_form.card_number.value.length<5)
		{
			msg +="Enter valid card number\n";

		}
		
		if(document.order_form.cvv.value.length < 3 && document.order_form.payment_method.value=="Credit Card")
		{
			msg +="Enter valid CVV\n";

		}
		*/
		
		if(!document.order_form.agree.checked)
			msg +="You need to acknowledge the terms of use\n";
		
		if(msg.length > 0)
		{
			alert(msg);
		
			return false;
		
		}
		
		return true;

}


function show_hide_cc(obj)
{
	
	if(obj.value=="Credit Card")
	{
		document.getElementById('dropdown').style.display = 'inline';
		document.getElementById('dropdown1').style.display = 'inline';
	}
	else
	{
		document.getElementById('dropdown').style.display = 'none';
		document.getElementById('dropdown1').style.display = 'none';	
		
	}


}


function validate_master_options()

{

	

	var msg="";

	

	dc=document.option_frm;

	

	if(dc.name.value.length==0)

		msg+="Enter Option Name\n";

	

	if(msg.length > 0)

	{	

		alert(msg);

		return false;

	}



	return true;		


}

function chk_mailing_list(obj)
{
	
		var msg="";

	if(obj.email.value.length==0)

	msg+="Enter Email\n";

  else if(!chk_email(obj.email))

	{

		msg+="Enter valid email\n";

	}				
	

	if(msg.length > 0)

	{	

		alert(msg);

		return false;

	}



	return true;		



}