﻿    var xmlHttp=false;
var url = "/App_Ajax/Ajax_CompanySearch.aspx";
var stuff="";
var var_results="";
document.getElementById("aspnetForm").onsubmit="return false";
// ==========================================================================================================================
function ClearFields()
{
document.getElementById("CompanyName").value="";
document.getElementById("results").style.display="none"
}
// ==========================================================================================================================
function CancelReturn()
{
if (event.keyCode == "13") 
    {
    return (false);
    }
return(event.keyCode);
}

function CheckKey() 
{
//return !(window.event && window.event.keyCode == 13);
if (event.keyCode == "13") 
    {
    return (false);
    }
if (event.keyCode == 32) 
    {
    return;
    }
document.getElementById('CompanyType').selectedIndex=0;
var var_value = document.getElementById("CompanyName").value;

if(!var_value =="" )
    {
    document.getElementById("results").style.display="block";
    getReqObjPost("DW=QUICK&VALUE="+var_value,function(xml,str){ DisplayQuickSearch(xml,str); });
    }  
}
// ==========================================================================================================================
function GetFromType()
{
document.getElementById("CompanyName").value ="";
var var_type = document.getElementById("CompanyType").value;
if (var_type== null){return;}
document.body.style.cursor = 'wait';
NewGrayOut('greyout', true,{'zindex':'50', 'bgcolor':'#111111', 'opacity':'30'});
getReqObjPost("DW=TYPE&VALUE="+var_type,function(xml,str){ DisplayQuickSearch(xml,str); });
}
//[+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+]
function getReqObjPost(params,func){
	var xmlhttp=false;
	if(window.XMLHttpRequest){
		try{
			xmlhttp = new XMLHttpRequest();
		}catch(e){
			xmlhttp = false;
		}
	}else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlhttp = false;
			}
		}
	}
	if(xmlhttp){
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){	
				if(xmlhttp.status==200){
					var str=xmlhttp.responseText;
					var xml=xmlhttp.responseXML;
					func(xml,str);
				}else{
					handleErrFullPage(xmlhttp.responseText)
				}
			}
		}
		var now=new Date();
		params=params + "&cdate"+now.getSeconds()+"=" + encodeURIComponent(now);
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(params);
	}
}
//[+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+]
function DisplayQuickSearch(xml,str)
{
var strHTML = str //this is the responseText
var response = eval("var d=" + strHTML);
var var_Results = "<table style='width:960px' border='1' cellpadding='1' cellspacing='0' bordercolor='#BBBBBB'><tr style='background-color: #CCCCCC; color:#000000; height:24px'><th id='xl' style='width:20px'>#</th><th style='width:520px'>COMPANY NAME</th><th style='width:220px'>COMPANY TYPE</th><th style='width:70px'>STATUS</th><th style='width:100px'>CITY</th><th style='width:30px'>STATE</th></tr>";
    if (d.length >0)
    {   
     for (var i=0; i < d.length; i++ )
        {
        if (i % 2 == 1)
            {
            if (d[i].STATUS=="FORMER NAME")
                {
                var_Results += "<tr title='click here to view details' id='ID"+i+"' style='cursor:pointer;background-color:#EFEFEF; height:18px; color:#CC6600:' onMouseOver='SetNewColor(this)' onMouseOut='SetOldColor(this)' onClick=SearchValue('"+ d[i].ORGID+"')><td style='background-color:#CCCCCC; color:#000000; width:20px'>"+ parseInt(i+1) +"</td><td style='text-align:left;width:520px'>"+  d[i].COMPANYNAME+"</td><td style='text-align:left;width:220px'>"+  d[i].LHNF_PTC+"</td>"
                }
                else
                {
                var_Results += "<tr title='click here to view details' id='ID"+i+"' style='cursor:pointer;background-color:#EFEFEF; height:18px' onMouseOver='SetNewColor(this)' onMouseOut='SetOldColor(this)' onClick=SearchValue('"+ d[i].ORGID+"')><td style='background-color:#CCCCCC; color:#000000; width:20px'>"+ parseInt(i+1) +"</td><td style='text-align:left;width:520px'>"+  d[i].COMPANYNAME+"</td><td style='text-align:left;width:220px'>"+  d[i].LHNF_PTC+"</td>"
                }
            if (d[i].STATUS=="ACTIVE"){var_Results += "<td style='text-align:left;color=#006633;width:90px'>"+  d[i].STATUS+"</td>"}
            if (d[i].STATUS=="INACTIVE"){var_Results += "<td style='text-align:left;color=#990A00;width:90px'>"+  d[i].STATUS+"</td>"}
            if (d[i].STATUS=="FORMER NAME"){var_Results += "<td style='text-align:left;color=#CC6600;width:90px'>"+  d[i].STATUS+"</td>"}
            var_Results += "<td style='text-align:left;width:100px'>"+  d[i].MAILCITY+"</td><td style='width:30px'>"+  d[i].MAILSTATE+"</td></tr>"
            }
        else
            {
           if (d[i].STATUS=="FORMER NAME")
            {
            var_Results += "<tr  title='click here to view details'  id='ID"+i+"' style='cursor:pointer;background-color:#CDDEFF; height:18px; color:#CC6600' onMouseOver='SetNewColor(this)' onMouseOut='SetOldColor(this)' onClick=SearchValue('"+ d[i].ORGID+"')><td style='background-color:#CCCCCC; color:#000000; width:20px'>"+ parseInt(i+1) +"</td><td style='text-align:left;width:520px'>"+  d[i].COMPANYNAME+"</td><td style='text-align:left;width:220px'>"+  d[i].LHNF_PTC+"</td>"
            }
            else
            {
            var_Results += "<tr  title='click here to view details'  id='ID"+i+"' style='cursor:pointer;background-color:#CDDEFF; height:18px' onMouseOver='SetNewColor(this)' onMouseOut='SetOldColor(this)' onClick=SearchValue('"+ d[i].ORGID+"')><td style='background-color:#CCCCCC; color:#000000; width:20px'>"+ parseInt(i+1) +"</td><td style='text-align:left;width:520px'>"+  d[i].COMPANYNAME+"</td><td style='text-align:left;width:220px'>"+  d[i].LHNF_PTC+"</td>"
            }
            if (d[i].STATUS=="ACTIVE"){var_Results += "<td style='text-align:left;color=#006633;width:90px'>"+  d[i].STATUS+"</td>"}
            if (d[i].STATUS=="INACTIVE"){var_Results += "<td style='text-align:left;color=#990A00;width:90px'>"+  d[i].STATUS+"</td>"}
            if (d[i].STATUS=="FORMER NAME"){var_Results += "<td style='text-align:left;color=#CC6600;width:90px'>"+  d[i].STATUS+"</td>"}
            var_Results += "<td style='text-align:left;width:100px'>"+  d[i].MAILCITY+"</td><td style='width:30px'>"+  d[i].MAILSTATE+"</td></tr>"
            
            }
        }
    }
    var_Results+= "</table><br><br>"
    document.getElementById("results").innerHTML = var_Results;
    document.body.style.cursor = 'normal';
    NewGrayOut('greyout',false); 
    if(!document.getElementById("CompanyName").value==""){document.getElementById("xl").innerHTML="#"}
    if(document.getElementById("CompanyName").value==""){document.getElementById("xl").innerHTML="<a href='NewCompanySearchDataXL.aspx?T="+document.getElementById("CompanyType").value+"'><img border='0' title='Click here to download this data in an Excel Spreadsheet format' src='/ExternalResources/Media/Images/pngs/xl.png' style='cursor:pointer'></a>"}
}
//[+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+]
function SearchValue(stuff)
{
window.open ("NewCompanySearchDetails.aspx?DI="+stuff,"mywindow","status=1");
}
//[+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+]
var _oldColor;
function SetNewColor(source)
{
_oldColor = source.style.backgroundColor;
source.style.backgroundColor = '#666666';
}

function SetOldColor(source)
{
source.style.backgroundColor = _oldColor;
}
//---------------------------------------------------------------------------//
function Trim(str)
{
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
 //[+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+][+]
 