function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
}
  return xmlhttp;
}

var http = getHTTPObject(); // We create the HTTP Object

function cnameBack(){
	var timeval=new Date().getTime();

	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	document.getElementById("gifval").value="1";
	showdefaultgif();
	http.open("GET","cnamesearchBack.php?timeval="+escape(timeval),true);
	http.onreadystatechange = handledefaultcompanyresults;
	http.send(null);
	}
	
}

function handledefaultcompanyresults()
{
	if (http.readyState == 4) {
			var results=http.responseText;
			document.getElementById("divforpaging").innerHTML = results;
			if(results!=""){
			document.getElementById("gifval").value="0";
			showdefaultgif();
			}
	}
}

// >>>>>>>>  For gif Image <<<<<<<<<<
function showdefaultgif(){
setlefttop();
var gifval=document.getElementById("gifval").value;
var res= document.getElementById('divforpaging').innerHTML;
if((gifval!="0") && (res!="")){
document.getElementById("loading_message_join").style.display = 'block';
}
else{
document.getElementById("loading_message_join").style.display = 'none';
}
}

// >>>>>>>>>>>  End Of Gif  <<<<<<<<<<<<<<


function companylink(ind){
compadv(ind);
}

function compadv(id){
var tvar = new Date().getTime();
var near = document.getElementById('ziploc').options[document.getElementById("ziploc").selectedIndex].text;
var compnm=document.getElementById("serv").value;
for(var i=0;i<compnm.length;i++){
compnm=compnm.replace("\'","");
compnm=compnm.replace("\"","");
}

var employ=document.getElementById("employ").options[document.getElementById("employ").selectedIndex].text;
var revenue=document.getElementById("revenue").options[document.getElementById("revenue").selectedIndex].text;
var join=document.getElementById("joincomp").value;
if(id!="cs"){
var ind1=id;
}
else{
var ind1=document.getElementById("ind1").options[document.getElementById("ind1").selectedIndex].value;
}

var country=document.getElementById("countrylink").options[document.getElementById("countrylink").selectedIndex].value;
var t=document.getElementById("slinker").type;
if(t=="text"){
var state=document.getElementById("slinker").value;
}
else{
var state=document.getElementById("slinker").options[document.getElementById("slinker").selectedIndex].value
}
var zip=document.getElementById("zip").value;
 if (http.readyState != 4 && http.readyState!=0){ 
		return;
		}
	else{
document.getElementById("gifval").value="1";
showgif();
http.open("GET","cadvsearch.php?cname="+escape(compnm)+"&emp="+escape(employ)+"&rev="+escape(revenue)+"&join="+escape(join)+"&ind1="+escape(ind1)+"&near="+escape(near)+"&country="+escape(country)+"&state="+escape(state)+"&zip="+escape(zip)+"&tvar="+escape(tvar),true);
http.onreadystatechange = handlecompanyresults;
http.send(null);
	}
}

// for button paging in cnamesearchBack.php
function innerscriptForSerachGoBack(ButtonNo,PageSize,RecordCount,kwrd){
    var  pagenoforsearch;
    if(ButtonNo == 1)
		pagenoforsearch = document.getElementById("pagefieldforhbsd1").value;
    else if(ButtonNo == 2)
		pagenoforsearch = document.getElementById("pagefieldforhbsd2").value;
		
		var pagenoforsearch = parseInt(pagenoforsearch);
		
	if(pagenoforsearch == "" || pagenoforsearch == null){
		alert("Enter page number in the text field");
	}
	else if(pagenoforsearch){
		    if(pagenoforsearch<=0){
				 alert("Negitive page numbers are not valid");
			} else if(pagenoforsearch > Math.ceil(RecordCount/PageSize)){
				 alert("Page number is out of search result range");
			} else{
			    pagingdivforpagingBack(pagenoforsearch,kwrd)
			}
    }else{
          alert("Enter valid page number");
	}
}

function pagingdivforpagingBack(PageNo,compnm)
{
	var time=new Date().getTime();
	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	document.getElementById("gifval").value="1";
	showdefaultgif();
	http.open("GET","cnamesearchBack.php?PageNo="+escape(PageNo)+"&kword="+escape(compnm)+"&time="+escape(time),true);
    http.onreadystatechange = handledefaultcompanyresults;
    http.send(null);
	}
}

// button paging code for cadvsearch.php
function pagingForcadvsearchGO(ButtonNo,PageSize,RecordCount,kwds,indus,emp,rev,near,joined,country,state,zip){
    var  pagenoforsearch;
    if(ButtonNo == 1)
		pagenoforsearch = document.getElementById("pagefieldforhbsd1").value;
    else if(ButtonNo == 2)
		pagenoforsearch = document.getElementById("pagefieldforhbsd2").value;
		
		var pagenoforsearch = parseInt(pagenoforsearch);
		
	if(pagenoforsearch == "" || pagenoforsearch == null){
		alert("Enter page number in the text field");
	}
	else if(pagenoforsearch){
		    if(pagenoforsearch<=0){
				 alert("Negitive page numbers are not valid");
			} else if(pagenoforsearch > Math.ceil(RecordCount/PageSize)){
				 alert("Page number is out of search result range");
			} else{
			    pagingForcadvsearch(pagenoforsearch,kwds,indus,emp,rev,near,joined,country,state,zip);
			}
    	}
	else{
          alert("Enter valid page number");
	}
}

