if(window.ActiveXObject) {
	try {
		var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) {
		var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
} 
else {
	var oHTTP = new XMLHttpRequest();
}


function showLOV(id){
	var chkBoxId="cat_"+id;
	var lovId="lov_"+id;
	if(document.getElementById(chkBoxId).checked==true){
		document.getElementById(lovId).style.display='';
	}
	else{
		document.getElementById(lovId).style.display='none';
	}
}

function checkVenForm1(){
	var element=document.ven_form1.elements;
	var chk=0;
	for(var i=0;i<element.length;i++){
		if(element[i].name=="cat[]"){
			if(element[i].checked==true){
				var id=element[i].value;
				var selId="sel_lov_"+id;
				var len=document.getElementById(selId).length;
				var selChk=0;
				
				for(var k=0;k<len;k++){
					if(document.getElementById(selId)[k].selected==true){
						selChk++;
						break;
					}
				}

				if(selChk==0){
					alert("Please select LOV");
					return false;
					break;
				}

				chk++;
			}
		}
	}

	if(chk==0){
		alert("Please select category");
		return false;
	}


	var chk=0;
	var type=0;
	for(var i=0;i<2;i++){
		if(document.ven_form1.user_type[i].checked==true){
			type=(i+1);
			chk++;
			break;
		}
	}

	if(chk==0){
		alert("Please select existing vendor or new vendor");
		return false;
	}
	
	var chk=0;
	for(var i=0;i<2;i++){
		if(document.ven_form1.user_country[i].checked==true){
			chk++;
			break;
		}
	}

	if(chk==0){
		alert("Please select indian / overseas vendor");
		return false;
	}

	if(type==2){
		if(document.ven_form1.vendor_code.value==""){
			alert("Please enter vendor code");
			document.ven_form1.vendor_code.focus();
			return false;
		}
	}

	var action="";
	if(document.ven_form1.user_country[0].checked==true){
		action="registration_indian.php";
	}
	else{
		action="registration_overseas.php";
	}

	document.ven_form1.action=action;

}

function showVendorCode(val){
	if(val==2){
		document.getElementById("ven_code").style.display='';
		document.ven_form1.vendor_code.focus();
	}
	else{
		document.getElementById("ven_code").style.display='none';
	}
}

function openSearchPopUp(){
	win=window.open('search_vendor.php','','width=700,height=600,toolbar=no,menubar=no,titlebar=no,scrollbars=yes');
	win.moveTo(400,200);
	window.opener=self;
}

function fetchVendor(name){
	var page="fetch_vendors.php?name="+name+"&mode=vendorList";
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		document.getElementById('msg_load').style.display='';
		document.getElementById('results').style.display='none';
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="none") {
				document.getElementById('results').style.display='';
				document.getElementById('results').innerHTML = getValue;
				document.getElementById('msg_load').style.display='none';
			}
		}
	}
	oHTTP.send(null);
}

function submitVendorCode(vendorCode){
	window.opener.document.ven_form1.vendor_code.value=vendorCode;
	window.opener.document.ven_form1.vendor_code.focus();
	window.close();
}

function checkVendorCode(vendorCode){
	if(vendorCode!=""){
		var page="fetch_vendors.php?vendorCode="+vendorCode+"&mode=checkVendor";
		oHTTP.open("GET", page, true);
		oHTTP.onreadystatechange=function() {
			if (oHTTP.readyState==4) {
				var getValue=oHTTP.responseText;
				if (getValue=="NO") {
					alert("Please enter valid vendor code");
					document.ven_form1.vendor_code.value="";
					document.ven_form1.vendor_code.focus();
					return false;
				}
			}
		}
		oHTTP.send(null);
	}
}


