
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
	
}
function elem() {
        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--){elem(arguments[i]).style.display=""}
}

function Hide(){
		for(var i=arguments.length-1;i>= 0;i--){elem(arguments[i]).style.display="none"}
}


     var ProductPrice=[];
      
 function SetPrice(id,val){
  
        if(elem('your_price'+id)!=null){
             elem('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(elem('you_save'+id)!=null){
            elem('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(elem('reg_price'+id)!=null){
             elem('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( '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 hideDiv_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="none"; 
} 
} 
} 

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, site_domain) {
    
    var op_id = '';
    var ddl = 'select_menu' + pid;
    var _this;
    var inx = 0;
   
    if(elem(ddl)!=null){
 
        _this =elem(ddl);
        inx = _this.selectedIndex;
        op_id = _this.options[inx].value;
    }
     
    var sLink='/cart_add.asp?pid=' + pid + '&ptype='+ ptype +'&opid=' + op_id + '&atc='+ atc;
		
    
    document.location.href=site_domain+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='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='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 IncludePage( PageURL, ContainerID) {

	var callback = 
	{ 
	  success:IncludePageSuccessHandler, 
	  failure: IncludePageFailureHandler, 
	  argument: { IncludePageContainerID: ContainerID}
	}; 

	var request = YAHOO.util.Connect.asyncRequest('GET', PageURL, callback);
}

function IncludePageSuccessHandler(o){
	var DivID=o.argument.IncludePageContainerID;
	document.getElementById(DivID ).innerHTML=o.responseText;
}

function IncludePageFailureHandler(o){
	var DivID=o.argument.IncludePageContainerID;
	document.getElementById(DivID ).innerHTML=o.status + " " + o.statusText;
}

function T(FfunctionName, divId) {
	IncludePage('engine_getAjaxTFunction.asp?t=' + FfunctionName , divId);
}


function MakeDIVPopupFromContentElement(ElementId) {
	writetxt(document.getElementById(ElementId).innerHTML);
}

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 emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

var triman_email = vpisan_email.replace(/^\s+|\s+$/, '');

var error_email = document.getElementById(id);
var vseok = true;
var error = 'ok';

	//test email for illegal characters
	if(!emailFilter.test(triman_email)){
		vseok = false;
		return vseok;
	}
	else if(triman_email.match(illegalChars)){
		vseok = false;
		return vseok;
	}
	else if(vpisan_email.match(illegalChars)){
		vseok = false;
		return vseok;
	}
	
	if(vpisan_email == "" || vpisan_email == null){
		changestyle_div(id, 1);
		vseok = false;
		return vseok;
	}
	var email = vpisan_email.toLowerCase();

	if(!email.match("@")){
		changestyle_div(id, 1);
		vseok = false;
		return vseok;
	}

	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".") // dot, pika

	if (AtPos == -1 || StopPos == -1 || AtPos == 0 || StopPos-AtPos <= 2 || StopPos < AtPos || AtPos == email.length || StopPos == email.length || email.charAt(0) == '.') {
		changestyle_div(id, 1);
		vseok = false;
		return vseok;
	}
		
	var len = email.length;
		var pos = email.lastIndexOf ( '.', len - 1 ) + 1;
		if ((len - pos) > 4) {
			changestyle_div(id, 1);
			vseok = false;
			return vseok;
		}
		else if((len - pos) < 2) {
			changestyle_div(id, 1);
			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 != null && emailKoncnica != 3)
	{
		changestyle_div(id, 1);
		vseok = false;
		return vseok;
	}	

	if(nedovoljenEmail != null && emailKoncnica == 3)
	{
		//initbox();
		changestyle_div(id, 1);
		vseok = false;
		//vseok = 'error';
		return vseok;
	}
return vseok;
}

function fbs_click(u) {
if (u==''){
	u=location.href;
}
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}