function pagingForcadvsearch(PageNo,kwds,indus,emp,rev,near,joined,country,state,zip)
{
	var time=new Date().getTime();
	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	document.getElementById("gifval").value="1";
	showgif();
	http.open("GET","cadvsearch.php?PageNo="+escape(PageNo)+"&cname="+escape(kwds)+"&ind1="+escape(indus)+"&emp="+escape(emp)+"&rev="+escape(rev)+"&near="+escape(near)+"&join="+escape(joined)+"&country="+escape(country)+"&state="+escape(state)+"&zip="+escape(zip),true);
    http.onreadystatechange = handlecompanyresults;
    http.send(null);
	}
}

function handlecompanyresults()
{
	if (http.readyState == 4) {
			var results=http.responseText;
            document.getElementById("divforpaging").innerHTML = results;
			if(results!=""){
			document.getElementById("gifval").value="0";
			showgif();
			}
	}
}


// >>>>>>>>  For gif Image <<<<<<<<<<
function showgif(){
setlefttop();
var gifval=document.getElementById("gifval").value;
if(gifval!="0"){
document.getElementById("loading_message_join").style.display = 'block';
}
else{
document.getElementById("loading_message_join").style.display = 'none';
}
}

// >>>>>>>>>>>  End Of Gif  <<<<<<<<<<<<<<

//******* Change Representative......

function changerep(id,cid,memc,rep)
{
var repid=document.getElementById('chngrep').value;
var rep=document.getElementById('chngrep').options[document.getElementById("chngrep").selectedIndex].text;
if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
http.open("POST","changerepresent.php?represent="+escape(rep)+"&uid="+escape(id)+"&cid="+escape(cid)+"&repid="+escape(repid)+"&memc="+escape(memc),true);
http.onreadystatechange = handlrepresent;
http.send(null);
	}
}

function handlrepresent()
{
     if (http.readyState == 4) {
          var results=http.responseText;
		if(results=="sent"){
		document.getElementById('chngrep').disabled=true;
		}
		window.location.href="company-profile.php";
	 }
}

function scriptForSearchBack(ButtonNo,PageSize,RecordCount,sortby,kword,ind,cata,type,mem,edt,near,any,country,zip)
{
   var  pagenoforsearch;
	if(ButtonNo == 1)
		pagenoforsearch = document.getElementById("pagefieldforhbsd1").value;
    else if(ButtonNo == 2)
		pagenoforsearch = document.getElementById("pagefieldforhbsd2").value;
		
		var pagenoforsearch = parseInt(pagenoforsearch);
		
	if(pagenoforsearch == "" || pagenoforsearch == null){
		alert("Enter page number in the text field");
	}
	else if(pagenoforsearch){
		    if(pagenoforsearch<=0){
				 alert("Negitive page numbers are not valid");
			} else if(pagenoforsearch > Math.ceil(RecordCount/PageSize)){
				 alert("Page number is out of search result range");
			} else{
			    pagingforGdsearchBack(pagenoforsearch,sortby,kword,ind,cata,type,mem,edt,near,any,country,zip)
			}
    }else{
          alert("Enter valid page number");
	}
}

function scriptForSearchGoBack(ButtonNo,PageSize,RecordCount,sortby)
{
   var  pagenoforsearch;
	if(ButtonNo == 1)
		pagenoforsearch = document.getElementById("pagefieldforhbsd1").value;
    else if(ButtonNo == 2)
		pagenoforsearch = document.getElementById("pagefieldforhbsd2").value;
		
		var pagenoforsearch = parseInt(pagenoforsearch);
		
	if(pagenoforsearch == "" || pagenoforsearch == null){
		alert("Enter page number in the text field");
	}
	else if(pagenoforsearch){
		    if(pagenoforsearch<=0){
				 alert("Negitive page numbers are not valid");
			} else if(pagenoforsearch > Math.ceil(RecordCount/PageSize)){
				 alert("Page number is out of search result range");
			} else{
			    pagingforGdsearchBack1(pagenoforsearch,sortby)
			}
    }else{
          alert("Enter valid page number");
	}
}

function pagingforGdsearchBack(PageNo,sortby,kword,ind,cata,type,mem,edt,near,any,country,zip)
{
	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	http.open("GET","Gdsearch.php?sby="+escape(sortby)+"&PageNo="+escape(PageNo)+"&kw="+escape(kword)
+"&industry="+escape(ind)+"&category="+escape(cata)+"&postdate="+escape(edt)
+"&gpublic="+escape(type)+"&memsize="+escape(mem)+"&near="+escape(near)+"&anywhere="+escape(any)
+"&country="+escape(country)+"&zip="+escape(zip),true);
    http.onreadystatechange = handlepagingforGdsearch;
    http.send(null);
	}
}

function handlepagingforGdsearch()
{
        if (http.readyState == 4) {
                  var results=http.responseText;
                    document.getElementById("divforpaging").innerHTML = results;
      }
}

function pagingforGdsearchBack1(PageNo,sortby)
{
	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	http.open("GET","GdsearchBack.php?PageNo="+escape(PageNo)+"&sby="+escape(sortby),true);
    http.onreadystatechange = handlepagingforGdsearchBack;
    http.send(null);
	}
}

function handlepagingforGdsearchBack()
{
        if (http.readyState == 4) {
                  var results=http.responseText;
	              document.getElementById("divforpaging").innerHTML = results;
      }
}
function cnameSearchBack(kwrd){
	var timeval=new Date().getTime();

	if (http.readyState != 4 && http.readyState!=0){ 
	return;
	}
	else{
	document.getElementById("gifval").value="1";
	showdefaultgif();
	http.open("GET","cnamesearchBack.php?timeval="+escape(timeval)+"&kword="+escape(kwrd),true);
	http.onreadystatechange = handledefaultcompanyresults;
	http.send(null);
	}
	
}
function gotoprofile(id){
window.location.href=id;
}