// JavaScript Document

function showhidestate(ival){
	//alert(ival);
	if(ival=="US"){
		document.getElementById('txtstate').value="";
		document.getElementById('txtstate').style.visibility="hidden";
		document.getElementById('txtstate').style.width="0px";
		document.getElementById('selstate').style.visibility="visible";
		document.getElementById('selstate').style.width="215px";
		
	}else{
		document.getElementById('selstate').selectedIndex=0;
		document.getElementById('selstate').style.visibility="hidden";
		document.getElementById('selstate').style.width="0px";
		document.getElementById('txtstate').style.visibility="visible";
		document.getElementById('txtstate').style.width="215px";
		
	}
}

function refreshImage(isrc)
{
img = document.getElementById("cam");
img.src=isrc + "?rand=" + Math.random();
}
function ChkNumeric(isrc){
	if (isNaN(isrc.value)){
		isrc.value="";
		alert("should be numeric value");
		isrc.focus;
		return false;
	}else{
		return true;
	}
	//alert(isrc.value);
}
function isNumber(strnumber)
{

	var regEx = /^\d+$/;
	if(!regEx.test(strnumber))
	{

			return false;
	}
	else
		return true;

}
function emailCheck(emailStr) 
  	{
  	  		var emailPat=/^(.+)@(.+)$/
  	        var matchArray;	
  	  		//var emailStr = document.frm_shop.email.value;	
  	  	
  	  		if(emailStr.length > 1)
  	  			{  	  	
			matchArray = emailStr.match(emailPat);
			if (matchArray == null) 
			
			{
				alert("Please Enter Correct Email Address"); 
				return false;
			}	
			else
			{
				return true;
			}  		
  		}
  	  	
    }
function chk_registration(iform){
	var Field= Array();
	var FieldName= Array();
	Field[0]=iform.FirstName.value;
	Field[1]=iform.LastName.value;
	Field[2]=iform.country.value;
	if(Field[2]=="US"){
		Field[3]=iform.usstate.value;
	}else{
		Field[3]=iform.state.value;	
	}
	Field[4]=iform.ZipCode.value;
	Field[5]=iform.bmon.value;
	Field[6]=iform.bday.value;
	Field[7]=iform.byear.value;
	Field[8]=iform.username.value;
	Field[9]=iform.Email.value;
	Field[10]=iform.ConfirmEmail.value;
	Field[11]=iform.Password.value;
	Field[12]=iform.ConfirmPassword.value;
	Field[13]=iform.SecurityQuestion.value;
	Field[14]=iform.SecurityAnswer.value;
	Field[15]=iform.impression.value;
	if(iform.agreement.checked){
		Field[16]=iform.agreement.value;
	}else{
		Field[16]="";
	}

	FieldName[0]="First Name";
	FieldName[1]="Last Name";
	FieldName[2]="Country";
	FieldName[3]="State";
	FieldName[4]="Zip Code";
	FieldName[5]="Birth Month";
	FieldName[6]="Birth Day";
	FieldName[7]="Birth Year";
	FieldName[8]="Username";
	FieldName[9]="Email";
	FieldName[10]="Confirm Email";
	FieldName[11]="Password";
	FieldName[12]="Confirm Password";
	FieldName[13]="Security Question";
	FieldName[14]="Security Answer";
	FieldName[15]="Image impression";
	FieldName[16]="Terms & Condition checkbox";
	
	
	var msg="";
	var bval=true;
	
	
	for(i=0; i<17; i++)
	{
		if(Field[i]=="")
		{
			msg = msg + "\n" + ">> " + FieldName[i];
		}
	}
	
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}
	if(bval)
	{
			bval=emailCheck(Field[9]);
			if(bval){
				bval=emailCheck(Field[10]);	
				if(Field[10]!=Field[9]){
					alert("Email and Confirm Email should be equal");
					bval=false;
				}
			}
			//bval=emailCheck();
	}
	if(bval){
			if(Field[8].length<5){
				alert("Username should be atleast 5 characters");
				bval=false;
			}
	}
	if(bval){
		if(Field[11].length<5){
			alert("Password should be atleast 5 characters");
			bval=false;
		}else{
			if(Field[11]!=Field[12]){
				alert("Password and Confirm Password should be equal");
				bval=false;
			}	
		}
	}

	return bval;
}
//added by amitava..............
function checkpaymentform(iform){
	if(iform.listingcost.value==""){
		alert('Pls. select an option for Number of Gowns Listed');
		iform.paymentmethod.value="CREDITCARD";
		return false;
	}
	//alert(iform.paymentmethod.value);
	if(iform.paymentmethod.value=="PAYPAL"){
		return true;	
	}
	var Field= Array();
	var FieldName= Array();
	Field[0]=iform.cctype.value;
	Field[1]=iform.ccname.value;
	Field[2]=iform.cclname.value;
	Field[3]=iform.ccnumber.value;
	Field[4]=iform.cvvcode.value;
	Field[5]=iform.ccmonth.value;
	Field[6]=iform.ccyear.value;
	Field[7]=iform.address.value;
	Field[8]=iform.city.value;
	Field[9]=iform.usstate.value;
	Field[10]=iform.email.value;
	Field[11]=iform.phone.value;
	Field[12]=iform.country.value;
	
	var msg="";
	var bval=true;
	
	FieldName[0]="Credit Card Type";
	FieldName[1]="First Name";
	FieldName[2]="Last Name";
	FieldName[3]="Credit Card Number";
	FieldName[4]="CVV Code";
	FieldName[5]="Exp. Month";
	FieldName[6]="Exp. Year";
	FieldName[7]="Address";
	FieldName[8]="City";
	FieldName[9]="State";
	FieldName[10]="Email";
	FieldName[11]="Phone";
	FieldName[12]="Country";
	
	for(i=0; i<13; i++)
	{
		if(Field[i]=="")
		{
			msg = msg + "\n" + ">> " + FieldName[i];
		}
	}
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}
	return bval;
}

