/* sidebar open close */

//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com
//This code can be used for any purpose

function animate(elementID, newWidth,
      newHeight, time, callback)
{
  var el = document.getElementById(elementID);
  if(el == null)
    return;
	
  var cWidth = parseInt(el.style.width);
  var cHeight = parseInt(el.style.height);
 
  var totalFrames = 1;
  if(time> 0)
    totalFrames = time/40;
 
  var fWidth = newWidth - cWidth;
  if(fWidth != 0)
    fWidth /= totalFrames;
 
  var fHeight = newHeight - cHeight;
  if(fHeight != 0)
    fHeight /= totalFrames;
   
  doFrame(elementID, cWidth, newWidth, fWidth,
      cHeight, newHeight, fHeight, callback);
}

function doFrame(eID, cWidth, nWidth, fWidth,
      cHeight, nHeight, fHeight, callback)
{
   var el = document.getElementById(eID);
   if(el == null)
     return;
	 
  cWidth = moveSingleVal(cWidth, nWidth, fWidth);
  cHeight = moveSingleVal(cHeight, nHeight, fHeight);
  
  el.style.width = Math.round(cWidth) + 'px';
  el.style.height = Math.round(cHeight) + 'px';
 
  if(cHeight == nHeight
    && cWidth == nWidth)
  {
    if(callback != null)
      callback();
    return;
  }
   
  setTimeout( 'doFrame("'+eID+'",'+cWidth+','+nWidth+','+fWidth+','
    +cHeight+','+nHeight+','+fHeight+','+callback+')', 40);
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
 
  currentVal += frameAmt;
  if((frameAmt> 0 && currentVal>= finalVal)
    || (frameAmt <0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}
function slideSidebar()
{
   var element = document.getElementById('sidebar');
   if(element.up == null || element.down)
   {
      animate('sidebar', 50, 150, 250, null);
      element.up = true;
      element.down = false;
   }
   else
   {
      animate('sidebar', 100, 150, 250, null);
      element.down = true;
      element.up = false;
   }
}

/* sidebar open close */

/* popup za predogled tiskanja */

var strQueryString;
strQueryString = '';

function printpreview(language)
{
  var scrnwdth = 0;
  var scrnhght = 0;
  var wdth = 640;
  var hght = 450;
  var lft;
  var tp;
  if((window.screen) && (screen.width) && (screen.height)) {scrnwdth = screen.width; scrnhght = screen.height;}
  if(scrnwdth != 0) lft = (scrnwdth - wdth)/2;
  if(scrnhght != 0) tp = (scrnhght - hght)/2;
  var prn = null;
  prn = window.open(language + '/frameset-print.asp?' + location.protocol + '//' + location.host + location.pathname + '?blnPrint=true' + strQueryString, 'prnwnd', 'width=' + wdth + ',height=' + hght + ',left=' + lft + ',top=' + tp + ',screenX=' + lft + ',screenY=' + tp + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
  if (prn.blur) prn.focus();
}

function printframe()
{
  parent.frame_print_bottom.focus();
  parent.frame_print_bottom.print();
}

/* popup za predogled tiskanja */

/* preverjanje vnosnih polj */

function isEmpty(besedilo, msg)
{
	if (besedilo.value.length == 0)
	{
		alert(msg)
		besedilo.focus()
		return false
	} 
	return true
}

function isEmail(besedilo, msg)
{
	if (besedilo.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	{
		alert(msg);
		besedilo.focus();
		return false;
	}
}

function isSelected(radio, msg)
{
	if (radio.length > 0)
	{
		blnOK = false;
		for (var intIndex = 0; intIndex < radio.length; intIndex++)
		{
			if (radio[intIndex].checked)
			{
				blnOK = true;
			}
		}
		if (blnOK)
		{
			return true;
		}
		else
		{
			alert(msg);
			return false;
		}
	}
		else
	{
		 return true;
	}
	
}

/* prikazovanje in skrivanje divov */

function ShowHide(divId)
{
	var id = document.getElementById(divId);
	if (id.style.display == "none")
	{
		eval("id.style.display = 'block';");
	}
	else
	{
		eval("id.style.display = 'none';");
	}
}

/* formatiranje ?tevilk v znesek */

function FormatMoney(input, decimal)
{
  var strMoney, strMoneyPare, strFormattedMoney, strMoneyDiv, strMoneyMod, strSto,intMoneyLength,strInteger;
	var Money,i,j,k;
	//alert(input.value)
	Money = input;

	intMoneyLength = Money.length;
  	strInteger = new String("");
  for (intIndex=0; intIndex<intMoneyLength; intIndex++)
  {
   
   if (Money.substring(intIndex,intIndex+1) == ",") Money = Money.replace(/,/,".");

  }
	
	Money = parseFloat(Money);
//alert(Money);
	
//alert(Money)	;
	Mio=Money/1000000;
	Mio = parseInt(Mio);
	Money = Money -Mio*1000000;
	Tisoc = parseInt(Money /1000);
	Money = Money -Tisoc*1000;
	Sto = parseInt(Money);
	Money-=Sto;
	Money*=100;
	Money=Math.round(Money);
	//Sto =Sto.slice(1,5)

strFormattedMoney = Mio+'+'+Tisoc+'+'+Sto;


if(Mio>0)
{
	
	if(Tisoc<100) 
	{
		strFormattedMoney = Mio+'.0'+Tisoc;
		if(Tisoc<10)
		{
			 strFormattedMoney = Mio+'.00'+Tisoc;
			 if(Tisoc == 0) strFormattedMoney = Mio+'.000';
		}
	}
	else strFormattedMoney = Mio+'.'+Tisoc;
	//alert(Sto);
	
	if (Sto < 100)
	{
		strSto = '.0'+Sto;
		if (Sto < 10) strSto = '.00'+Sto;
		{
			if(Sto < 1) strSto = '.000';
		}
	}
	else strSto = '.'+Sto
	strFormattedMoney += strSto;
}
if(Mio<1)
{
	if(Tisoc == 0) strFormattedMoney ='';
	else strFormattedMoney = Tisoc;

	if (Sto < 100 &&Tisoc >0)
	{
		strSto = '.0'+Sto;
		if (Sto < 10) strSto = '.00'+Sto;
		{
			if(Sto < 1) strSto = '.000';
		}
	}
	else
	{ 
	if (Tisoc == 0) strSto = Sto;
	else strSto = '.'+Sto;
	
	}
	strFormattedMoney += strSto;

}

if (decimal!=false){
if (Money ==0) strFormattedMoney = strFormattedMoney+',00';
else if (Money <10) strFormattedMoney = strFormattedMoney+',0'+Money;
else 
  strFormattedMoney = strFormattedMoney+','+Money;

}
  return  strFormattedMoney;
  
}

function MoneyToFloat(input)
{
  var strMoney, intMoneyLength, intIndex, strInteger;
	if(input==0) return 0;
	if(input =='')return 0;
  strMoney = new String(input);
  
 // strMoney = strMoney.replace(/./,"a")
  
  //Money = parseFloat(Money);
//	alert(strMoney)
  
   if (input.length < 2)
  {
    return 0;
  }
  
  intIndex = 0;
 // while (strMoney.substring(intIndex, intIndex+1) == '0') {intIndex++};

  intMoneyLength = strMoney.length;
  strMoney = strMoney.substring(intIndex, intMoneyLength);

  strInteger = new String("");
  for (intIndex=0; intIndex<intMoneyLength; intIndex++)
  {
    if (strMoney.substring(intIndex,intIndex+1) == ".") {continue};
//    if (strMoney.substring(intIndex,intIndex+1) == ",") {break};
    strInteger += strMoney.substring(intIndex,intIndex+1);
  }


//alert(strInteger);
	strMoney = strInteger.replace(/,/,".")




 /* if (strInteger.length == 0) {return 0};
  if (isNaN(strInteger))
  {
    return 0;
  }
  else
  {
    return parseInt(strInteger);
  }*/	

	return parseFloat(strMoney);
}
//XML

function LoadXml(text)

{

	// code for IE

	if (window.ActiveXObject)

	  {

	  var doc=new ActiveXObject("Microsoft.XMLDOM");

	  doc.async="false";

	  doc.loadXML(text);

	  }

	// code for Mozilla, Firefox, Opera, etc.

	else

	  {

	  var parser=new DOMParser();

	  var doc=parser.parseFromString(text,"text/xml");

	  }	

	  

	return doc;

}


/* prikazovanje in skrivanje divov */



function setModel(p_model, p_kodaOpreme) {
	document.frmcarData.Model.value = p_model;
	document.frmcarData.KodaOpreme.value = p_kodaOpreme;
	document.frmcarData.submit();
}

function ShowHide(divId)
{
	var id = document.getElementById(divId);
	if (id.style.display == "none")
	{
		eval("id.style.display = 'block';");
	}
	else
	{
		eval("id.style.display = 'none';");
	}
}

function showPage(str) { 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = "/library/includes/sidebar.asp";
	url = url + "?Sidebar="+str;
	url = url + "&sid="+Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function showPager(str, q, o) { 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = "/library/includes/sidebar.asp";
	url = url + "?Sidebar="+str;
	url = url + "&q="+q;
	url = url + "&o="+o;
	url = url + "&sid="+Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState == 4)
	{
		document.getElementById("sidebar").innerHTML=xmlHttp.responseText;
	}
}

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;
}



   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('sidebar').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

function strReplace(str) {
	var txt = str.replace("c", "brk");
	alert(txt + "enaka: '"+("c"==str)+"'");
	return false;
	//return txt;
}
   
function get(obj) {
	var poststr = "inputSidebar=" + encodeURI( document.getElementById("inputSidebar").value ) +
	"&1=" + encodeURI( document.getElementById("Name").value ) +
	"&2=" + encodeURI( document.getElementById("LastName").value ) +
	"&3=" + encodeURI( document.getElementById("Address").value ) +
	"&4=" + encodeURI( document.getElementById("PostalCode").value ) +
	"&5=" + encodeURI( document.getElementById("City").value ) +
	"&6=" + encodeURI( document.getElementById("Phone").value ) +
	"&7=" + encodeURI( document.getElementById("EmailFrom").value ) +
	"&8=" + encodeURI( document.getElementById("Car").value ) +
	"&9=" + encodeURI( document.getElementById("ContactTo").value ) +
	"&10=" + encodeURI( document.getElementById("Note").value ) +
	"&11=" + encodeURI( document.getElementById("OrderEnews").value ) +
	"&12=" + encodeURI( document.getElementById("CategoryId").value ) +
	"&13=" + encodeURI( document.getElementById("LanguageId").value ) +
	"&Submit=" + encodeURI( document.getElementById("Submit").value );
	//strReplace(document.getElementById("Name").value);
	makePOSTRequest('/library/includes/sidebar.asp', poststr);
}

   
function getSearch(obj) {
  var poststr = "inputSidebar=" + encodeURI( document.getElementById("inputSidebar").value ) +
				"&q=" + encodeURI( document.getElementById("q").value ) +
				"&Submit=" + encodeURI( document.getElementById("Submit").value );
  makePOSTRequest('/library/includes/sidebar.asp', poststr);
}

function addSubmitClass() {
	var submits = document.getElementsByTagName('input');
	for (i=0;i<submits.length;i++){
		if((submits[i].getAttribute('type') == 'submit') || (submits[i].getAttribute('type') == 'button')) {
			//alert(submits[i].attributes.getNamedItem("type").value);
			submits[i].className = 'submit';
		}
	}
}
window.onload = addSubmitClass;