function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
	
}
function $() {
        var els = new Array();
        for (var i=0;i<arguments.length;i++){
	        var el = arguments[i];
	        if (typeof el=='string')
		        el=document.getElementById(el);
	        if (arguments.length==1)
		        return el;
	        els.push(el);
        }
        return els;
  }

function Show(){
		for(var i=arguments.length-1;i>= 0;i--){$(arguments[i]).style.display=""}
}

function Hide(){
		for(var i=arguments.length-1;i>= 0;i--){$(arguments[i]).style.display="none"}
}


     var ProductPrice=[];
      
 function SetPrice(id,val){
  
        if($('your_price'+id)!=null){
            $('your_price'+id).innerHTML = ProductPrice[val]["your_price"];
            if (ProductPrice[val]["your_price"]==''){Hide('your_price_txt'+id)}
            else {Show('your_price_txt'+id)}   
         };

        if($('you_save'+id)!=null){
            $('you_save'+id).innerHTML = ProductPrice[val]["you_save"];
        };
        
    
        if(ProductPrice[val]["you_save"] == ''){      
            Hide('you_save_txt'+id)
         }
            else 
         {
             Show('you_save_txt'+id)
         }    
       

        if($('reg_price'+id)!=null){
            $('reg_price'+id).innerHTML = ProductPrice[val]["reg_price"]
            if(ProductPrice[val]["reg_price"]==''){Hide('reg_price_txt'+id)}
            else {Show('reg_price_txt'+id)} 
            };

 }


// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function open_popup(theURL) { //v2.0
 MM_openBrWindow(theURL,'','scrollbars=yes,resizable=yes,width=520,height=500');
}

function PopupPic(sPicURL) {
     window.open( rootUrl + 'popup_image.asp?url=' + sPicURL, "",  "resizable=1,HEIGHT=200,WIDTH=200");
}

function hideDiv(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){//if they are 'see' divs 
if (document.getElementById) // DOM3 = IE5, NS6 
divs[i].style.visibility="hidden";// show/hide 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'hidden'; 
else // IE 4 
document.all.hideshow.divs[i].visibility = 'hidden'; 
} 
} 
} 

function showDiv(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){ 
if (document.getElementById) 
divs[i].style.visibility="visible"; 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'visible'; 
else // IE 4 
document.all.hideshow.divs[i].visibility = 'visible'; 
} 
} 
} 


function changeclass(id, newClass) {

identity=document.getElementById(id);
identity.className=newClass;

}

function changestyle(id, ifWrite) {

identity=document.getElementById(id);
if (ifWrite ==1 )
identity.style.border='2px solid red';
else
identity.style.border='1px solid #30547d';
}

function changestyle_div(id, ifWrite) {

identity=document.getElementById(id);
if (ifWrite ==1 )
identity.style.border='2px solid red';
else
identity.style.border='none';
}

function isValidEmail(str) {
   return ( str.indexOf("@") > 0);
 
}

function ClickEmail(textbox_name)
 {
if (isValidEmail(textbox_name)) 
{
return(textbox_name)
}
else
{
return(' ')
}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
		
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function open_popup_wide(theURL) { //v2.0
 MM_openBrWindow(theURL,'','scrollbars=yes,resizable=yes,width=700,height=500');
}


function open_popup_full_screen(theURL) { //v2.0
var width=screen.availWidth;
var height=screen.availHeight;
 MM_openBrWindow(theURL,'','scrollbars=yes,resizable=yes,width='+ width +',height='+ height+'');
}

function showDiv_display(pass) { 

var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){ 
if (document.getElementById) 
divs[i].style.display="block"; 
} 
} 
} 

function div_obroki_change(id_obrok){
	

	if (id_obrok == 'bank_credit'){
	showDiv('div_obrok');
	hideDiv('div_kart');}

	
	if (id_obrok == 'credit_card'){
	showDiv('div_kart');
	hideDiv('div_obrok');}
	
	
	if(id_obrok == 'cash'){
	hideDiv('div_kart');
	hideDiv('div_obrok');}
	


}