function chk_update_reg(iform){
	var Field= Array();
	var FieldName= Array();
	Field[0]=iform.FirstName.value;
	Field[1]=iform.LastName.value;
	Field[2]=iform.country.value;
	if(Field[2]=="US"){
		Field[3]=iform.usstate.value;
	}else{
		Field[3]=iform.state.value;	
	}
	Field[4]=iform.ZipCode.value;
	Field[5]=iform.bmon.value;
	Field[6]=iform.bday.value;
	Field[7]=iform.byear.value;
	Field[8]=iform.username.value;
	Field[9]=iform.Email.value;
	Field[10]=iform.ConfirmEmail.value;
	Field[11]=iform.Password.value;
	Field[12]=iform.ConfirmPassword.value;
	Field[13]=iform.SecurityQuestion.value;
	Field[14]=iform.SecurityAnswer.value;

	FieldName[0]="First Name";
	FieldName[1]="Last Name";
	FieldName[2]="Country";
	FieldName[3]="State";
	FieldName[4]="Zip Code";
	FieldName[5]="Birth Month";
	FieldName[6]="Birth Day";
	FieldName[7]="Birth Year";
	FieldName[8]="Username";
	FieldName[9]="Email";
	FieldName[10]="Confirm Email";
	FieldName[11]="Password";
	FieldName[12]="Confirm Password";
	FieldName[13]="Security Question";
	FieldName[14]="Security Answer";

	
	var msg="";
	var bval=true;
	
	
	for(i=0; i<15; i++)
	{
		if(Field[i]=="")
		{
			msg = msg + "\n" + ">> " + FieldName[i];
		}
	}
	
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}
	if(bval)
	{
			bval=emailCheck(Field[9]);
			if(bval){
				bval=emailCheck(Field[10]);	
				if(Field[10]!=Field[9]){
					alert("Email and Confirm Email should be equal");
					bval=false;
				}
			}
			//bval=emailCheck();
	}
	if(bval){
			if(Field[8].length<5){
				alert("Username should be atleast 5 characters");
				bval=false;
			}
	}
	if(bval){
		if(Field[11].length<5){
			alert("Password should be atleast 5 characters");
			bval=false;
		}else{
			if(Field[11]!=Field[12]){
				alert("Password and Confirm Password should be equal");
				bval=false;
			}	
		}
	}

	return bval;
}


