function createRequestObject()
{
	var tmpXmlHttpObject;
	//depending on what the browser supports, use the right way to create the XMLHttpRequest object
	if (window.XMLHttpRequest) { 
		// Mozilla, Safari would use this method ...
		tmpXmlHttpObject = new XMLHttpRequest();
	} else if (window.ActiveXObject) { 
		// IE would use this method ...
		tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return tmpXmlHttpObject;
}
 var http = createRequestObject();
 
function deleteUserSubindustry(table,id,uid,rowid) {
   	http.open("GET", "serverexe.php?table="+table+"&subcatid="+id+"&userid="+uid+"&rowid="+rowid);
	http.onreadystatechange = function() 
	{
		if(http.readyState == 4) {
			document.getElementsByTagName("BODY")[0].removeChild(document.getElementById("popup_userlist"));
			//document.getElementsByTagName("BODY")[0].removeChild(document.getElementById("popup_userlist"));
			//document.getElementsByTagName("BODY")[0].removeChild(document.getElementById("popup_userlist"));
			document.getElementById("cover").style.display='None';	
 			var row = document.getElementById(rowid);
		    row.style.display = "none"; 
			
  			document.getElementById("industrycount").value=document.getElementById("industrycount").value-1;
			if(document.getElementById("industrycount").value==0) {
				document.getElementById("addmore").style.display='Block';
				document.getElementById("Add").value='Cancel';
			}
			
		
		}   else if(http.readyState == 1) {
 		document.getElementById("cover").style.display='Block';  
 		var pageSize = getPageSize();
		var pageScroll = getPageScroll();
 		var popupTop = pageScroll[1] + (pageSize[3] / 2);
		var elDiv = document.createElement("DIV");
		var elDiv = document.createElement("DIV");
		elDiv.style.top = popupTop +'px';
		elDiv.id = "popup_userlist";
 		elDiv.innerHTML =  '<img src="images/loader.gif" align="absmiddle">&nbsp;Processing.....................';
   		document.getElementsByTagName("BODY")[0].appendChild(elDiv);
	  }
	};
	http.send(null);
}
 
////////////////////////////////////////////////////
function displayorgCategory(keyword) {
   txt='serverexe.php?orgcat='+keyword;
   http.open('get', txt);
   http.onreadystatechange = handledisplayorgCategory; 
   http.send(null);

 }

function handledisplayorgCategory()
{
		if(http.readyState == 4) 
		{
			response = http.responseText;
   			document.getElementById('orgcategory').options.length=0;
			options = response.split("|");
   				for( var i = 0; i < options.length; i++ )
  				if (options[i]!="") {
 					nameValue=options[i].split("~"); 
 					document.getElementById('orgcategory').options[i] = new Option(nameValue[0], nameValue[1]); 
 				} else {
						   document.getElementById('orgcategory').options[i] = new Option('Please Select', '0'); 
				}
				
		}
  }
 
function displayState( countryId, StateId, CityId )
{
        //alert(countryId);
	var http1 = createRequestObject();
  	http1.open("GET", "serverexe.php?getStateOption="+countryId);
	http1.onreadystatechange = function() 
	{ 
		if( http1.readyState == 4 ) 
		{
			response = http1.responseText;
			varState="state";
			document.getElementById(varState).options.length=0;
			varoptions = response.split("|");
			if(varoptions.length==2) {
			//if(countryId!=253) {
				nameValue=varoptions[0].split("~"); 
				document.getElementById(varState).options[0] = new Option(nameValue[0], nameValue[1]);
				document.getElementById("state").disabled=true;
			} else {
				document.getElementById("state").disabled=false;
				for( var i = 0; i < varoptions.length; i++ ) {
					if (varoptions[i]!="") {
						nameValue=varoptions[i].split("~"); 
						document.getElementById(varState).options[i] = new Option(nameValue[0], nameValue[1]);
						if(nameValue[1]==StateId) {
							document.getElementById(varState).options[i].selected=true;
						}
					}	
				} 
			}
  			if(document.getElementById('hSecurityCode').value=="1") {
 				SecurityCode('newcode');
			}
			 if(StateId>0) {
  				displayCity( StateId ,CityId );
			 }
 		}
		//if(document.getElementById('othercountry').value=="1") {
			if(countryId!=109) {
				displayCityOption();
			} else {
				document.getElementById("cmbCity").disabled=true;
				document.getElementById("cmbCity").style.display='none';
				document.getElementById("txtCity").disabled=false;
				document.getElementById("txtCity").style.display='block';
			}
		//}
		 
	};
	http1.send(null);
 }

function displayCity(StateId,CityId) {
    	http.open("GET", "serverexe.php?getCityOption="+StateId);
	http.onreadystatechange = function() 
	{
		if(http.readyState == 4) {
			 response = http.responseText;
			 //alert("cityResponse"+response);
   			 document.getElementById('cmbCity').options.length=0;
			 options = response.split("|");
			 
 			for( var i = 0; i < options.length; i++ ) {
 				if (options[i]!="") {
					nameValue=options[i].split("~"); 
					document.getElementById('cmbCity').options[i] = new Option(nameValue[0], nameValue[1]); 
					 if(nameValue[1]==CityId) {
							document.getElementById('cmbCity').options[i].selected=true;
					}
				} else {
					document.getElementById('cmbCity').options[i] = new Option('Please Select', '0'); 
				}
	  		} 
	    }
	};
	http.send(null);
}

function SecurityCode(keyword) {
	
	http.open("GET", "scripts/ajax/captcha.php?securitycode="+keyword);
	http.onreadystatechange = function() 
	{
 		if(http.readyState == 4) {
			response = http.responseText;
 			reTval=response.split("|");
			document.getElementById("security").innerHTML=reTval[0];
			document.getElementById("chkSecuritycode").value=reTval[1];
		}
	};
	http.send(null);
}
 

function chkEmail(email,uid) {
	if(uid=="") {
		http.open("GET", "serverexe.php?email="+email);
	} else {
		http.open("GET", "serverexe.php?emailEdit="+email+'&uid='+uid);
	} 
 	
 	http.onreadystatechange = function() 
	{ 
		if(http.readyState == 4) 
		{	
			response = http.responseText;
 			document.getElementById("emailerror").innerHTML=response;
		}
		 
	};
	http.send(null);
	
}
function chkUsername(username,uid) {
 	if(uid=="") {
		http.open("GET", "serverexe.php?username="+username);
	} else {
		http.open("GET", "serverexe.php?usernameEdit="+username+'&uid='+uid);
	}
 	
 	http.onreadystatechange = function() 
	{ 
		if(http.readyState == 4) 
		{	
			response = http.responseText;
 			document.getElementById("usernameerror").innerHTML=response;
		}
		 
	};
	http.send(null);
	
}


function chkAppTitle( title, appFid ,uid) {
   	http.open("GET", "serverexe.php?apptitle="+title+"&appFid="+appFid+"&uid="+uid);
	 http.onreadystatechange = function() 
	 {
		if(http.readyState == 4) 
		  {
 				response = http.responseText;
    			document.getElementById("apperror").innerHTML=response;	
  		  } 
 	 };
 	 http.send(null);
 }
 
 function chkAppTitleIndia( title, appFid ,uid) {
   	http.open("GET", "serverexe.php?apptitleindia="+title+"&appFid="+appFid+"&uid="+uid);
	 http.onreadystatechange = function() 
	 {
		if(http.readyState == 4) 
		  {
 				response = http.responseText;
    			document.getElementById("apperror").innerHTML=response;	
  		  } 
 	 };
 	 http.send(null);
 }

function makeDisable() {
 	document.getElementById("state").disabled=true;
}
 
function chkSelectedItem(obj) {
 	len = obj.options.length;
	i = 0;
	reTxt =0;
	for (i = 0; i < len; i++) {
		if(obj.options[i].selected) {
			if(obj.options[i].value!="") {
				reTxt = 1;
			} 
		}
	}	
	if(reTxt==1) {
		return true;
	} else {
		return false;
	}
}
function chkSelectedItemForRegistration(obj) {
	
 	len = obj.options.length;
	
	i = 0;
	reTxt =0;
	for (i = 0; i < len; i++) {
		obj.options[i].selected=true;
		if(obj.options[i].value!="") {
				reTxt = 1;
			} 
	}	
	if(reTxt==1) {
		return true;
	} else {
		return false;
	}
}

function numbersonly(str ,e)
{
 	var key;
	var keychar;
	var e=e;
   	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	 keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27))
	   return true;
	// numbers
	else if (((str).indexOf(keychar) > -1))
	   return true;
	else
	{
	   alert("Please enter numbers only");
	   return false;
	}
	 
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function GB_myShow(caption, url, /* optional */ height, width, callback_fn) {
       var options = {
        caption: caption,
        height: height || 400,
        width: width || 630,
        fullscreen: false,
        show_loading: true,
		reload_on_close:false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
	  // url="http://www.biz2credit.in/"+url;
    return win.show(url);
}

function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}

