﻿ var showtime;
        var i = 0;
function ShowOverlayDiv(divId)
{   
    
    var dv = document.getElementById(divId);
    dv.style.display = 'block';
}


function HideOverlayDiv(divId)
{
   var dv = document.getElementById(divId);
    dv.style.display = 'none';
}


function ShowOverlay(MakeID, ZipCodeID, OverlayDivID)
{
  
    if(ValidateZip(ZipCodeID))
       { ShowOverlayDiv(OverlayDivID); 
         ShowDealers(MakeID,ZipCodeID);
         return true;
        }
    else
        {
         alert('Invalid Zipcode');
         return false;
        }
}

function ValidateZip(ZipCodeID)
{
    var isZipValid=false;

     var zip =  document.getElementById(ZipCodeID).value;
        	var http_request = false; 
	
	if(zip=='')
	    return false;
	
	var browser = document.getElementById('hdnBrowser').value;
	var urls = document.getElementById('hdnSiteUrl').value

	if (window.XMLHttpRequest) 
	{		
		http_request = new XMLHttpRequest(); 
		if (http_request.overrideMimeType) 
		{ 
			http_request.overrideMimeType('text/xml'); 
		
		} 
		
	} 
	else if (window.ActiveXObject) 
	{ 
	
	try 
	{ 
		http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) 
	{ 
	try 
	{ 
		http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch (e) 
	{} 
	} 
	} 
		if (!http_request) 
		{ 
		} 
		
	   	var url = urls+"Ajax/DealersList.aspx?request=validatezip&zipcode=" + zip;
	
		//http_request.onreadystatechange = function() { alertDealerContents(http_request); }; 
		
		
		
		if(browser == "IE")
		    http_request.open('POST', url, false);
		else
		    http_request.open('GET', url, false);
		    
		http_request.send(null); 
		
		if (http_request.readyState == 4) 
	    { 
		    if (http_request.status == 200) 
		    { 	
		        isZipValid = (http_request.responseText=="1");	
		    }
		}
		
	
		
		
		    
		return isZipValid;
}

function ShowDealers(MakeID, ZipCodeID)
{
    var make = document.getElementById(MakeID).value;
    var zip =  document.getElementById(ZipCodeID).value;
    
    var siteUrl = document.getElementById('hdnSiteUrl').value;
    
    //Set Make Image
    var MakeImg = document.getElementById('makeimage__');
    
    MakeImg.src = siteUrl + "MakeLogos/" + make + ".jpg";
    MakeImg.alt = make;
    
    CallAjax(document.getElementById('hdnBrowser').value,siteUrl,make,zip);
 
}



function CallAjax(browser,urls,make,zipcode) 
{ 

	var http_request = false; 
	
	if(window.location.href.indexOf("www")==-1)
	{	   
	    urls=urls.replace("www.","");		    	         	   	    
	}
	

	if (window.XMLHttpRequest) 
	{		
		http_request = new XMLHttpRequest(); 
		if (http_request.overrideMimeType) 
		{ 
			http_request.overrideMimeType('text/xml'); 
		
		} 
		
	} 
	else if (window.ActiveXObject) 
	{ 
	
	try 
	{ 
		http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) 
	{ 
	try 
	{ 
		http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch (e) 
	{} 
	} 
	} 
		if (!http_request) 
		{ 
		} 
		
	   	var url = urls+"Ajax/DealersList.aspx?dealermake="+make+"&dealerzip="+zipcode;
	
		//http_request.onreadystatechange = function() { alertDealerContents(http_request); }; 
		
		
		
		if(browser == "IE")
		    http_request.open('POST', url, false);
		else
		    http_request.open('GET', url, false);
		    
		http_request.send(null); 
		    
		alertDealerContents(http_request);
}
		  
function alertDealerContents(http_request) 
{  
	  
	if (http_request.readyState == 4) 
	{ 
		if (http_request.status == 200) 
		{ 							
				try
				{
				    var lst= http_request.responseText;	
				    document.getElementById('dealerlistHidden').value=lst;
				   
                    //showtime__ = setInterval("redir()", 3000);		
                    showPopUp('dialog');
                    //showIframe();
					//document.form1.submit(); 				    
				    				    
				}
				 catch(e){}
		}
	} 
}


        function showPopUp(el) 
        {
            //var cvr = document.getElementById("cover")
            var dlg = document.getElementById(el)
            //cvr.style.display = "block"
            dlg.style.display = "block"
            /*if (document.body.style.overflow = "hidden") {
                cvr.style.width = window.screen.width
                cvr.style.height = window.screen.height
            }*/

            slideshow();

        }
        function closePopUp(el) 
        {
            //var cvr = document.getElementById("cover")
            var dlg = document.getElementById(el)
            //cvr.style.display = "none"
            dlg.style.display = "none"
            document.body.style.overflowY = "scroll"
        }


        function slideshow() 
        {
            showtime = setInterval("change()", 1000);
        }

      function change() {
            var arr = document.getElementById('dealerlistHidden').value.split("|");

            if (arr[i] != null)
                document.getElementById("dealername").innerHTML = arr[i];
            i = i + 1;
            if (i > (arr.length - 1)) { i = 0 }

            // showIframe();
        }

            // showIframe();
