function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
	
}
	
	
	function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
}

	
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(ProductPrice[val]["your_price"]=='' && ProductPrice[val]["you_save"] == '' && ProductPrice[val]["reg_price"]!='')
			 {
				 
				  $('your_price'+id).innerHTML = ProductPrice[val]["reg_price"];
					Show('your_price_txt'+id);
					 Hide('you_save_txt'+id);
					 Hide('reg_price_txt'+id);
					
				}
			 else
			 {
  
        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)} 
            };
			 }

 }

      
 function SetPrice_old(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(rootUrl,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 changestyle2(id, ifWrite) {

identity=document.getElementById(id);
if (ifWrite ==1 )
identity.style.border='2px solid blue';
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_gift(theURL) { //v2.0
 MM_openBrWindow(theURL,'','scrollbars=yes,resizable=yes,width=927,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='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='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);
}
