	
//Global XMLHTTP Request object
var XmlHttp;
var ddlSource;
var ddlDestination;
var isIE 
isIE = false; 
var isSelect ;
isSelect  = false;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{

var objXMLHttp=null
if (window.XMLHttpRequest)
{
	objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	isIE = true;
}

XmlHttp =  objXMLHttp
	
}

//Gets called when combo box selection changes
function DropDownOnChange(objSource, objDestination,ddlType,GroupId,ISSelect,curCountry) 
{    
	ddlDestination = objDestination;	
	var ddlList = objSource;
	isSelect =  ISSelect; 

	//Getting the selected country from country combo box.
	var selectedValue = ddlList.options[ddlList.selectedIndex].value;
	var thisdate = new Date();

	// URL to get states for a given country
	var requestUrl =  "/adapteccom/GetData.aspx?GroupId="+ GroupId +"&ddlType="+ ddlType +"&SelectedId=" + encodeURIComponent(selectedValue) + "&Time=" + thisdate.getTime();
	
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}	
	return;
}


function SearchData(ddlCountry,ddlProduct, ddlPurchaseType) 
{    
    //Getting the selected country from country combo box.
	var CountryId = ddlCountry.options[ddlCountry.selectedIndex].value;
	
	var ProductId = ddlProduct.options[ddlProduct.selectedIndex].value;
	var PurchaseId = ddlPurchaseType.options[ddlPurchaseType.selectedIndex].value;
	
	var thisdate = new Date();

	// URL to get states for a given country	
	var requestUrl =  "/adapteccom/GetData.aspx?CountryId="+ encodeURIComponent (CountryId) +"&ddlType=search&ProductId=" + encodeURIComponent(ProductId) +  "&PurchaseId=" + encodeURIComponent(PurchaseId) + "&Time=" + thisdate.getTime();
	
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleSearchResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}	
	return;
}

