var xmlHttp;
var oArtikelID;
var oBarvaID;
var oVelikostID;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } 
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function GetZavezanecByEnter(myfield, e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
  {
  	myfield.form.submit();
   	return false;
  }
	else
   return true;
}
function GetSoferskaVoznja()
{
  var lokacijaOd = document.getElementById("cboxLokacijaOd").value;
  var lokacijaDo = document.getElementById("cboxLokacijaDo").value;
  var StOseb 		 = document.getElementById("cboxStOseb").value;
	
	if (lokacijaOd!="" && lokacijaDo !="" && StOseb !="")
	{
		  xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	} 
	   var url="ajax_getSoferDrive.asp";
	   url=url+"?lokacijaOd="+ lokacijaOd + "&lokacijaDo=" + lokacijaDo + "&stoseb=" + StOseb + "&mid=sl";
	   xmlHttp.onreadystatechange=DataLocationReady;
	   xmlHttp.open("GET",url,true);
	   xmlHttp.send(null);
	}
}
function AjaxChangePassword()
{
	var enaslov;
	enaslov = document.getElementById("enaslov").value;
	var geslo;
	geslo   = document.getElementById("geslo").value;
	var vzdevek;
	vzdevek = document.getElementById("vzdevek").value;

	if (geslo=="") 
	{
		alert("Geslo mora biti daljše od 4 znakov.");
		return;
	}
	else
	{
		if (geslo.length <=4)
		{
			alert("Geslo mora biti daljše od 4 znakov.");
			return;
		}
	}
  xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
 	{
 		alert ("Your browser does not support AJAX!");
 		return;
 	} 
  var url="ajax_resetgeslo.asp";
  url=url+"?enaslov="+ enaslov + "&geslo=" + geslo + "&vzdevek=" + vzdevek;
  xmlHttp.onreadystatechange=GesloChangedReady;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
function getPrice4Car()
{

  var inf = document.getElementById("avtoid").value;
	var startdate = document.getElementById("datumod").value;
	var enddate = document.getElementById("datumdo").value;
	
	var startura = document.getElementById('ETAHour').value;
	var endura = document.getElementById('ETTHour').value;
	var startminute = document.getElementById('ETAMinute').value;
	var endminute = document.getElementById('ETTMinute').value;
	var provizija = document.getElementById("provizija").value;

	//var startura = document.getElementById('ETAHour').options[document.getElementById('ETAHour').selectedIndex].value;
	//var endura = document.getElementById('ETTHour').options[document.getElementById('ETTHour').selectedIndex].value;
	//var startminute = document.getElementById('ETAMinute').options[document.getElementById('ETAMinute').selectedIndex].value;
	//var endminute = document.getElementById('ETTMinute').options[document.getElementById('ETTMinute').selectedIndex].value;

	  if (startdate !="" && enddate!="")
	  {
		  xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	} 
	   var url="ajax_getcarprice.asp";
	   url=url+"?avtoID="+ inf + "&startdate=" + startdate + "&enddate=" + enddate + "&uraod=" + startura + "&urado=" + endura + "&minuteod=" + startminute + "&minutedo=" + endminute + "&provizija=" + provizija;
	   xmlHttp.onreadystatechange=DataCarPriceReady;
	   xmlHttp.open("GET",url,true);
	   xmlHttp.send(null);
	 	}
}
function DateAdd(objDate, strInterval, intIncrement)
    {
        if(typeof(objDate) == "string")
        {
            objDate = new Date(objDate);
 
            if (isNaN(objDate))
            {
                throw("DateAdd: Date is not a valid date");
            }
        }
        else if(typeof(objDate) != "object" || objDate.constructor.toString().indexOf("Date()") == -1)
        {
            throw("DateAdd: First parameter must be a date object");
        }
 
        if( strInterval != "M" && strInterval != "D" && strInterval != "Y" && strInterval != "h" && strInterval != "m" && strInterval != "uM" && strInterval != "uD" && strInterval != "uY" && strInterval != "uh" && strInterval != "um" && strInterval != "us")
        {
            throw("DateAdd: Second parameter must be M, D, Y, h, m, uM, uD, uY, uh, um or us");
        }
 
        if(typeof(intIncrement) != "number")
        {
            throw("DateAdd: Third parameter must be a number");
        }
 
        switch(strInterval)
        {
            case "M":
            objDate.setMonth(parseInt(objDate.getMonth()) + parseInt(intIncrement));
            break;
 
            case "D":
            objDate.setDate(parseInt(objDate.getDate()) + parseInt(intIncrement));
            break;
 
            case "Y":
            objDate.setYear(parseInt(objDate.getYear()) + parseInt(intIncrement));
            break;
 
            case "h":
            objDate.setHours(parseInt(objDate.getHours()) + parseInt(intIncrement));
            break;
 
            case "m":
            objDate.setMinutes(parseInt(objDate.getMinutes()) + parseInt(intIncrement));
            break;
 
            case "s":
            objDate.setSeconds(parseInt(objDate.getSeconds()) + parseInt(intIncrement));
            break;
 
            case "uM":
            objDate.setUTCMonth(parseInt(objDate.getUTCMonth()) + parseInt(intIncrement));
            break;
 
            case "uD":
            objDate.setUTCDate(parseInt(objDate.getUTCDate()) + parseInt(intIncrement));
            break;
 
            case "uY":
            objDate.setUTCFullYear(parseInt(objDate.getUTCFullYear()) + parseInt(intIncrement));
            break;
 
            case "uh":
            objDate.setUTCHours(parseInt(objDate.getUTCHours()) + parseInt(intIncrement));
            break;
 
            case "um":
            objDate.setUTCMinutes(parseInt(objDate.getUTCMinutes()) + parseInt(intIncrement));
            break;
 
            case "us":
            objDate.setUTCSeconds(parseInt(objDate.getUTCSeconds()) + parseInt(intIncrement));
            break;
        }
        return objDate;
    }
