//////////Company info/////////
function validateCompanyInfo(theForm){
	var reason="";
	if(theForm.industry_cate_id.value=="-1"){
		reason += "Please select industry category\n";
		theForm.industry_cate_id.style.background='#d4f1c5'; 
	}else{
			 theForm.industry_cate_id.style.background='White'; 
	}
	if(theForm.member_company_name.value == 0){
		reason += "Please enter company name!\n";
		theForm.member_company_name.style.background='#d4f1c5'; 
	}else{
		theForm.member_company_name.style.background='White'; 
	}
	if(theForm.member_street1.value == 0){
		reason += "Please enter street address 1!\n";
		theForm.member_street1.style.background='#d4f1c5'; 
	}else{
		theForm.member_street1.style.background='White'; 
	}
	if(theForm.member_city.value == 0){
		reason += "Please enter city!\n";
		theForm.member_city.style.background='#d4f1c5'; 
	}else{
		theForm.member_city.style.background='White'; 
	}
	if(theForm.member_province_id.value=="-1"){
		reason += "Please select province\n";
		theForm.member_province_id.style.background='#d4f1c5'; 
	}else{
			 theForm.member_province_id.style.background='White'; 
	}
	if(theForm.member_zip.value == 0){
		reason += "Please enter zipcode!\n";
		theForm.member_zip.style.background='#d4f1c5'; 
	}else{
		theForm.member_zip.style.background='White'; 
	}
	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
//////////Subdomain Send Message/////////
function validateInquiryForm(theForm){
	var reason="";

	if(theForm.subdomain_message_name.value == 0){
		reason += "Please enter your name!\n";
		theForm.subdomain_message_name.style.background='#d4f1c5'; 
	}else{
		theForm.subdomain_message_name.style.background='White'; 
	}
	
	reason += validateEmail(theForm.subdomain_message_email);
	
	if(theForm.subdomain_message_company.value == 0){
		reason += "Please enter your company name!\n";
		theForm.subdomain_message_company.style.background='#d4f1c5'; 
	}else{
		theForm.subdomain_message_company.style.background='White'; 
	}

	if(theForm.subdomain_message_country_code.value != 0){
		if(isNaN(theForm.subdomain_message_country_code.value)){
			reason += "Country code must be digit!\n";
			theForm.subdomain_message_country_code.style.background='#d4f1c5'; 
		}else{
			theForm.subdomain_message_country_code.style.background='White'; 
		}	
	}else{
		reason += "Please enter country code!\n";
		theForm.subdomain_message_country_code.style.background='#d4f1c5'; 
	}
	if(theForm.subdomain_message_area_code.value != 0){
		if(isNaN(theForm.subdomain_message_area_code.value)){
			reason += "Area code must be digit!\n";
			theForm.subdomain_message_area_code.style.background='#d4f1c5'; 
		}else{
			theForm.subdomain_message_area_code.style.background='White'; 
		}	
	}else{
		reason += "Please enter area code!\n";
		theForm.subdomain_message_area_code.style.background='#d4f1c5'; 
	}
	if(theForm.subdomain_message_phone.value != 0){
		if(isNaN(theForm.subdomain_message_phone.value)){
			reason += "Phone number must be digit!\n";
			theForm.subdomain_message_phone.style.background='#d4f1c5'; 
		}else{
			theForm.subdomain_message_phone.style.background='White'; 
		}	
	}else{
		reason += "Please enter phone number!\n";
		theForm.subdomain_message_phone.style.background='#d4f1c5'; 
	}

	if(theForm.subdomain_message_detail.value == 0){
		reason += "Please enter message detail!\n";
		theForm.subdomain_message_detail.style.background='#d4f1c5'; 
	}else{
		theForm.subdomain_message_detail.style.background='White'; 
	}

	if(theForm.secure_num.value == 0){
		reason += "Please enter security number!\n";
		theForm.secure_num.style.background='#d4f1c5'; 
	}else{
		theForm.secure_num.style.background='White';
	}

	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
//////////////////////////
function validateFormOnnewMemberRegister(theForm){
	var reason="";
	
	reason += validateEmail(theForm.member_email);

	reason += validatePassword(theForm.member_password);
	if(theForm.member_password.value!=theForm.passwordc.value){
		reason += "Confirm password wrong\n";
			theForm.passwordc.style.background='#d4f1c5'; 
	}else{
		theForm.passwordc.style.background='White';
	}

	if(theForm.member_name.value == ""){
		reason += "Please enter your name!\n";
		theForm.member_name.style.background='#d4f1c5'; 
	}else{
		theForm.member_name.style.background='White'; 
	}

	if(theForm.member_lastname.value == ""){
		reason += "Please enter your last name!\n";
		theForm.member_lastname.style.background='#d4f1c5'; 
	}else{
		theForm.member_lastname.style.background='White'; 
	}

	if(theForm.member_company_name.value == ""){
		reason += "Please enter company name!\n";
		theForm.member_company_name.style.background='#d4f1c5'; 
	}else{
		theForm.member_company_name.style.background='White'; 
	}

	if(theForm.member_street1.value == ""){
		reason += "Please enter street 1!\n";
		theForm.member_street1.style.background='#d4f1c5'; 
	}else{
		theForm.member_street1.style.background='White'; 
	}

	if(theForm.member_city.value == ""){
		reason += "Please enter ciry!\n";
		theForm.member_city.style.background='#d4f1c5'; 
	}else{
		theForm.member_city.style.background='White'; 
	}

	if(theForm.member_zip.value == ""){
		reason += "Please enter postal code!\n";
		theForm.member_zip.style.background='#d4f1c5'; 
	}else{
		theForm.member_zip.style.background='White'; 
	}
	
	if(theForm.selectThailand[0].checked){
				if(theForm.member_province_id.value=="-1"){
					reason += "Please select Province\n";
					theForm.member_province_id.style.background='#d4f1c5'; 
					error="Please select Province\n"
				}else{
						 theForm.member_province_id.style.background='White'; 
				}
			}else{
				if(theForm.country.value==""){
					reason += "Please select Country\n";
					theForm.country.style.background='#d4f1c5'; 
					error="Please select Country\n"
				}else{
						 theForm.country.style.background='White'; 
				}
			}

	if(theForm.member_phone_num.value != ""){
		if(isNaN(theForm.member_phone_num.value)){
			reason += "Phone number must be digit!\n";
			theForm.member_phone_num.style.background='#d4f1c5'; 
		}else{
			theForm.member_phone_num.style.background='White'; 
		}	
	}else{
		reason += "Please enter phone number!\n";
		theForm.member_phone_num.style.background='#d4f1c5'; 
	}

	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
////////////////
function validateFormOnEditProfile(theForm){ 
	var reason="";
	
	if(theForm.member_province_id.value=="-1"){
		reason += "Please select province\n";
		theForm.member_province_id.style.background='#d4f1c5'; 
	}else{
			 theForm.member_province_id.style.background='White'; 
	}
	
	reason += validatePassword(theForm.member_password);
	if(theForm.member_password.value!=theForm.passwordc.value){
		reason += "Confirm password wrong\n";
			theForm.passwordc.style.background='#d4f1c5'; 
	}else{
		theForm.passwordc.style.background='White';
	}
	
	if(theForm.member_name.value == 0){
		reason += "Please enter your name!\n";
		theForm.member_name.style.background='#d4f1c5'; 
	}else{
		theForm.member_name.style.background='White'; 
	}

	if(theForm.member_lastname.value == 0){
		reason += "Please enter your last name!\n";
		theForm.member_lastname.style.background='#d4f1c5'; 
	}else{
		theForm.member_lastname.style.background='White'; 
	}

	if(theForm.member_street1.value == 0){
		reason += "Please enter street 1!\n";
		theForm.member_street1.style.background='#d4f1c5'; 
	}else{
		theForm.member_street1.style.background='White'; 
	}

	if(theForm.member_street2.value == 0){
		reason += "Please enter street 2!\n";
		theForm.member_street2.style.background='#d4f1c5'; 
	}else{
		theForm.member_street2.style.background='White'; 
	}

	if(theForm.member_city.value == 0){
		reason += "Please enter ciry!\n";
		theForm.member_city.style.background='#d4f1c5'; 
	}else{
		theForm.member_city.style.background='White'; 
	}

	if(theForm.member_zip.value == 0){
		reason += "Please enter zip code!\n";
		theForm.member_zip.style.background='#d4f1c5'; 
	}else{
		theForm.member_zip.style.background='White'; 
	}

	if(theForm.member_phone_num.value!=""){
		if(theForm.member_area_code.value==""&&theForm.member_area_code.value=="0"){
			reason += "Please enter area code!\n";
			theForm.member_area_code.style.background='#d4f1c5';
		}else{
			theForm.member_area_code.style.background='White';
		}
	}

	if(theForm.member_phone_num.value==""&&theForm.member_mobile_num.value==""){
		reason += "Please phone number or mobile number!\n";
		theForm.member_phone_num.style.background='#d4f1c5';
	}else{
		theForm.member_phone_num.style.background='White';
	}

	if(theForm.member_company_name.value == 0){
		reason += "Please enter company name!\n";
		theForm.member_company_name.style.background='#d4f1c5'; 
	}else{
		theForm.member_company_name.style.background='White'; 
	}

	if(theForm.member_dep.value=="-1"){
		reason += "Please select department\n";
		theForm.member_dep.style.background='#d4f1c5'; 
	}else{
		theForm.member_dep.style.background='White'; 
	}

	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
////////////////

function returnValidateFormOnSubmitEmail(theForm){
	var reason="";
	reason += validateEmail(theForm.member_email);
	
	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
////////////////

function validateAdminMemberFormOnSubmit(theForm){
	var reason="";
	reason += validateEmpty(theForm.member_subdomain);
	reason += validateEmpty(theForm.member_email);
	reason += validateEmail(theForm.member_email);
	reason += validateEmpty(theForm.member_type);
	reason += validateEmpty(theForm.member_package);
	reason += validateEmpty(theForm.member_paytotal);

	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}

function validateContactFormOnSubmit(theForm,authen){
	var reason="";

	if(theForm.message_subject.value == ""){
		reason += "Please enter message subject!\n";
		theForm.message_subject.style.background='#d4f1c5'; 
	}else{
		theForm.message_subject.style.background='White'; 
	}

	if(theForm.message_detail.value == ""){
		reason += "Please enter message detail!\n";
		theForm.message_detail.style.background='#d4f1c5'; 
	}else{
		theForm.message_detail.style.background='White'; 
	}

	if(authen==1){
		if(theForm.contact_relationship[0].checked==true){
			
			if(theForm.business_email.value == ""){
				reason += "Please enter your email!\n";
				theForm.business_email.style.background='#d4f1c5'; 
			}else{
				theForm.business_email.style.background='White'; 
			}
			
			if(theForm.firstname.value == ""){
				reason += "Please enter your first name!\n";
				theForm.firstname.style.background='#d4f1c5'; 
			}else{
				theForm.firstname.style.background='White'; 
			}

			if(theForm.lastname.value == ""){
				reason += "Please enter your last name!\n";
				theForm.lastname.style.background='#d4f1c5'; 
			}else{
				theForm.lastname.style.background='White'; 
			}

			if(theForm.company_name.value == ""){
				reason += "Please enter your company name!\n";
				theForm.company_name.style.background='#d4f1c5'; 
			}else{
				theForm.company_name.style.background='White'; 
			}
			
			if(isNaN(theForm.country_code.value)){
				reason += "Country code must be digit!\n";
				theForm.country_code.style.background='#d4f1c5'; 
			}else{
				theForm.country_code.style.background='White'; 
			}
			if(isNaN(theForm.area_code.value)){
				reason += "Area code must be digit!\n";
				theForm.area_code.style.background='#d4f1c5'; 
			}else{
				theForm.area_code.style.background='White'; 
			}
			
			if(isNaN(theForm.phone_number.value)){
				reason += "Phone number must be digit!\n";
				theForm.phone_number.style.background='#d4f1c5'; 
			}else{
				theForm.phone_number.style.background='White'; 
			}
			
			reason += validateEmpty(theForm.country_code);
			reason += validateEmpty(theForm.area_code);
			reason += validateEmpty(theForm.phone_number);
			
		}else{
			theForm.business_email.style.background='white';
			theForm.firstname.style.background='white';
			theForm.lastname.style.background='white';
			theForm.company_name.style.background='white';
			theForm.country_code.style.background='white';
			theForm.area_code.style.background='white';
			theForm.phone_number.style.background='white';
		}
	}
	if(isNaN(theForm.Initial_Order_Quantity.value)){
		reason += "Initial Order Quantity must be digit only!\n";
		theForm.Initial_Order_Quantity.style.background='#d4f1c5';
	}else{
		theForm.Initial_Order_Quantity.style.background='white';
	}
	
	if(reason !=""){
		alert("Green fields need correction:\n" + reason);
		return false;
	}
	return true;
}
////////////////
function validatePostNewserviceFormOnSubmit(theForm){
	var reason="";
	
	if(theForm.service_name.value == 0){
		reason += "Please enter service subject\n";
		theForm.service_name.style.background='#d4f1c5'; 
	}else{
		theForm.service_name.style.background='White'; 
	}

	if(theForm.service_keyword1.value == 0){
		reason += "Please enter service keyword\n";
		theForm.service_keyword1.style.background='#d4f1c5'; 
	}else{
		theForm.service_keyword1.style.background='White'; 
	}

	if(theForm.service_cate_id.value=="-1"){
		reason += "Please select service category\n";
		theForm.service_cate_id.style.background='#d4f1c5'; 
		error="Please select Product Category\n"
	}else{
			 theForm.service_cate_id.style.background='White'; 
	}

	if(theForm.brief_description.value == 0){
		reason += "Please enter service brief description\n";
		theForm.brief_description.style.background='#d4f1c5'; 
	}else{
		theForm.brief_description.style.background='White'; 
	}
	
	if(theForm.detailed_description.value.length == 0){
		reason += "Please enter service detail description!\n";
		theForm.detailed_description.style.background='#d4f1c5'; 
	}else{
		theForm.detailed_description.style.background='White'; 
	}
	
	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}
  return true;
}
////////////////

function validateNewbuyingLeads(theForm){
	var reason="";
	if(theForm.buying_lead_subject.value == 0){
		reason += "Please enter buying lead subject\n";
		theForm.buying_lead_subject.style.background='#d4f1c5'; 
	}else{
		theForm.buying_lead_subject.style.background='White'; 
	}
	
	if(theForm.buying_lead_keyword1.value == 0){
		reason += "Please enter buying lead keyword\n";
		theForm.buying_lead_keyword1.style.background='#d4f1c5'; 
	}else{
		theForm.buying_lead_keyword1.style.background='White'; 
	}

	if(theForm.buying_cate_id.value=="-1"){
		reason += "Please select buying lead category\n";
		theForm.buying_cate_id.style.background='#d4f1c5'; 
	}else{
			 theForm.buying_cate_id.style.background='White'; 
	}

	if(theForm.buying_lead_brief_des.value == 0){
		reason += "Please enter buying lead brief description\n";
		theForm.buying_lead_brief_des.style.background='#d4f1c5'; 
	}else{
		theForm.buying_lead_brief_des.style.background='White'; 
	}
	
	if(theForm.buying_lead_detail_des.value.length == 0){
		reason += "Please enter buying lead detail description!\n";
		theForm.buying_lead_detail_des.style.background='#d4f1c5'; 
	}else{
		theForm.buying_lead_detail_des.style.background='White'; 
	}

	if(theForm.buying_lead_valid.value=="-1"){
		reason += "Please select buying lead valid for\n";
		theForm.buying_lead_valid.style.background='#d4f1c5';
		//error="Please select  valid for\n"
	}else{
			 theForm.buying_lead_valid.style.background='White';
	}

	//<!-----Hardest Condition------>
	if (theForm.buying_lead_currency.value=="-1"){
		if(theForm.buying_lead_amont_from.value.length !="0"){
			reason += "Please select currency!\n";
			theForm.buying_lead_currency.style.background='#d4f1c5';
		}else{
			if(theForm.buying_lead_amont_to.value.length !="0"){
				reason += "Please input price range start1 value!\n";
				theForm.buying_lead_amont_from.style.background='#d4f1c5';
			}else{
				theForm.buying_lead_amont_from.style.background='White';
			}
			theForm.buying_lead_currency.style.background='White';
		}
	}else{
		if(theForm.buying_lead_amont_from.value.length=="0"){
			reason += "Please enter price range begin value!\n";
			theForm.buying_lead_amont_from.style.background='#d4f1c5'; 
		}else{
			if(isNaN(theForm.buying_lead_amont_from.value)){
				reason += "Price range begin value must be digit!\n";
				theForm.buying_lead_amont_from.style.background='#d4f1c5'; 
			}else{
				theForm.buying_lead_amont_from.style.background='White';
			}
		}

		if(theForm.buying_lead_amont_to.value.length!="0"){
			if(isNaN(theForm.buying_lead_amont_to.value)){
				reason += "Price range end value be digit!\n";
				theForm.buying_lead_amont_to.style.background='#d4f1c5';
			}else{
				theForm.buying_lead_amont_to.style.background='White'; 
			}
			if(theForm.buying_lead_amont_from.value>theForm.buying_lead_amont_to.value){
				reason += "Price range begin value must be less than end value, example: 250 - 300\n";
				theForm.buying_lead_amont_from.style.background='#d4f1c5'; 
			}else{
				theForm.buying_lead_amont_from.style.background='White';
			}
		}else{
			theForm.buying_lead_amont_to.style.background='White';
		}
		
		theForm.buying_lead_currency.style.background='White';
	}
	//<!----------->
	
	if(theForm.buying_lead_minimum_quatity.value.length!="0"){
		if(isNaN(theForm.buying_lead_minimum_quatity.value)){
			reason += "Minimum order quality must be digit!\n";
			theForm.buying_lead_minimum_quatity.style.background='#d4f1c5'; 
		}else{
			theForm.buying_lead_minimum_quatity.style.background='White'; 
		}
		if(theForm.buying_lead_minimum_quatity_unit.value=="-1"){
			reason += "Please select minimum quality unit!\n";
			theForm.buying_lead_minimum_quatity_unit.style.background='#d4f1c5'; 
		}else{
			theForm.buying_lead_minimum_quatity_unit.style.background='White'; 
		}
	}else{
		if(theForm.buying_lead_minimum_quatity.value!="-1"){
			reason += "Please enter minimum order quality!\n";
			theForm.buying_lead_minimum_quatity.style.background='#d4f1c5'; 
		}else{
			theForm.buying_lead_minimum_quatity.style.background='White'; 
		}
	}
	

	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}
  return true;
}

function validateNewSellingLeads(theForm){
	var reason="";
	/*var btn11=valButton11(theForm.selling_leads_type);
	if (btn11==null){
		reason +="Please select member lead type\n";
	}
	function valButton11(btn11) {
    var cnt11=-1;
    for (var i=btn11.length-1; i > -1; i--) {
        if (btn11[i].checked) {cnt11=i; i=-1;}
    }
    if (cnt11 > -1) return btn11[cnt11].value;
    else return null;
	}
	*/
	if(theForm.selling_leads_subject.value.length == 0){
		reason += "Please enter selling subject!\n";
		theForm.selling_leads_subject.style.background='#d4f1c5'; 
	}else{
		theForm.selling_leads_subject.style.background='White';
	}

	if(theForm.selling_leads_cate_id.value=="-1"){
		reason += "Please select Product Category\n";
		theForm.selling_leads_cate_id.style.background='#d4f1c5'; 
		error="Please select Product Category\n"
	}else{
			 theForm.selling_leads_cate_id.style.background='White'; 
	}

	if(theForm.selling_leads_brief_des.value.length == 0){
		reason += "Please enter selling brief description!\n";
		theForm.selling_leads_brief_des.style.background='#d4f1c5'; 
	}else{
		theForm.selling_leads_brief_des.style.background='White';
	}

	if(theForm.selling_leads_detail_des.value.length == 0){
		reason += "Please enter selling detail description!\n";
		theForm.selling_leads_detail_des.style.background='#d4f1c5'; 
	}else{
		theForm.selling_leads_detail_des.style.background='White'; 
	}

	if(theForm.selling_leads_valid.value=="-1"){
		reason += "Please select selling valid for\n";
		theForm.selling_leads_valid.style.background='#d4f1c5'; 
	}else{
			 theForm.selling_leads_valid.style.background='White';
	}

	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}

  return true;
}


function validatePostNewProductFormOnSubmit(theForm){
	var FOB_price_from=parseInt(theForm.FOB_price_from.value);
	var FOB_price_to=parseInt(theForm.FOB_price_to.value);

	var reason="";
	if(theForm.product_name.value.length == 0){
		reason += "Please enter product name!\n";
		theForm.product_name.style.background='#d4f1c5'; 
	}else{
		theForm.product_name.style.background='White'; 
	}
	
	if(theForm.product_keyword1.value.length == 0){
		reason += "Please enter product keyword!\n";
		theForm.product_keyword1.style.background='#d4f1c5'; 
	}else{
		theForm.product_keyword1.style.background='White'; 
	}

	if (theForm.product_cate_id.value=="-1")
	{
		reason += "Please select product category!\n";
		theForm.product_cate_id.style.background='#d4f1c5'; 
	}else{
		theForm.product_cate_id.style.background='White'; 
	}
	
	if(theForm.placeoforigin.value.length == 0){
		reason += "Please enter product origin place!\n";
		theForm.placeoforigin.style.background='#d4f1c5'; 
	}else{
		theForm.placeoforigin.style.background='White'; 
	}
	
	if(theForm.brandname.value.length == 0){
		reason += "Please enter product brandname!\n";
		theForm.brandname.style.background='#d4f1c5'; 
	}else{
		theForm.brandname.style.background='White'; 
	}

	if(theForm.brief_description.value.length == 0){
		reason += "Please enter product brief description!\n";
		theForm.brief_description.style.background='#d4f1c5'; 
	}else{
		theForm.brief_description.style.background='White'; 
	}

	if(theForm.detailed_description.value.length == 0){
		reason += "Please enter product detail description!\n";
		theForm.detailed_description.style.background='#d4f1c5'; 
	}else{
		theForm.detailed_description.style.background='White'; 
	}

	if(theForm.currency.value=="-1"){
		if(theForm.FOB_price_from.value.length!="0"){
			reason += "Please enter Currency!\n";
			theForm.currency.style.background='#d4f1c5';
		}else{
			theForm.currency.style.background='White';
			if(theForm.FOB_price_to.value.length!="0"){
				if(isNaN(theForm.FOB_price_to.value)){
					reason += "FOB price end must be digit only!\n";
					theForm.FOB_price_to.style.background='#d4f1c5'; 
				}else{
					theForm.FOB_price_to.style.background='White'; 
				}
				reason += "Please FOB price start!\n";
				theForm.FOB_price_from.style.background='#d4f1c5';
			}else{
				theForm.FOB_price_from.style.background='White';
			}
		}

		if(theForm.FOB_price_from.value.length!="0"){
			if(theForm.FOB_price_to.value.length!="0"){
				if(FOB_price_from>FOB_price_to){
					reason += "FOB price start must be less than end, example: 250 - 300\n";
					theForm.FOB_price_from.style.background='#d4f1c5';
					reason += "Please enter Currency!\n";
					theForm.currency.style.background='#d4f1c5';
				}else{
					theForm.FOB_price_from.style.background='White';
					theForm.currency.style.background='#d4f1c5';
				}
			}else{
				theForm.FOB_price_to.style.background='White';
			}
		}else{
			theForm.FOB_price_from.style.background='White';
		}
	}else{
		if(theForm.FOB_price_from.value.length=="0"){
			reason += "Please enter FOB price srart!\n";
			theForm.FOB_price_from.style.background='#d4f1c5';
		}else{
			if(isNaN(theForm.FOB_price_from.value)){
				reason += "FOB price start must be digit!\n";
				theForm.FOB_price_from.style.background='#d4f1c5';
			}else{
				theForm.FOB_price_from.style.background='White';
				theForm.currency.style.background='White';
			}
		}
		
		if(theForm.FOB_price_to.value.length!="0"){
			if(theForm.FOB_price_from.value.length=="0"){
				//reason += "Please enter FOB price srart!\n";
				theForm.FOB_price_from.style.background='#d4f1c5';
			}else{
				if(FOB_price_from>FOB_price_to){
				reason += "FOB price start must be less than end, example: 250 - 300\n";
				theForm.FOB_price_from.style.background='#d4f1c5'; 
				}else{
					theForm.FOB_price_from.style.background='White'; 
				}
			}
		}else{
			theForm.FOB_price_to.style.background='White';
			theForm.currency.style.background='White';
		}

	}
	if(theForm.minimum_order_quantity.value.length != 0){
		if(isNaN(theForm.minimum_order_quantity.value)){
			reason += "Minimum order quantity must be digit only!\n";
			theForm.minimum_order_quantity.style.background='#d4f1c5'; 
		}else{
			theForm.minimum_order_quantity.style.background='White'; 
		}

		if(theForm.minimum_order_quantity_uit.value=="-1"){
			reason += "Please select minimum order quantity unit\n";
			theForm.minimum_order_quantity_uit.style.background='#d4f1c5'; 
		}else{
			theForm.minimum_order_quantity_uit.style.background='White';
		}
	}else{
		theForm.minimum_order_quantity.style.background='White'; 
		theForm.minimum_order_quantity_uit.style.background='White';
	}
	//Chain Select
	if(theForm.supply_ability.value.length != 0){
		if(isNaN(theForm.supply_ability.value)){
			reason += "Supply ability must be digit only!\n";
			theForm.supply_ability.style.background='#d4f1c5'; 
		}else{
			theForm.supply_ability.style.background='White'; 
		}
		if(theForm.supply_ability_unit.value=="-1"){
			reason += "Please select supply ability\n";
			theForm.supply_ability_unit.style.background='#d4f1c5'; 
		}else{
			theForm.supply_ability_unit.style.background='White';
		}
		if(theForm.supply_ability_per.value=="-1"){
			reason += "Please select Supply Abillity Time Unit\n";
			theForm.supply_ability_per.style.background='#d4f1c5'; 
		}else{
			theForm.supply_ability_per.style.background='White';
		}
	}else{
		theForm.supply_ability.style.background='White'; 
		theForm.supply_ability_unit.style.background='White';
		theForm.supply_ability_per.style.background='White';
	}
	/*
	if(theForm.packaging.value.length == 0){
		reason += "Please enter packaging!\n";
		theForm.packaging.style.background='#d4f1c5'; 
	}else{
		theForm.packaging.style.background='White'; 
	}

	if(theForm.delivery_lead_time.value.length == 0){
		reason += "Please enter delivery lead time!\n";
		theForm.delivery_lead_time.style.background='#d4f1c5'; 
	}else{
		theForm.delivery_lead_time.style.background='White'; 
	}
	*/
	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}

  return true;
}
/// Send message to QuinL
function validateProfileFormOnSubmit(theForm){
var reason="";
	if(theForm.sendto.value=="-1"){
			reason += "Please select Send message to\n";
			theForm.sendto.style.background='#d4f1c5'; 
	}else{
			 theForm.sendto.style.background='White';
	}
	
	if(theForm.customer_country_id.value=="-1"){
			reason += "Please select Country\n";
			theForm.customer_country_id.style.background='#d4f1c5'; 
	}else{
			 theForm.customer_country_id.style.background='White';
	}

	if(theForm.customer_name.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.customer_name.style.background='#d4f1c5'; 
	}else{
		theForm.customer_name.style.background='White'; 
	}

	reason += validateEmail(theForm.customer_email);

	if(theForm.customer_company.value.length == 0){
		reason += "Please enter company!\n";
		theForm.customer_company.style.background='#d4f1c5'; 
	}else{
		theForm.customer_company.style.background='White'; 
	}

	if(theForm.customer_country_code.value.length != 0){
		if(isNaN(theForm.customer_country_code.value)){
			reason += "Your country code must be digit only!\n";
			theForm.customer_country_code.style.background='#d4f1c5'; 
		}else{
			theForm.customer_country_code.style.background='White'; 
		}
	}else{
		reason += "Please enter country code!\n";
		theForm.customer_country_code.style.background='#d4f1c5'; 
	}

	if(theForm.customer_area_code.value.length != 0){
		if(isNaN(theForm.customer_area_code.value)){
			reason += "Your area code must be digit only!\n";
			theForm.customer_area_code.style.background='#d4f1c5'; 
		}else{
			theForm.customer_area_code.style.background='White'; 
		}
	}else{
		reason += "Please enter area code!\n";
		theForm.customer_area_code.style.background='#d4f1c5'; 
	}

	if(theForm.customer_phone.value.length != 0){
		if(isNaN(theForm.customer_phone.value)){
			reason += "Your phone must be digit only!\n";
			theForm.customer_phone.style.background='#d4f1c5'; 
		}else{
			theForm.customer_phone.style.background='White'; 
		}
	}else{
		reason += "Please enter phone number!\n";
		theForm.customer_phone.style.background='#d4f1c5'; 
	}
	
	if(theForm.customer_message.value.length == 0){
		reason += "Please enter message!\n";
		theForm.customer_message.style.background='#d4f1c5'; 
	}else{
		theForm.customer_message.style.background='White'; 
	}

	if(theForm.secure_num.value == 0){
		reason += "Please enter security number!\n";
		theForm.secure_num.style.background='#d4f1c5'; 
	}else{
		theForm.secure_num.style.background='White';
	}

	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateFormOnSubmit(theForm,randomStr){
    var reason="";
	if(theForm.member_province_id.value=="-1"){
			reason += "Please select Country\n";
			theForm.member_province_id.style.background='#d4f1c5'; 
	}else{
			 theForm.member_province_id.style.background='White';
	}
	//reason += validateEmpty(theForm.member_type);
	var btn=valButton(theForm.member_type);
	if (btn==null){
		reason +="Please select Member Type (You are a..)\n";
	}
	function valButton(btn) {
    var cnt=-1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt=i; i=-1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
	}
	
	//reason += validateEmpty(theForm.have_website);
	var btn2=valButton2(theForm.member_havewebsite);
	if (btn2==null){
		reason +="Please select Member website (Do you have a website..?)\n";
	}
	function valButton2(btn2) {
    var cnt2=-1;
    for (var i=btn2.length-1; i > -1; i--) {
        if (btn2[i].checked) {cnt2=i; i=-1;}
    }
    if (cnt2 > -1) return btn2[cnt2].value;
    else return null;
	}
	reason += validateEmpty(theForm.business_email);
    reason += validateEmail(theForm.business_email);
	reason += validateEmpty(theForm.password);
	reason += validatePassword(theForm.password);
	   if(theForm.password.value!=theForm.passwordc.value){
				reason += "Password invalid\n";
				theForm.password.style.background='#d4f1c5'; 
				error="The required field has not been filled in\n"
		}else{
				 theForm.password.style.background='White';
		}

	reason += validateEmpty(theForm.member_name);
	reason += validateEmpty(theForm.member_lastname);
	//reason += validateEmpty(theForm.sex);
	var btn3=valButton3(theForm.sex);
	if (btn3==null){
		reason +="Please select your Sex\n";
	}
	function valButton3(btn3){
	var cnt3=-1;
	for (var i=btn3.length-1; i > -1; i--){
			if(btn3[i].checked){
				cnt3=i;
				i= -1;
		}
	}
	if(cnt3 > -1)
		return btn3[cnt3].value;
	else return null;
	}

	reason += validateEmpty(theForm.member_street);
	reason += validateEmpty(theForm.member_city);
	reason += validateEmpty(theForm.member_zip);
	reason += validateEmpty(theForm.country_code);
	reason += validateEmpty(theForm.area_code);
	reason += validateEmpty(theForm.phone_number);
	reason += validatePhone(theForm.country_code);
	reason += validatePhone(theForm.area_code);
	reason += validatePhone(theForm.phone_number);
	reason += validateEmpty(theForm.company_name);
		
		if(isNaN(theForm.fax_country_code.value)){
			reason += "Fax Country code must be digit only!\n";
			theForm.fax_country_code.style.background='#d4f1c5'; 
		}else{
				 theForm.fax_country_code.style.background='White';
		}
		if(isNaN(theForm.fax_area_code.value)){
			reason += "Your Fax area code must be digit only!\n";
			theForm.fax_area_code.style.background='#d4f1c5';
		}else{
				 theForm.fax_area_code.style.background='White';
		}
		if(isNaN(theForm.fax_phone_number.value)){
			reason += "Your Fax number must be digit only!\n";
			theForm.fax_phone_number.style.background='#d4f1c5';
		}else{
				 theForm.fax_phone_number.style.background='White';
		}
		if(isNaN(theForm.mobile_phone_number_code.value)){
			reason += "Your Mobile code must be digit only!\n";
			theForm.mobile_phone_number_code.style.background='#d4f1c5';
		}else{
				 theForm.mobile_phone_number_code.style.background='White';
		}
		if(isNaN(theForm.mobile_phone_number.value)){
			reason += "Your Mobile number must be digit only!\n";
			theForm.mobile_phone_number.style.background='#d4f1c5';
		}else{
				 theForm.mobile_phone_number.style.background='White';
		}
		if(theForm.member_dep.value=="-1"){
				reason += "Please select department\n";
				theForm.member_dep.style.background='#d4f1c5'; 
		}else{
				 theForm.member_dep.style.background='White';
		}
	
		if(theForm.secure_num.value != 0){
			if(theForm.secure_num.value!=randomStr){
					reason += "Secure Number invalid.\n";
					theForm.secure_num.style.background='#d4f1c5'; 
			}else{
					 theForm.secure_num.style.background='White';
			}
		}else{
			reason += "Please enter security code!\n";
			theForm.secure_num.style.background='#d4f1c5'; 
		}
  
	if (reason != "") {
		alert("Green fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateEmpty(fld) {
    var error="";
  
    if (fld.value.length == 0) {
		error="Please full fill in green field. \n";
        fld.style.background='#d4f1c5'; 
    } else {
        fld.style.background='White';
    }
    return error;   
}
function validateUsername(fld) {
    var error="";
    var illegalChars=/\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background='#d4f1c5'; 
        error="You didn't enter a username\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background='#d4f1c5'; 
        error="The username is the wrong length\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background='#d4f1c5'; 
        error="The username contains illegal characters\n";
    } else {
        fld.style.background='White';
    } 
    return error;
}
function validatePassword(fld) {
    var error="";
    //var illegalChars=/[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background='#d4f1c5';
        error="You didn't enter a password.\n";
    }else if ((fld.value.length < 6) || (fld.value.length > 15)){
        error="The password is the wrong length\n";
        fld.style.background='#d4f1c5';
    //} else if (illegalChars.test(fld.value)) {
    //    error="The password contains illegal characters\n";
    //    fld.style.background='#d4f1c5';
    }else if(!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))){
        error="The password must contain at least one numeral\n";
        fld.style.background='#d4f1c5';
    }else{
        fld.style.background='White';
    }
   return error;
}   
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld=trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter=/^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background='#d4f1c5';
        error="You didn't enter an email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background='#d4f1c5';
        error="Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background='#d4f1c5';
        error="The email address contains illegal characters\n";
    } else {
        fld.style.background='White';
    }
    return error;
}
function validatePhone(fld) {
    var error="";
    var stripped=fld.value.replace(/[\(\)\.\-\ ]/g, '');     

	if (isNaN(parseInt(stripped))) {
        error="The phone number contains illegal characters\n";
        fld.style.background='#d4f1c5';
    }else {
        fld.style.background='White';
    }// else if (!(stripped.length == 10)) {
      //  error="The phone number is the wrong length. Make sure you included an area code.\n";
      //  fld.style.background='#d4f1c5';
  //  } 
    return error;
}

