function pad_with_zeros(rounded_value, decimal_places) {

    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else 
        decimal_part_length = value_string.length - decimal_location - 1
   
	var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) 
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
   
    return value_string
}

function popIm(id){
	window.open("Showimage.php?id="+id,"popIm","top=10,left=20,resizable=no,width=200,height=200,status=no,location=no,menubar=no,scrollbars=yes")
}

function popSpecialIm(id,module){
	window.open("Showimage.php?id="+id+"&module="+module,"popIm","top=10,left=20, resizable=no,width=200,height=200,status=no,location=no,menubar=no,scrollbars=yes")
}
function sendPageLink(id) {
	window.open("saadalink.php?id="+id,"DescriptiveWindowName","width=466,height=391,scrollbars=yes,status=1");
}
function sendPageLink2(id) {
	window.open("printpage.php?"+id,"DescriptiveWindowName","width=800,height=600,scrollbars=yes,status=1");
}

function refreshSearch() {
	var prod = document.getElementsByName('products').item(0);
	var brand = document.getElementsByName('brands').item(0);
	var word = document.getElementsByName('word').item(0);
	var sURL = window.location.pathname+'?main=64&word='+word.value+'&products='+prod.value+'&brands='+brand.value;
	window.location.href = sURL;
	//window.location.reload(sURL);
	//alert(sURL);
	
}

function popUserRegForm(addValues){
	window.open("Register.php?"+addValues,"popUp","top=10,left=20,resizable=no,width=700,height=500,status=no,location=no,menubar=no,scrollbars=yes")
}

function checkInt(field, minInt, maxInt){
	var value=parseInt(field.value);
	field.value=value
	if((value<minInt) || (!value))
		field.value=minInt;
	else if(value>maxInt)
		field.value=maxInt;
}

function popCart(id){
		var popUp=window.open(	"modules/Checks/cart.php?orderID="+id,
							"popCart",
							"width=700,height=600,status=no,location=no,menubar=no,scrollbars=yes");
	}

function popGal(id){
	window.open('galerii.php?lang=est&id='+id,'','resizable=no,width=600,height=650,status=no,location=no,menubar=no,scrollbars=yes')
}

function init(){
	var head=document.getElementById("headerTD");
	var bank=document.getElementById("bankLogos");
	var bankS=document.getElementById("bankLogoSpace");
	
	if(bankS && bank && head){
		var top=getTop(bankS);
		var left=getLeft(head);
		var width=head.offsetWidth;
		
		var bWidth=bank.offsetWidth;
		var bHeight=bank.offsetHeight;

		bank.style.left=left+width-bWidth+24;
		bank.style.top=top;
		bankS.style.height=bHeight;
		bank.style.visibility="visible"
		
	}
}

function getTop(item){
	var myTarget = item;  
	var top=0;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;     
		myTarget = myTarget.offsetParent;   
	} 
	return top;
}

function getLeft(item){
	var myTarget = item;  
	var left=0;
	while(myTarget!= document.body) {
		left += myTarget.offsetLeft;     
		myTarget = myTarget.offsetParent;   
	} 
	return left;
}