function frmvalidation()
{
   	var Field= Array();
	var FieldName= Array();
	
	
	Field[0]=document.frm_shop.email.value;
	Field[1]=document.frm_shop.first_name.value;
	Field[2]=document.frm_shop.last_name.value;
	Field[3]=document.frm_shop.city.value;
	Field[5]=document.frm_shop.zip_code.value;
	Field[6]=document.frm_shop.country.value;
	Field[7]=document.frm_shop.telephone.value;
	if(Field[6]=="US"){
		Field[4]=document.frm_shop.state.value;
	}else{
		Field[4]=document.frm_shop.other_state.value;
	}
	Field[8]=document.frm_shop.first_name1.value;
	Field[9]=document.frm_shop.last_name1.value;
	Field[10]=document.frm_shop.city1.value;
	
	Field[12]=document.frm_shop.zip_code1.value;
	Field[13]=document.frm_shop.country1.value;
	Field[14]=document.frm_shop.telephone1.value;
	if(Field[13]=="US"){
		Field[11]=document.frm_shop.state1.value;
	}else{
		Field[11]=document.frm_shop.other_state1.value;
	}
	
	Field[15]=document.frm_shop.select_card.value;
	Field[16]=document.frm_shop.card_no.value;
	Field[17]=document.frm_shop.cvv_code.value;
	Field[18]=document.frm_shop.ex_date1.value;
	Field[19]=document.frm_shop.ex_date2.value;
	
	FieldName[0]="Email";
	FieldName[1]="Billing First Name";
	FieldName[2]="Billing Last Name";
	FieldName[3]="Billing City";
	if(Field[6]=="US"){
		FieldName[4]="Billing US State";
	}else{
		FieldName[4]="Billing Other State";
	}
	FieldName[5]="Billing Zip Code";
	FieldName[6]="Billing Country";
	FieldName[7]="Billing Telephone No.";
	FieldName[8]="Shipping First Name";
	FieldName[9]="Shipping Last Name";
	FieldName[10]="Shipping City";
	if(Field[13]=="US"){
		FieldName[11]="Shipping US State";
	}else{
		FieldName[11]="Shipping Other State";
	}
	FieldName[12]="Shipping Zip Code";
	FieldName[13]="Shipping Country";
	FieldName[14]="Shipping Telephone No";
	FieldName[15]="Card Type";
	FieldName[16]="Card No.";
	FieldName[17]="CVV Code";
	FieldName[18]="Expiration Date";
	FieldName[19]="Expiration Year";
	
	var msg="";
	var bval=true;
	
	for(i=0; i<20; i++)
	{
		if(Field[i]=="")
		{
			//alert("Please fill " + FieldName[i] + " field.");
			msg = msg + "\n" + ">> " + FieldName[i];
			//bval=false;
			//break;
		}
	}
	
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}
	if(bval)
	{
			bval=emailCheck();
	}
		
	if(document.frm_shop.zip_code.value != "" && bval)
		{				
			if(isNumber(document.frm_shop.zip_code.value)==false)
			{
				alert("Zip Code must be numeric value.");
				document.frm_shop.zip_code.focus();
				bval=false;
			}
		}
	if(document.frm_shop.telephone.value != "" && bval)
	{				
		if(isNumber(document.frm_shop.telephone.value)==false)
		{
			alert("telephone no must be numeric value.");
			document.frm_shop.telephone.focus();
			bval=false;
		}
	}
	if(document.frm_shop.card_no.value != "" && bval)
		{
			if(isCardNumber(document.frm_shop.card_no.value)==false)
			{
				alert("Card No must be a 16 digit numeric value.");
				document.frm_shop.card_no.focus();
				bval=false;
			}
		}
		
	if(document.frm_shop.cvv_code.value != "" && bval)
		{
			if(isCVVCode(document.frm_shop.cvv_code.value)==false)
			{
				alert("CVV Code must be a 3 digit numeric value.");
				document.frm_shop.cvv_code.focus();
				bval=false;
			}
		}	
	if(document.frm_shop.terms.checked !=true && bval)
	{
		alert("Please agree with Terms and Condition");
		document.frm_shop.terms.focus();
		bval=false;
	}
		
		return bval;
		//return false;
	
	
}
function loginvalidation()
{
   	var Field= Array();
	var FieldName= Array();

	Field[0]=document.login.username.value;
	Field[1]=document.login.Password.value;

	FieldName[0]="User Name";
	FieldName[1]="Password";

	var msg="";
	var bval=true;
	
	for(i=0; i<3; i++)
	{
		if(Field[i]=="")
		{
			//alert("Please fill " + FieldName[i] + " field.");
			msg = msg + "\n" + ">> " + FieldName[i];
			//bval=false;
			//break;
		}
	}
	
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}
	return bval;
}