function checkVenFormIndian(){
	if(document.ven_form_ind.dd_no.value==""){
		alert("Please enter DD No");
		document.ven_form_ind.dd_no.focus();
		return false;
	}

	if(document.ven_form_ind.dd_no.value==""){
		alert("Please enter DD No");
		document.ven_form_ind.dt.focus();
		return false;
	}

	if(document.ven_form_ind.amount.value==""){
		alert("Please enter amount");
		document.ven_form_ind.amount.focus();
		return false;
	}

	if(document.ven_form_ind.company_name.value==""){
		alert("Please enter company name");
		document.ven_form_ind.company_name.focus();
		return false;
	}

	if(document.ven_form_ind.address.value==""){
		alert("Please enter address");
		document.ven_form_ind.address.focus();
		return false;
	}

	if(document.ven_form_ind.contact_person.value==""){
		alert("Please enter contact person");
		document.ven_form_ind.contact_person.focus();
		return false;
	}

	if(document.ven_form_ind.phone_no.value==""){
		alert("Please enter phone no");
		document.ven_form_ind.phone_no.focus();
		return false;
	}
	
	if(document.ven_form_ind.email.value==""){
		alert("Please enter email id");
		document.ven_form_ind.email.focus();
		return false;
	}
	else{
		if(!echeck(document.ven_form_ind.email.value)){
			document.ven_form_ind.email.focus();
			return false;
		}
	}

	var chk=0;
	for(var i=0;i<3;i++){
		if(document.ven_form_ind.type_establishment[i].checked==true){
			chk++;
			break;
		}
	}

	if(chk==0){
		alert("Please choose type of establishment");
		return false;
	}

	if(document.ven_form_ind.proprietor.value==""){
		alert("Please enter proprietor name");
		document.ven_form_ind.proprietor.focus();
		return false;
	}

	var chk=0;
	var man=0;
	for(var i=0;i<4;i++){
		if(document.ven_form_ind.whether_manufacturer[i].checked==true){
			if(i==0){
				man=man+1;
			}
			chk++;
			break;
		}
	}

	if(chk==0){
		alert("Please choose manufacturer/Agent/ Authorised dealer/Trader");
		return false;
	}

	if(document.ven_form_ind.business_period.value==""){
		alert("Please enter business period");
		document.ven_form_ind.business_period.focus();
		return false;
	}

	if(man==1){
		if(document.ven_form_ind.furnish_details.value==""){
			alert("Please enter furnish details of items manufacture with manufacturing capacity");
			document.ven_form_ind.furnish_details.focus();
			return false;
		}
	}

	if(document.ven_form_ind.furnish_details_including_factory.value==""){
		alert("Please enter registration sought for item(s)");
		document.ven_form_ind.furnish_details_including_factory.focus();
		return false;
	}
	
	if(document.ven_form_ind.details_testing.value==""){
		alert("Please enter details of testing facilities");
		document.ven_form_ind.details_testing.focus();
		return false;
	}

	if(document.ven_form_ind.dg_reg_no.value==""){
		alert("Please enter DGS&D registration no");
		document.ven_form_ind.dg_reg_no.focus();
		return false;
	}

	if(document.ven_form_ind.dsg_items_registered.value==""){
		alert("Please enter items");
		document.ven_form_ind.dsg_items_registered.focus();
		return false;
	}

	if(document.ven_form_ind.nsic_reg_no.value==""){
		alert("Please enter NSIC registration no");
		document.ven_form_ind.nsic_reg_no.focus();
		return false;
	}

	if(document.ven_form_ind.nsic_items_registered.value==""){
		alert("Please enter items");
		document.ven_form_ind.nsic_items_registered.focus();
		return false;
	}

	if(document.ven_form_ind.nsic_validity.value==""){
		alert("Please enter validity");
		document.ven_form_ind.nsic_validity.focus();
		return false;
	}

	if(document.ven_form_ind.ssi_reg_no.value==""){
		alert("Please enter SSI registration no");
		document.ven_form_ind.ssi_reg_no.focus();
		return false;
	}

	if(document.ven_form_ind.ssi_items_registered.value==""){
		alert("Please enter items");
		document.ven_form_ind.ssi_items_registered.focus();
		return false;
	}

	if(document.ven_form_ind.fact_licence_no.value==""){
		alert("Please enter factory licence no");
		document.ven_form_ind.fact_licence_no.focus();
		return false;
	}

	if(document.ven_form_ind.reg_tax[0].checked==true){
		if(document.ven_form_ind.pan_no.value==""){
			alert("Please enter PAN no");
			document.ven_form_ind.pan_no.focus();
			return false;
		}

		if(document.ven_form_ind.vat_no.value==""){
			alert("Please enter VAT no");
			document.ven_form_ind.vat_no.focus();
			return false;
		}

		if(document.ven_form_ind.cst_reg_no.value==""){
			alert("Please enter CST registration no");
			document.ven_form_ind.cst_reg_no.focus();
			return false;
		}

		if(document.ven_form_ind.cst_reg_no.value==""){
			alert("Please enter excise registration no");
			document.ven_form_ind.excise_reg_no.focus();
			return false;
		}

		if(document.ven_form_ind.service_tax_no.value==""){
			alert("Please enter service tax no");
			document.ven_form_ind.service_tax_no.focus();
			return false;
		}

		if(document.ven_form_ind.service_tax_no.value==""){
			alert("Please enter service tax no");
			document.ven_form_ind.service_tax_no.focus();
			return false;
		}
	}

	if(document.ven_form_ind.anual_income.value==""){
		alert("Please enter anual turnover");
		document.ven_form_ind.anual_income.focus();
		return false;
	}

	if(document.ven_form_ind.city_name.value==""){
		alert("Please enter name of major clients where products are supplied during last two year");
		document.ven_form_ind.city_name.focus();
		return false;
	}
}