function add_to_cart_new(pid, ptype, atc) {
    
    var op_id = '';
    var ddl = 'select_menu' + pid;
    var _this;
    var inx = 0;
   
    if($(ddl)!=null){
 
        _this = $(ddl);
        inx = _this.selectedIndex;
        op_id = _this.options[inx].value;
    }
     
    var sLink = rootUrl + 'cart_add.asp?pid=' + pid + '&ptype='+ ptype +'&opid=' + op_id + '&atc='+ atc;
		
    
    document.location.href=sLink;

}

function open_page_kredit(kredit, spec) {
    
    var st_anuitet = '';
    var nbr_obrok = document.getElementById('nbr_obrok');
    var _this;
    var inx = 0;
    if(nbr_obrok!=null){
        inx = nbr_obrok.selectedIndex;
        st_anuitet = nbr_obrok.options[inx].value;
    }
     
    var sLink = rootUrl + 'popup_kredit.asp?kredit=' + kredit + '&st_anuitet='+ st_anuitet+'&spec='+spec;
		
    open_popup(sLink);

}

function open_page_kredit_kartica(kredit, spec) {
    
    var st_anuitet = '';
    var nbr_obrok = document.getElementById('nbr_obrok_kartica');
    var _this;
    var inx = 0;
    if(nbr_obrok!=null){
        inx = nbr_obrok.selectedIndex;
        st_anuitet = nbr_obrok.options[inx].value;
    }
     
    var sLink = rootUrl + 'popup_kredit.asp?kredit=' + kredit + '&st_anuitet='+ st_anuitet+'&spec='+spec;
		
    open_popup(sLink);

}




function open_popup_center(theURL) { //v2.0

var w = 640, h = 480;
if (parseInt(navigator.appVersion)>3) {
 w = screen.width;
 h = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 w = jScreenSize.width;
 h = jScreenSize.height;
}



var popW = 520, popH = 500;

var leftPos = (w-popW)/2, topPos = (h-popH)/2;


 MM_openBrWindow(theURL,'','scrollbars=yes,resizable=yes,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
}



function hideDiv2(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){//if they are 'see' divs 
if (document.getElementById) // DOM3 = IE5, NS6 
divs[i].style.display="none";// show/hide 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'none'; 
else // IE 4 
document.all.hideshow.divs[i].display = 'none'; 
} 
} 
} 


function showDiv2(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){ 
if (document.getElementById) 
divs[i].style.display="block"; 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'block'; 
else // IE 4 
document.all.hideshow.divs[i].display = 'block'; 
}
} 
}

function div_obroki_change(id_obrok){
 

 if (id_obrok == 'bank_credit'){
 showDiv('div_obrok');
 hideDiv('div_kart');}

 
 if (id_obrok == 'credit_card'){
 showDiv('div_kart');
 hideDiv('div_obrok');}
 
 
 if(id_obrok == 'cash'){
 hideDiv('div_kart');
 hideDiv('div_obrok');}
}

function div2_obroki_change(id_obrok){
 

 if (id_obrok == 'bank_credit'){
 showDiv2('div_obrok');
 hideDiv2('div_kart');}

 
 if (id_obrok == 'credit_card'){
 showDiv2('div_kart');
 hideDiv2('div_obrok');}
 
 
 if(id_obrok == 'cash'){
 hideDiv2('div_kart');
 hideDiv2('div_obrok');}
}