function chk_Accessory_detail(iform){
	var blockactive;
	if(iform.accessoryfl1.value!=""){
		if(iform.Accessory1.value==""){
			alert("Please input description for #1 Accessory");
			return false;
		}
	}
	if(iform.Accessory1.value!=""){
		blockactive=true;
	}
	if(iform.accessoryfl2.value!=""){
		if(iform.Accessory2.value==""){
			alert("Please input description for #2 Accessory");
			return false;
		}
	}
	if(iform.Accessory2.value!=""){
		blockactive=true;
	}
	if(iform.accessoryfl3.value!=""){
		if(iform.Accessory3.value==""){
			alert("Please input description for #3 Accessory");
			blockactive=true;
			return false;
		}
	}
	if(iform.Accessory3.value!=""){
		blockactive=true;
	}
	if(blockactive){
		if(iform.accpurchaseprice.value=="" || iform.accrentprice.value==""){
			if(iform.CmbListType.value=="1" && iform.accpurchaseprice.value=="" ){
				alert("Please input purchase price for Accessories");
				return false;
			}else if(iform.CmbListType.value=="2" && iform.accrentprice.value==""){
				alert("Please input rent price for Accessories");
				return false;
			}else if(iform.CmbListType.value=="3"){
				alert("Please input rent and purchase price for Accessories");
				return false;
			}
			
		}else{
			if(!chkNumeric(iform.accpurchaseprice.value) || !chkNumeric(iform.accrentprice.value)){
				alert('Accessories price should be numeric');
				return false
			}	
		}
	}
	return true;
}

