function ge (id) {
	return document.getElementById(id);
}

function change(field) {
	if(ge(field).style.display == '') {
		ge(field).style.display = 'none';
	} else {
		ge(field).style.display = '';
	}
}

function hide(field) {
	ge(field).style.display = 'none';
}

function show(field) {
	ge(field).style.display = '';
}

function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = new Array();
	//(strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;

	strClassName = strClassName.replace(/\-/g, "\\-");

	if(strTagName == "*" && document.all) {
		arrElements = document.all;
	} else {
		arrElements = oElm.getElementsByTagName(strTagName);
	}

	for(var i=0; i<arrElements.length; i++) {
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)) {
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function getWindowWidth() {
	var width = screen.width;

	if (window.innerWidth) {
		width = window.innerWidth;
	}

	if (document.body.clientWidth) {
		width = document.body.clientWidth;
	}

	return width;
}

function changeDisplayOnScreenSize(containerId, tagName, hideClass, maxResizeScreen) {
	l = getElementsByClassName(ge(containerId), tagName, hideClass);
	w = getWindowWidth();

	for(var i=0; i<l.length; i++) {
		if(w < maxResizeScreen) {
			l[i].style.display = 'none';
		} else {
			l[i].style.display = '';
		}
	}
}

function xmlHttpPost(strURL, queryString, action, params) {
	var xmlHttpReq = false;
	var self = this;
	var result = '';

	if(window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	self.xmlHttpReq.open('POST', strURL, true);

	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.send(queryString);
	self.xmlHttpReq.onreadystatechange = function() {
		if(self.xmlHttpReq.readyState == 4) {
			eval(action + '(\'' + escape(self.xmlHttpReq.responseText) + '\', params);');
		}
	}
}

function categoriesMenu (id, e) {
	var disp = ge('cMenu'+id).style.display;
	if(disp == 'none'){
		ge('cMenu'+id).style.display = 'block';
		e.innerHTML = e.innerHTML.replace('cmenu','cmenu_e');
	}else{
		ge('cMenu'+id).style.display = 'none';
		e.innerHTML = e.innerHTML.replace('cmenu_e','cmenu');
	}
	return false;
}

var productGalleryW;
var productGalleryURL;
function productGallery (pid, id) {
	if(id == null){ id = ''; }
	productGalleryW=window.open('/productgallery.php?p='+pid+'&i='+id,'productGallery','height=580,width=750,resizable=no,scrollbars=no,toolbar=no,status=no');
}


function display(element) {
        document.getElementById(element).style.display = 'block';
}

function hide(element) {
        document.getElementById(element).style.display = 'none';
}

function cartPaymentMethod (e) {
	hide('creditcards'); hide('creditcardsonline'); hide('creditform');
	
	if(e.value == 3){
		display('creditcards');
	}else if(e.value == 4){
		display('creditcardsonline');
	}else if(e.value == 5){
		display('creditform');
	}
	
	cartShowTotals();
}

function cartDeliveryMethod (e) {
	hide('euroshopcenters');
	if(e.value == 2){
		display('euroshopcenters');
	}
	cartShowTotals();
}

function cartShowTotals () {
	
	for (i=0;i<document.cart_buy.payment_method.length;i++) {
		if (document.cart_buy.payment_method[i].checked) { var payment_method = document.cart_buy.payment_method[i].value; }
	}
	for (i=0;i<document.cart_buy.delivery_method.length;i++) {
		if (document.cart_buy.delivery_method[i].checked) { var delivery_method = document.cart_buy.delivery_method[i].value; }
	}
	
	var total = baseprice;
	var processing_discount = 0;
	var processing_fee = 0;
	if(payment_method == 1){
		processing_discount = opd;
	}
	if(payment_method == 2){
		if(customers_type == 1){ processing_fee = opf; }else{ processing_fee = opf_entity; }
	}
	
	if(delivery_method == 1){
		shipping = shipping_fee;
	}else{
		shipping = 0;
	}
	
	total += processing_fee;
	total += shipping;
	total += processing_discount;
	
	ge('shipping_fee').innerHTML = cartFormatPrice(shipping);	
	ge('processing_fee').innerHTML = cartFormatPrice(processing_fee);
	ge('processing_discount').innerHTML = cartFormatPrice(processing_discount);
	ge('total_price').innerHTML = cartFormatPrice(total);
	
}

function cartFormatPrice (price) {
	return price.toFixed(2) + ' Ls';
}