//Called when response comes back from server
function HandleSearchResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{	
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{						
			var xmlData = XmlHttp.responseXML.documentElement;	
			var src="";
			
			var stateNodes = xmlData.getElementsByTagName('Table');	
			var strData ="", strAnchor = "";
			var strResult ="",strAddress = "", companyName ="", type="";
			//E:10289 JEY  
			var PurchaseTitle="", PurchaseSubTitle="";
			//E:11120 SARAVANA
			var CompanyContact = "";
			strData = "<div id=\"box1\"><div id=\"wlogo2\"><table  width=\"690\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-bottom:20px;\"><tr>";
            
            document.getElementById("divMsg").style.display="none";
//            var lbl = document.getElementById("<%=lblMessage.ClientID%>");
//            lbl.style.display ="none";
//	         
	        
			var itr=1;
			for (var count = 0; count < stateNodes.length; count++)
	        {	            	
	        	
	        	strAddress = "";
	        	companyName="";
	        	CompanyContact = ""
	        	src="";
	        	type="";
	        	for (var index =0 ; index < stateNodes[count].childNodes.length; index++)
	        	{
	        	switch (stateNodes[count].childNodes[index].nodeName)
	        	{
	       
	        	    case "Street_Address":	        	    
	        	        strAddress =  strAddress +  "<br>"+ stateNodes[count].childNodes[index].childNodes[0].nodeValue;	
	        	        break	        	        
	        	        
	        	    case "City":	        	    
	        	        strAddress =  strAddress +  "<br>"+ stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break	        	        
	        	        
	        	    case "State_Province":	        	    
	        	        strAddress =  strAddress +  "<br>"+ stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break
	        	    	        	    
	        	    case "Zip_code":	        	    
	        	        strAddress =  strAddress +  "<br>"+ stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break
	        	        
	        	    case "Company_URL":	        	    
	        	        strAnchor = stateNodes[count].childNodes[index].childNodes[0].nodeValue;  
	        	        if (strAnchor=="")
	        	            strAnchor="#"	        	        
	        	        break        	        
	        	        
	        	     case "Logo_Path":	        	    
	        	        src= stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break        	        
	        	           
	        	     case "Company_Name":	        	    
	        	        companyName = stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break
	        	       
	        	    case "PurchaseType":
	        	    
	        	       if(type=="")	        	    
	        	        type = stateNodes[count].childNodes[index].childNodes[0].nodeValue;  	        	
	        	        break
	        	            
                    case "CountryFullName":
                        countryname= stateNodes[count].childNodes[index].childNodes[0].nodeValue;
                        break  	        
                    case "ProductName":
                        oProductName= stateNodes[count].childNodes[index].childNodes[0].nodeValue;
                        break  	
                        
//                    E:10289 Begin JEY  
                    case "PurchaseTitle":
                        PurchaseTitle = stateNodes[count].childNodes[index].childNodes[0].nodeValue;
                        break  	        
                        
                    case "PurchaseSubTitle":
                        PurchaseSubTitle = stateNodes[count].childNodes[index].childNodes[0].nodeValue;
                        break  	
//                    E:10289 End JEY

//                  E:11120 Begin SARAVANA
                    case "CompanyContact":
                        CompanyContact = stateNodes[count].childNodes[index].childNodes[0].nodeValue;
                        break  	        
//                  E:11120 End SARAVANA  
	        	    default:
	        	     	//alert(stateNodes[count].childNodes[index].nodeName)
	        	}
	        	
	        		        	
	        	}
                if (src == "" || src== null )
                {
                strData= strData + "<td  style=\"width=177px;\"><center><b>"+ companyName+ "</b><br><a href=\"" + strAnchor+ "\"  target=_blank >"+ strAnchor+ "</a><br>"+CompanyContact+"</center> </td>";			        
                //strData= strData + "<td  style=\"width=127px;height=50px;text-align:center;overflow:hidden;\"><b>"+ companyName+ "</b><br><a href=\"" + strAnchor+ "\"  target=_blank >"+ strAnchor+ "</a><br>"+CompanyContact+"</td>";			        
                
                }
	        	else
	        	{
	        	strData= strData + "<td  style=\"width=177px;\"><center><a href=\"" + strAnchor+ "\" target=_blank ><img border=\"0\" src=\""+ "http://graphics.adaptec.com/us/wheretobuy/" + src + "\" alt=\""+ companyName+ "\" style=\"display:block; \" hspace=\"3\" vspace=\"5\"  width=\"127px\"></a><br><a href=\"" + strAnchor+ "\"  target=_blank >"+ addChartoString(strAnchor,24,' ')+ "</a><br>"+CompanyContact+" </center> </td>";			      	
	        	//overflow:hidden;
	        	//strData= strData + "<td  style=\"width=127px;height=50px;text-align:center;overflow:hidden;\"><a href=\"" + strAnchor+ "\" target=_blank ><img border=\"0\" src=\""+ "http://graphics.adaptec.com/us/wheretobuy/" + src + "\" alt=\""+ companyName+ "\" style=\"display:block; \" hspace=\"3\" vspace=\"5\"  width=\"127px\"></a><br><a href=\"" + strAnchor+ "\"  target=_blank >"+ strAnchor+ "</a><br>"+CompanyContact+"</td>";			      	
	        	
	        	}
	        	
//              if (strAddress!="" && 
//	        	if (countryname == "China")
//	        	{
//	        		strData= strData + "<td NOWRAP style=\"word-wrap:break-word;width=127px;;\" class=\"wbodygreytext\">" + strAddress  +  (strAnchor !="#"? "<br>" + strAnchor :"") + "</td>"
//	                if(itr == 2)
//	                {
//	                    strData += "</tr></tr>";
//	                    itr = 0;
//	                    document.getElementById("wlogomaincontainer").style.height=(stateNodes.length)/2*135;
//	                } 		
//	            } 		
//	            else
//	            {
//	                if(itr == 4)
//	                {
//	                    document.getElementById("wlogomaincontainer").style.height=(stateNodes.length)/4*130;
//	                    strData += "</tr></tr>";
//	                    itr = 0;
//	                } 		
//	            }
                 if(itr == 4)
	                {
	                    //document.getElementById("wlogomaincontainer").style.height=(stateNodes.length)/4*130;
	                    
	                    document.getElementById("wlogomaincontainer").style.height='auto';
	                    strData += "</tr></tr>";
	                    itr = 0;
	                } 	
                itr = itr + 1;
                
                 
                    if (countryname == 'Japan')
	        		{
	        		strResult =   oProductName + " " + type +  countryname;
	        		}
                    else if (countryname == 'China' || countryname == 'Hong Kong')
	        		{
	        		//strResult =  "在 [国家名] "+ "的 " + oProductName + " " + type;
	        		strResult =  "在 " + countryname + " 的 " + oProductName + " " + type;
	        		}
	        		 else if (countryname == 'Germany')
	        		{
	        		strResult =  type+ " von " + oProductName  +" in " + countryname ;
	        		}
	        		 else if (countryname == 'France')
	        		{
	        		strResult =  type+ " de " + oProductName  +" in " + countryname ;
	        		}
	        		else if (countryname == 'Russia')
	        		{
    //                    E:10289 Begin JEY  
	        		    if (PurchaseTitle == '_Default')
	        		    {
    	        		    strResult =  type+ " -- " + oProductName  +" в " + countryname ;
	        		    }
	        		    if (PurchaseTitle != '_Default')
	        		    {
    	        		    strResult = PurchaseTitle
	        		    }
    //                    E:10289 Begin JEY  
	        		}
	        		else
	        		 strResult =  type+ " of " + oProductName + " in " + countryname ;
	        	
	        }			
	            
	                        strData= strData + "</tr></table></div></div>"

		        var obj = document.getElementById ("divShortDesc");
		        if (obj!=null)		        
				    obj.style.display = "none";   
				    
			var divData = document.getElementById ("wlogomaincontainer");
			var olblErrMsg = document.getElementById("BaseTemplateContainer_lblErrMsg");
			if (divData !=null)
			{			
			    if (strData!="")			
			        {
                        divData.innerHTML  = strData; 
                        if (obj!=null)
                        {                                   
                            obj.style.display = "block";
                            obj.style.visibility = "visible";                
                        }  
                     }
                else
                     divData.innerHTML  = "<span class=\"wbodygreytext\" >" + olblErrMsg.innerHTML + "</span>";                                         
                                                                                              
            }
            if(stateNodes.length == 0)
            {
                 divData.innerHTML  = "<span class=\"wbodygreytext\" >" + olblErrMsg.innerHTML + "</span>";                   }
                             
            var olblShortMsg = document.getElementById("BaseTemplateContainer_lblShortDesc");
            var olblShortMsgjp = document.getElementById("BaseTemplateContainer_lblShortDescjp");
            var olblShortMsgjplast = document.getElementById("BaseTemplateContainer_lblShortDescjplast");
            
            var divShortDesc = document.getElementById ("divShortDesc");            
            if (divShortDesc !=null)
            {
           
            if (countryname == 'korea')
            {
             divShortDesc.innerHTML  = "<span class=\"wbodygreytext\" >" + olblShortMsg.innerHTML  + " </span>" 
            }
            else if (countryname == 'Japan')
            {
                divShortDesc.innerHTML  = "<span class=\"wbodygreytext\" >" + olblShortMsg.innerHTML +" "+  type + " " + olblShortMsgjp.innerHTML+ "<br>" + olblShortMsgjplast.innerHTML + "</span>"           
            }   
    //                    E:10289 Begin JEY  
            else if (countryname == 'Russia')
            {
                if (PurchaseSubTitle == '_Default')
                {
                    divShortDesc.innerHTML  = "<span class=\"wbodygreytext\" >" + olblShortMsg.innerHTML +" "+  type + " " + olblShortMsgjp.innerHTML+ "<br>" + olblShortMsgjplast.innerHTML + "</span>"           
                }
                if (PurchaseSubTitle != '_Default')
                {
                    divShortDesc.innerHTML = PurchaseSubTitle
                }
            }   
    //                    E:10289 Begin JEY  
            else
               divShortDesc.innerHTML  = "<span class=\"wbodygreytext\" >" + olblShortMsg.innerHTML +  type + " </span>"                         
               
			}
                        
            var lblResult = document.getElementById ("lblResult");            
            if (lblResult !=null)
            {
                lblResult.innerHTML  = strResult;             
            }                         
			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}


//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{	
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{				
		
			ClearAndSetItems(XmlHttp.responseXML.documentElement);					
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}


//Clears the contents and adds the items corresponding to the currently selected items
function ClearAndSetItems(rootNode)
{

    var stateList = ddlDestination; //document.getElementById("stateList");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = rootNode.getElementsByTagName('Table');		
	
	var textValue; 
	var optionItem;
	if (isSelect)	
		{
		//OptionText = "-- Select --";
		 var olblShortMsgJpSelect = document.getElementById("BaseTemplateContainer_lblSelect");
		 OptionText=olblShortMsgJpSelect.innerHTML;
		 }
	else
		{
		OptionText = "-- All --";
		}
		
   	OptionValue = 0 ;  	
   		
	optionItem = new Option( OptionText, OptionValue,  false, false);
	stateList.options[stateList.length] = optionItem;	
			

	var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var fullVersion=0;
    var majorVersion=0;
    // In Internet Explorer, the true version is after "MSIE" in userAgent
    
    if ((verOffset=nAgt.indexOf("MSIE"))!=-1) 
    {
    fullVersion  = parseFloat(nAgt.substring(verOffset+5));
    majorVersion = parseInt(''+fullVersion);
    }
    
    if (majorVersion == 7 || majorVersion == 8)
    {
    isIE=true;
    }
        


	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{	
		if (isIE)
		{
			OptionText = stateNodes[count].childNodes[1].text;
   			OptionValue = stateNodes[count].childNodes[0].text;  	
   		}
   		else
   		{
   			OptionText = stateNodes[count].childNodes[3].textContent;
   			OptionValue = stateNodes[count].childNodes[1].textContent; 
   		}
   		   		
		optionItem = new Option( OptionText, OptionValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

//Returns the node text value 
function GetInnerText (node)
{
	 //return (node.textContent || node.innerText || node.text) ;
	 if(isIE)
		{ return node.text; }
	 else
		{ return node.textContent ; }
}



function MultipleDropDown(ddlEquip,ddlMfr,ddlModel,ddlType,ddlType1,GroupId)
{

	ddlMfr[0].selected = true;
	ddlMfr.onchange();
	return DropDownOnChange(ddlEquip, ddlMfr,ddlType,GroupId) 
	
}

function ClearItems(ddlDestination)
{
  var stateList = ddlDestination; //document.getElementById("stateList");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}
	OptionText = "-- All --";
   	OptionValue = 0 ;  	
   		
	optionItem = new Option( OptionText, OptionValue,  false, false);
	stateList.options[stateList.length] = optionItem;
	ddlMfr[0].selected = true;
	ddlMfr.onchange();
}


function addChartoString(sString,iPos,sChar)
{
var _sNewString="";
var _sBuffer="";
var _sBufLen;
var _length = sString.length;
if (_length>iPos)
  {
  var _mod = sString.length / iPos
  var idx;
    _sNewString = sString.substring(0,iPos);
    for (idx=0;idx<=_mod;idx++)
    {
    _sNewString = _sNewString + sChar; 
    _sBufLen    = iPos+1;
    _sBuffer    = sString.substr((_sNewString.length-(idx+1)),(_sBufLen)) ;
    _sNewString = _sNewString + _sBuffer;
    }
  }
else
  {
  _sNewString = sString
  }
return _sNewString;
}