function chk_product_detail(iform){
	var Field= Array();
	var FieldName= Array();
	
	Field[0]=iform.CmbType.value;
	Field[1]=iform.CmbSize.value;
	Field[2]=iform.CmbColor.value;
	Field[3]=iform.CmbStyle.value;
	Field[4]=iform.CmbDesigner.value;
	Field[5]=iform.CmbLocation.value;
	Field[6]=iform.CmbMonth.value;
	Field[7]=iform.CmbYear.value;	
	Field[8]=iform.CmbUsage.value;
	//Field[9]=iform.TxtTitle.value;	
	//Field[10]=iform.TxtRetailPrice.value;		
	
	FieldName[0]="Type";
	FieldName[1]="Size";
	FieldName[2]="Color";
	FieldName[3]="Style";
	FieldName[4]="Designer";
	FieldName[5]="Location";
	FieldName[6]="Month";
	FieldName[7]="Year";
	FieldName[8]="Usage";
	//FieldName[9]="Title";
	//FieldName[10]="Retail Price";
	
	var msg="";
	var bval=true;
	if(bval){
		bval=checkAllBrowseFld();	
	}
	for(i=0; i<9; i++)
	{
		if(Field[i]=="")
		{
			msg = msg + "\n" + ">> " + FieldName[i];
		}
	}
	
	if(msg != "")
	{
		al = "Please Fill the following fields" 
		al = al + "\n" + msg;
		alert(al);
		bval=false;
	}

	if(bval)
	{
		var FieldType=Array();
		var FieldTypeName=Array();
		
		FieldType[0]=0;
		FieldType[1]=0;
		FieldType[2]=0;
		switch(iform.CmbListType.value){
			case "1":
				if(iform.TxtSellingPrice.value!=""){
					FieldType[1]=iform.TxtSellingPrice.value;
				}else{
					alert("Price for Purchase should not be blank");
					bval=false;
				}
				break;
			case "2":
				if(iform.TxtRentalPrice.value!=""){
					FieldType[2]=iform.TxtRentalPrice.value;
				}else{
					alert("Price for Rent should not be blank");
					bval=false;
				}
				break;
			case "3":
				if(iform.TxtRentalPrice.value==""){
					alert("Price for Rent should not be blank");
					bval=false;
					break;
				}
				if(iform.TxtSellingPrice.value==""){
					alert("Price for Purchase should not be blank");
					bval=false;
					break;
				}
				FieldType[1]=iform.TxtSellingPrice.value;
				FieldType[2]=iform.TxtRentalPrice.value;
				break;
				
		}
		FieldType[0]=iform.TxtRetailPrice.value;
		
		
		FieldType[3]=iform.TxtBust.value;
		FieldType[4]=iform.TxtWaist.value;		
		FieldType[5]=iform.TxtHips.value;
		FieldType[6]=iform.TxtDressLength.value;		
		FieldType[7]=iform.TxtHeightFeet.value;
		FieldType[8]=iform.TxtHeightInches.value;		
		FieldType[9]=iform.TxtHeelSize.value;

		
		FieldTypeName[0]="Retail price";
		FieldTypeName[1]="Price for Purchase";
		FieldTypeName[2]="Price for Rent";
		
		FieldTypeName[3]="Bust size";
		FieldTypeName[4]="Waist size";
		FieldTypeName[5]="Hips size";
		FieldTypeName[6]="Dress length";
		FieldTypeName[7]="Feet of owner height";
		FieldTypeName[8]="Inches of owner height";
		FieldTypeName[9]="Heel size";
		
		if(bval){
			for(i=0; i<3; i++)
			{
				if(!chkNumeric(FieldType[i])){
						alert(FieldTypeName[i] + " should be a numeric value");
						bval=false;
						break;
				}
			}
		}
		if(bval){
			for(i=3; i<9; i++)
			{
				if(FieldType[i]!="")
				{
					if(!isNumber(FieldType[i]))
					{
						msg = FieldTypeName[i] + " must be a integer value.";
						alert(msg);
						bval=false;
						break;
					}
					
				}
			}
		}
		if(bval){
			bval=chk_Accessory_detail(iform);
		}
	}
		
	return bval;
}
//for list and sell page to active/deactive priceboxes.
function showhideprice(ival){

	switch(ival){
		case "1":
			document.getElementById('tdsellprc').innerHTML="Price for Purchase ($): ";
			document.getElementById('tdrentprc').innerHTML="<s>Price for Rent ($/week): </s>";
			document.getElementById('TxtSellingPrice').style.visibility="visible";
			document.getElementById('TxtRentalPrice').style.visibility="hidden";
			enablePurchaseblock(true);
			enableRentalblock(false);
			break;
		case "2":
			document.getElementById('tdsellprc').innerHTML="<s>Price for Purchase ($): </s>";
			document.getElementById('tdrentprc').innerHTML="Price for Rent ($/week): ";
			document.getElementById('TxtSellingPrice').style.visibility="hidden";
			document.getElementById('TxtRentalPrice').style.visibility="visible";
			enablePurchaseblock(false);
			enableRentalblock(true);
			break;
		case "3":
			document.getElementById('tdsellprc').innerHTML="Price for Purchase ($): ";
			document.getElementById('tdrentprc').innerHTML="Price for Rent ($/week): ";
			document.getElementById('TxtSellingPrice').style.visibility="visible";
			document.getElementById('TxtRentalPrice').style.visibility="visible";
			enablePurchaseblock(true);
			enableRentalblock(true);
			break;
	
	}
	return true;	
	
}
function enablePurchaseblock(iflag){
	if(iflag){
		document.getElementById('radio1').disabled=false;
		document.getElementById('radio2').disabled=false;
		document.listandsell.purchasefile.disabled=false;
		document.listandsell.textareapurchase.disabled=false;
	}else{
		document.getElementById('radio1').disabled=true;
		document.getElementById('radio2').disabled=true;
		document.listandsell.purchaseradio.disabled=true;
		document.listandsell.purchasefile.disabled=true;
		document.listandsell.textareapurchase.disabled=true;
	}
}
function enableRentalblock(iflag){
	if(iflag){
		document.getElementById('radio3').disabled=false;
		document.getElementById('radio4').disabled=false;
		document.listandsell.rentalfile.disabled=false;
		document.listandsell.textarearental.disabled=false;
	}else{
		document.getElementById('radio3').disabled=true;
		document.getElementById('radio4').disabled=true;
		document.listandsell.rentalfile.disabled=true;
		document.listandsell.textarearental.disabled=true;
	}
}

function chkNumeric(ival){
	if(isNaN(ival)){
		return false;		 
	}else{
		return true;	
	}
}