function SetPriceOnlyForDiscount(id,val){
	 
	if(ProductPrice[val]["you_save"] != '') {
	 
        if( document.getElementById('your_price'+id)!=null){
             document.getElementById('your_price'+id).innerHTML = ProductPrice[val]["your_price"];
            if (ProductPrice[val]["your_price"]==''){HideMinisite('your_price_txt'+id);
																											HideMinisite('your_price'+id)}
            else {ShowMinisite('your_price_txt'+id);
									ShowMinisite('your_price'+id)}   
         };

        if( document.getElementById('you_save'+id)!=null){
             document.getElementById('you_save'+id).innerHTML = ProductPrice[val]["you_save"];
						 
						 if(ProductPrice[val]["you_save"] == ''){
							  	if( document.getElementById('you_save_txt'+id)!=null){
            					HideMinisite('you_save_txt'+id);}
									HideMinisite('you_save'+id)
         				}
            	else 
         			{
								if( document.getElementById('you_save_txt'+id)!=null){
             					ShowMinisite('you_save_txt'+id);}
						 		ShowMinisite('you_save'+id)
         			}    
        };
        if( document.getElementById('reg_price'+id)!=null){
             document.getElementById('reg_price'+id).innerHTML = ProductPrice[val]["reg_price"]
					if(ProductPrice[val]["reg_price"]==''){HideMinisite('reg_price_txt'+id);
																								HideMinisite('reg_price'+id)}
            else {ShowMinisite('reg_price_txt'+id);
									ShowMinisite('reg_price'+id)} 
            };		
						
	}
	else
	{
		if( document.getElementById('your_price'+id)!=null){
					HideMinisite('you_save_txt'+id);
					HideMinisite('you_save'+id)}
		if( document.getElementById('reg_price'+id)!=null){
					HideMinisite('reg_price_txt'+id);
					HideMinisite('reg_price'+id)}
		if( document.getElementById('you_save'+id)!=null){
					HideMinisite('your_price_txt'+id);
					HideMinisite('your_price'+id)}
	}

}

function ShowMinisite(){
		for(var i=arguments.length-1;i>= 0;i--){document.getElementById(arguments[i]).style.display=""}
}

function HideMinisite(){
		for(var i=arguments.length-1;i>= 0;i--){document.getElementById(arguments[i]).style.display="none"}
}

function add_to_cart_redirect_back(pid, ptype, cid, tn, id1, id2) {
    
    var op_id = '';
    var ddl = 'select_menu' + pid;
    var _this;
    var inx = 0;
   
    if(document.getElementById(ddl)!=null){
 
        _this = document.getElementById(ddl);
        inx = _this.selectedIndex;
        op_id = _this.options[inx].value;
    }
     
    var sLink='cart_add_redirect_back.asp?pid=' + pid + '&ptype='+ ptype +'&opid=' + op_id + '&cid='+ cid+ '&tn='+ tn+ '&id1='+ id1+ '&id2='+ id2;
		
    document.location.href=sLink;

}

function checkEmail(id){
//function checkEmail(id, ok, error, klicaj){
if(document.getElementById) { var vpisan_email = document.getElementById(id).value; }
else if ((document.all) && (!document.getElementById)) { var vpisan_email = document.all.id.value; } // ie4
else if (document.layers) { var vpisan_email = document.layers[id].value; } // ns4
else { var vpisan_email = document.all[id].value; }

var error_email = document.getElementById(id);
var vseok = true;

	if(vpisan_email == "" || vpisan_email == null){
		vseok = false;
		return vseok;
	}
	var email = vpisan_email.toLowerCase();

	if(!email.match("@")){
		vseok = false;
		return vseok;
	}

	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".") // dot, pika

	if (AtPos == -1 || StopPos == -1 || AtPos == 0 || StopPos-AtPos <= 1 || StopPos < AtPos || AtPos == email.length || StopPos == email.length) {
		vseok = false;
		return vseok;
	}
		
	var len = email.length;
		var pos = email.lastIndexOf ( '.', len - 1 ) + 1;
		if ((len - pos) > 4) {
			vseok = false;
			return vseok;
		}
		else if((len - pos) < 2) {
			vseok = false;
			return vseok;
		}

var nedovoljenEmail = "@email.si";
//var nedovoljenEmail = /@email.si/;
//nedovoljenEmail = email.search(nedovoljenEmail);
nedovoljenEmail = email.match(nedovoljenEmail);
var emailKoncnica = email.length - StopPos; // 3 more bit
//if(nedovoljenEmail != -1){
	if (nedovoljenEmail != null && emailKoncnica != 3)
	{
		vseok = false;
		return vseok;
	}	

	if(nedovoljenEmail != null && emailKoncnica == 3)
	{
		initbox();
		vseok = false;
		return vseok;
	}
return vseok;
}

id = "newsletter_email";
function disableEnterKey(e)
{
     var key;     
     if(window.event){
          key = window.event.keyCode; //IE
     }
     else {
          key = e.which; //firefox
     }

	if(key == 13 && checkEmail(id) == false){
    	return false;
    }
    else {
		return true;
    }
//return (key != 13);
}