function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}

function Trim(str)
{
	return LTrim(RTrim(str));
}

 function showIndustry(val) {
 	if(val=="Add") {
		document.getElementById("addmore").style.display='Block';
 		document.getElementById("Add").value='Cancel';
	} else {
		document.getElementById("addmore").style.display='none';
 		document.getElementById("Add").value='Add';
	}
 }
 
function isInteger (s)
{
  var i;

  if (isEmpty(s))
  if (isInteger.arguments.length == 1) return 0;
  else return (isInteger.arguments[1] == true);

  for (i = 0; i < s.length; i++)
  {
	 var c = s.charAt(i);

	 if (!isDigit(c)) return false;
  }

  return true;
}
function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}

function displayCityOption() {
	
	if(document.getElementById("state").disabled==true) {
		document.getElementById("cmbCity").disabled=true;
		document.getElementById("cmbCity").style.display='none';
		document.getElementById("txtCity").disabled=false;
		document.getElementById("txtCity").style.display='Block';
		
	} else {
		document.getElementById("cmbCity").disabled=false;
  		document.getElementById("cmbCity").style.display='Block';
		document.getElementById("txtCity").disabled=true;
		document.getElementById("txtCity").style.display='none';
	}

}

function displayStateInAdmin( countryId, StateId, CityId ) {
	
	
	//alert(countryId);
	//alert(StateId);
	//alert(CityId);
	http.open("GET", "serverexe.php?getStateOption="+countryId);
	http.onreadystatechange = function() 
	{ 
		if( http.readyState == 4 ) 
		{
			response = http.responseText;
			//alert(response);
			varState="stateForUser";
			document.getElementById(varState).options.length=0;
			varoptions = response.split("|");
			if(varoptions.length==2) {
				nameValue=varoptions[0].split("~"); 
				document.getElementById(varState).options[0] = new Option(nameValue[0], nameValue[1]);
				document.getElementById("stateForUser").disabled=true;
			} else {
				document.getElementById("stateForUser").disabled=false;
				for( var i = 0; i < varoptions.length; i++ ) {
					if (varoptions[i]!="") {
						nameValue=varoptions[i].split("~"); 
						document.getElementById(varState).options[i] = new Option(nameValue[0], nameValue[1]);
						if(nameValue[1]==StateId) {
							document.getElementById(varState).options[i].selected=true;
						}
					}	
				} 
			}
  			
 
			 if( (StateId>0) && (CityId>0) ) {
				displayCity( StateId, CityId );
			 }
  		}
		
		//if(document.getElementById('othercountry').value=="1") {
			if(countryId!=109) {
				if(document.getElementById("stateForUser").disabled==true) {
					document.getElementById("cmbCity").disabled=true;
					document.getElementById("cmbCity").style.display='none';
					document.getElementById("txtCity").disabled=false;
					document.getElementById("txtCity").style.display='Block';
		
				} else {
					document.getElementById("cmbCity").disabled=false;
					document.getElementById("cmbCity").style.display='Block';
					document.getElementById("txtCity").disabled=true;
					document.getElementById("txtCity").style.display='none';
				}
			} else {
				document.getElementById("cmbCity").disabled=true;
				document.getElementById("cmbCity").style.display='none';
				document.getElementById("txtCity").disabled=false;
				document.getElementById("txtCity").style.display='block';
			}
		//}
		 
	};
	http.send(null);
 

}

function submitEmailForFinancial(emailID) {
	//alert("----------"+ emailID);
	http.open("GET", "serverexe.php?emailForFin="+emailID);
	 http.onreadystatechange = function() 
	 {
		if(http.readyState == 4) 
		  {
 				response = http.responseText;
				//alert(response);
				document.getElementById("emailID").value="";
    			document.getElementById("messege").innerHTML=response;	
  		  } 
 	 };
 	 http.send(null);
 }