﻿function Querystring(qs) { 
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') 
	
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 

function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 

var today = new Date(); 
var zero_date = new Date(0,0,0); 
today.setTime(today.getTime() - zero_date.getTime()); 
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 

function setVisitorID() { 
   if (Get_Cookie('VisitorID')) { 
       var VisitorID = Get_Cookie('VisitorID'); 
   }else{ 
       Set_Cookie('VisitorID',Math.random(),cookie_expire_date); 
   } 
} 

function setSessionID() { 
   if (!Get_Cookie('SessionID')) 
       Set_Cookie('SessionID',Math.random()); 
} 

var loaded_script = true; 


setInterval('blinkIt()',500)

function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}

function handleHttpResponse() {
if (http.readyState == 4) {
   
    for(var i = aspnetForm.Cities.options.length-1; i >= 0; i--)
    aspnetForm.Cities.options.remove(i)
    for(var i = aspnetForm.CitiesReturn.options.length-1; i >= 0; i--)
    aspnetForm.CitiesReturn.options.remove(i)
    
    results = http.responseText.split(";;;");
     for (x in results){    
      results2=results[x].split("**");
     
     
      if  (results2[1]!='')
      aspnetForm.Cities.options[aspnetForm.Cities.length] = new Option(results2[1], results2[2]);
      if (results2[3]=='-1')
      aspnetForm.Cities.options[aspnetForm.Cities.length-1].style.backgroundColor='yellow';
       
      aspnetForm.CitiesReturn.options[aspnetForm.CitiesReturn.length] = new Option(results2[1],results2[2]);
	if (results2[3]=='-1')
      aspnetForm.CitiesReturn.options[aspnetForm.CitiesReturn.length-1].style.backgroundColor='yellow';
      
      
     }
    document.getElementById('load2').innerHTML=''
    document.getElementById('load1').innerHTML=''
    } 
}

function ShowData(dataid){
  results3=dataid.split("**");
  document.getElementById('CitiesAddress').innerHTML=results3[0];
  document.getElementById('CitiesAddressReturn').innerHTML=results3[0];
  document.getElementById('CitiesReturn').selectedIndex=document.getElementById('Cities').selectedIndex
}

function ShowDataReturn(dataid){
  results4=dataid.split("**");
  document.getElementById('CitiesAddressReturn').innerHTML=results4[0];
}

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}

var http = getHTTPObject();

function GetLocations(valtext) {
document.getElementById('Search_Countries').selectedIndex=getOptionIndex('Search_Countries',valtext)
if (valtext.length>=1) {
document.getElementById('load2').innerHTML='<blink>טוען - נא להמתין</blink>'
document.getElementById('load1').innerHTML='<blink>טוען - נא להמתין</blink>'
  http.open("GET", "GetLocations.aspx?LocId=" + valtext, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
  }
}

function checkdata(){
var flag = true;
    if (aspnetForm.Cities.value==''){ 
        alert('יש לציין תחנת לקיחה')
        flag=false
    }
    
    if (aspnetForm.txtDateTake.value==''){ 
        alert('יש לציין תאריך לקיחה')
        flag=false
    }
    if (aspnetForm.CitiesReturn.value==''){ 
        alert('יש לציין תחנת החזרה')
        flag=false
    }
    
    if (aspnetForm.txtDate.value==''){ 
        alert('יש לציין תאריך החזרה')
        flag=false
    }
    if(flag){
        document.cookie='Countries=' + document.getElementById('Search_Countries').value + '; path=/';
        document.cookie='Cities=' + aspnetForm.Cities.value + '; path=/';
        document.cookie='txtDateTake=' + aspnetForm.txtDateTake.value + '; path=/';
        document.cookie='CitiesReturn=' + aspnetForm.CitiesReturn.value + '; path=/';
        document.cookie='txtDate=' + aspnetForm.txtDate.value + '; path=/';
        document.cookie='HourTake=' + aspnetForm.HourTake.value + '; path=/';  
        document.cookie='HourReturn=' + aspnetForm.HourReturn.value + '; path=/';        
        document.cookie='DriverAge=' + aspnetForm.DriverAge.value + '; path=/';   

        aspnetForm.action='CarList.aspx'
        aspnetForm.submit();
    }
}
function loaddata(){
if (Get_Cookie("Countries") != null) {
document.getElementById('Search_Countries').selectedIndex=getOptionIndex('Search_Countries',Get_Cookie("Countries"))
aspnetForm.HourTake.selectedIndex=getOptionIndex('HourTake',Get_Cookie("HourTake"))
aspnetForm.HourReturn.selectedIndex=getOptionIndex('HourReturn',Get_Cookie("HourReturn"))
aspnetForm.DriverAge.selectedIndex=getOptionIndex('DriverAge',Get_Cookie("DriverAge"))
aspnetForm.txtDateTake.value=Get_Cookie("txtDateTake")
aspnetForm.txtDate.value=Get_Cookie("txtDate")
getstation(Get_Cookie("Cities"),Get_Cookie("Countries"))
}
if (Get_Cookie("Countries") == '') {
GetLocations('US')
}
}
  function getOptionIndex(tbSelYear,yy) {
    for (var i = 0; i < document.getElementById(tbSelYear).options.length; i ++) {
      if (document.getElementById(tbSelYear).options[i].value == yy) 
        return i;
    }
    return -1;
  }

function getstation(stationid,countryid){
GetLocations(countryid)
aspnetForm.Cities.selectedIndex=getOptionIndex('Cities',Get_Cookie("Cities"))
aspnetForm.CitiesReturn.selectedIndex=getOptionIndex('CitiesReturn',Get_Cookie("CitiesReturn"))
}