function checkVenFormOver(){
	if(document.ven_form_ind.dd_no.value==""){
		alert("Please enter DD No");
		document.ven_form_ind.dd_no.focus();
		return false;
	}

	if(document.ven_form_ind.dd_no.value==""){
		alert("Please enter DD No");
		document.ven_form_ind.dt.focus();
		return false;
	}

	if(document.ven_form_ind.amount.value==""){
		alert("Please enter amount");
		document.ven_form_ind.amount.focus();
		return false;
	}

	if(document.ven_form_ind.company_name.value==""){
		alert("Please enter company name");
		document.ven_form_ind.company_name.focus();
		return false;
	}

	if(document.ven_form_ind.address.value==""){
		alert("Please enter address");
		document.ven_form_ind.address.focus();
		return false;
	}

	if(document.ven_form_ind.contact_person.value==""){
		alert("Please enter contact person");
		document.ven_form_ind.contact_person.focus();
		return false;
	}

	if(document.ven_form_ind.phone_no.value==""){
		alert("Please enter phone no");
		document.ven_form_ind.phone_no.focus();
		return false;
	}
	
	if(document.ven_form_ind.email.value==""){
		alert("Please enter email id");
		document.ven_form_ind.email.focus();
		return false;
	}
	else{
		if(!echeck(document.ven_form_ind.email.value)){
			document.ven_form_ind.email.focus();
			return false;
		}
	}

	var chk=0;
	for(var i=0;i<2;i++){
		if(document.ven_form_ind.auth_indian_agent[i].checked==true){
			chk++;
			break;
		}
	}

	if(chk==0){
		alert("Please choose whether the vendor is an authorized Indian agent");
		return false;
	}

	if(document.ven_form_ind.business_period.value==""){
		alert("Please enter business period");
		document.ven_form_ind.business_period.focus();
		return false;
	}

	if(document.ven_form_ind.furnish_details.value==""){
		alert("Please enter furnish details");
		document.ven_form_ind.furnish_details.focus();
		return false;
	}

	if(document.ven_form_ind.reg_sought_items.value==""){
		alert("Please enter registration sought for item(s) with product details");
		document.ven_form_ind.reg_sought_items.focus();
		return false;
	}

	if(document.ven_form_ind.product_manufactured.value==""){
		alert("Please specify products manufactured conforms to International standard benchmark");
		document.ven_form_ind.product_manufactured.focus();
		return false;
	}

	if(document.ven_form_ind.city_name.value==""){
		alert("Please enter name of major clients where products are supplied during last two year");
		document.ven_form_ind.city_name.focus();
		return false;
	}
}

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){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 return true					
}