function GetCarListForCountry()
{
  var inf = document.getElementById("cboxdrzava").value;
	var startdate = document.getElementById("datumod").value;
  if (inf.length!=0 && startdate !="")
  {
	  xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
   var url="ajax_getcarlist.asp";
   url=url+"?drzavaID="+ inf + "&startdate=" + startdate;
   xmlHttp.onreadystatechange=DataCarListReady;
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
 	}
}
function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode == 13 )
	 {
			GetTransferRate();
			return false;
	 }
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;
   return true;
}
function GetSoferRate()
{
  var inf 			= document.forms["reservation2"].elements["cboyavto"].value;
	var startdate = document.forms["reservation2"].elements["datumod"].value;
	var uraod 		= document.forms["reservation2"].elements["ETAHour"].value;
	var urado 		= document.forms["reservation2"].elements["ETTHour"].value;
	var minuteod 	= document.forms["reservation2"].elements["ETAMinute"].value;
	var minutedo 	=document.forms["reservation2"].elements["ETTMinute"].value;

  if (inf.length!=0 && startdate !="")
  {
	  xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
   var url="ajax_getsofer.asp";
   url=url+"?avtoid="+ inf + "&startdate=" + startdate + "&uraod=" + uraod + "&urado=" + urado + "&minuteod=" + minuteod + "&minutedo=" + minutedo;
   xmlHttp.onreadystatechange=DataSoferReady;
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
 	}
}
function GetTransferRate()
{
  var inf = document.getElementById("cboxavto").value;
	var StKm = document.getElementById("txtStKm").value;
  if (inf.length!=0 && StKm !="")
  {
	  xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
   var url="ajax_gettransfers.asp";
   url=url+"?avtoid="+ inf + "&txtStKm=" + StKm;
   xmlHttp.onreadystatechange=DataTransferReady;
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
 	}
}
function DataCarListReady()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("divcarlist").innerHTML=xmlHttp.responseText;
		if(document.forms["reservation"].elements["avtoid"] !=null)
		{
			getPrice4Car();
		}
	}
}
function DataSoferReady()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("sofer_izracun").innerHTML=xmlHttp.responseText;
	}

}
function DataTransferReady()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("transfer_izracun").innerHTML=xmlHttp.responseText;
	}
}
function DataLocationReady()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("IzracunID").innerHTML=xmlHttp.responseText;
	}
}
function DataCarPriceReady()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("divcarprice").innerHTML=xmlHttp.responseText;
	}
}
function addEvent( obj, type, fn )
{
if (obj.addEventListener)
obj.addEventListener( type, fn, false );
else if (obj.attachEvent)
{
obj['e'+type+fn] = fn;
obj[type+fn] = function() { obj['e'+type+fn]( window.event ); }
obj.attachEvent( 'on'+type, obj[type+fn] );
}
}