//-----------------------------------------------------------------------------------------------------------------------------

	function changeLoginFeild(){	
		if(document.getElementById('member_country_id').value!=""){
			document.getElementById('member_province_id').disabled=false;
			if(document.getElementById('member_country_id').value==1){
				document.getElementById('member_province_id').disabled=false;
			}else{
				document.getElementById('member_province_id').disabled=true;
			}
		}else{
			document.getElementById('member_province_id').disabled=true;
		}
	}

	function checkSignup(theform,option){
		var error=0;
		if(theform.member_country_id.value==""){
			error=1;
			document.getElementById("country_error").innerHTML="Please select your country";
		}else{
			document.getElementById("country_error").innerHTML="";
		}
		if(theform.member_country_id.value=="1"){
			if(theform.member_province_id.value==""){
				error=1;
				document.getElementById("member_province_id_error").innerHTML="Please select your province";
			}else{
				document.getElementById("member_province_id_error").innerHTML="";
			}
		}else{
			document.getElementById("member_province_id_error").innerHTML="";
		}
		if(theform.business_email.value==""){
			error=1;
			document.getElementById("business_email_error").innerHTML="Please input your email";
		}else{
			if(checkEmailInput("business_email")!=""){
				error=1;
				document.getElementById("business_email_error").innerHTML="Invalid email address";
			}else{
				document.getElementById("business_email_error").innerHTML="";
			}
		}
		if(theform.password.value==""){
			error=1;
			document.getElementById("password_error").innerHTML="Please input your password";
		}else{
			if(theform.password.value.length>=7&&theform.password.value.length<=20){
					document.getElementById("password_error").innerHTML="";
			}else{
					document.getElementById("password_error").innerHTML="Please use both letters and numbers in your password to improve account security. Enter between 7 and 20 characters (A-Z, a-z, 0-9, no spaces). Try to use a hard to guess password for your own protection.";
			}
		}
		if(theform.passwordc.value==""){
			error=1;
			document.getElementById("passwordc_error").innerHTML="Please input your confirm password";
		}else{
			document.getElementById("passwordc_error").innerHTML="";
			if(theform.password.value!=theform.passwordc.value){
				error=1;
				document.getElementById("passwordc_error").innerHTML="Confirm password invalid please input again.";
			}
		}
		if(theform.member_name.value==""){
			error=1;
			document.getElementById("member_name_error").innerHTML="Please input your name";
		}else{
			document.getElementById("member_name_error").innerHTML="";
		}
		if(theform.member_lastname.value==""){
			error=1;
			document.getElementById("member_lastname_error").innerHTML="Please input your lastname";
		}else{
			document.getElementById("member_lastname_error").innerHTML="";
		}

		if(theform.member_phone_num.value==""&&theform.member_mobile_num.value==""){
			error=1;
			document.getElementById("phone_error").innerHTML="Please input Phone or Mobile number";
		}else{
			document.getElementById("phone_error").innerHTML="";
			if(theform.member_phone_num.value!=""){
				if(theform.member_country_code.value==""){
					error=1;
					document.getElementById("member_country_code_error").innerHTML="please input country code";
				}else{
					document.getElementById("member_country_code_error").innerHTML="";
					if(isNaN(theform.member_country_code.value)){
						error=1;
						document.getElementById("member_country_code_error").innerHTML="^ please input digit";
					}else{
						document.getElementById("member_country_code_error").innerHTML="";
					}
				}
				if(theform.member_area_code.value==""){
					error=1;
					document.getElementById("member_area_code_error").innerHTML="^ please input area code";
				}else{
					document.getElementById("member_area_code_error").innerHTML="";
					if(isNaN(theform.member_area_code.value)){
						error=1;
						document.getElementById("member_area_code_error").innerHTML="^ please input digit";
					}else{
						document.getElementById("member_area_code_error").innerHTML="";
					}
				}
				if(theform.member_phone_num.value==""){
					error=1;
					document.getElementById("member_phone_num_error").innerHTML="input phone number";
				}else{
					document.getElementById("member_phone_num_error").innerHTML="";
					if(isNaN(theform.member_phone_num.value)){
						error=1;
						document.getElementById("member_phone_num_error").innerHTML="^ please input digit";
					}else{
						document.getElementById("member_phone_num_error").innerHTML="";
					}
				}
				if(theform.member_mobile_num.value!=""){
					if(isNaN(theform.member_mobile_num.value)){
						error=1;
						document.getElementById("member_mobile_num_error").innerHTML="^ please input digit";
					}else{
						document.getElementById("member_mobile_num_error").innerHTML="";
					}
				}
			}else{
				if(theform.member_mobile_num.value!=""){
					if(theform.member_country_code.value==""){
						error=1;
						document.getElementById("member_country_code_error").innerHTML="input country code";
					}else{
						document.getElementById("member_country_code_error").innerHTML="";
						if(isNaN(theform.member_country_code.value)){
							error=1;
							document.getElementById("member_country_code_error").innerHTML="^ please input digit";
						}else{
							document.getElementById("member_country_code_error").innerHTML="";
						}
					}
					if(isNaN(theform.member_mobile_num.value)){
						error=1;
						document.getElementById("member_mobile_num_error").innerHTML="^ please input digit";
					}else{
						document.getElementById("member_mobile_num_error").innerHTML="";
					}
				}
			}
		}
		if(theform.member_subdomain.value==""){
			error=1;
			document.getElementById("member_subdomain_error").innerHTML="^ Please input folder name";
		}else{
			document.getElementById("member_subdomain_error").innerHTML="";
		}

		if(theform.member_company_name.value==""){
			error=1;
			document.getElementById("member_company_name_error").innerHTML="Please input your company name";
		}else{
			document.getElementById("member_company_name_error").innerHTML="";
		}
		if(theform.secure_num.value==""){
			error=1;
			document.getElementById("secure_num_error").innerHTML="Please input security number from the picture";
		}else{
			document.getElementById("secure_num_error").innerHTML="";
		}
		if(error){
			return false;
		}else{
			return true;
		}
	}
	function checkEmailInput(id) {
		   var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address=document.getElementById(id).value;
		   if(reg.test(address) == false) {
			  return "Invalid Email Address<br>";
		   }else{
			  return "";
		   }
	}
	function checkURLInput(id) {
		   var reg=/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/;
		   var URL=document.getElementById(id).value;
		   var v1=new RegExp(); 
		   v1.compile(reg); 
		   if(!(v1.test(URL))){ 
			  return "Invalid URL.<br>";
		   }else{
			  return "";
		   }
	}
	function checkCharacterInput(id)
	{
		var reg=/\W/;
		var number=document.getElementById(id).value;
		if(reg.test(number)) {
			return "Please input your Character.<br>";
		 }else{
			return "";
		 }
	}
