function confirmAction()
{
var agree = confirm("Are you sure you want to delete this pages ?");
if (agree)
	return true ;
else
	return false ;
}

function clearTxt(id, txt){
  if (document.getElementById(id).value == txt){
	  document.getElementById(id).value = "";
	}	
}

function doChangeImage(imgName, imgLocation){
	document.getElementById(imgLocation).src = imgName;
}

function doShowHide(iDivId){
	if (document.getElementById(iDivId).style.display == "block"){
		document.getElementById(iDivId).style.display = "none";
	} else {
		document.getElementById(iDivId).style.display = "block";
	}
}

// per fushen e kerkimit nese eshte e zbrazet
function checkSearch(){
  if (document.search.searchNews.value == ""){
     alert("Please fill the search field !!!")
  return false
  }else{
  return true
  }	
}

function doClearTxt(){
  if (document.getElementById('address').value == "Ju lutemi këtu shënoni adresën tuaj të saktë."){
	  document.getElementById('address').value = "";
	}	
}

function doBreadCrump(itemName, headTitle, childTitles, childLinks, childLinkStyle){
	var childName = childTitles.split("~");
	var childLocation = childLinks.split("~");
	var childCurrentLinkStyle = childLinkStyle.split("~");
	
	//alert(childTitles);
	//alert(childLinks);	
	
	var childList = "<ul style='margin:0px; padding:0px; list-style-type:none;'>";
	for (g=0; g<childName.length; g++){
		if (childCurrentLinkStyle[g] == "href"){
			var linkTo = "href='"+childLocation[g]+"'"
		} else {
			var linkTo = "onClick=\"" + unescape(childLocation[g]) + "\"";
		}
		childList += "<li style='margin:0px; background-color:#fc150b; height:18px; padding-top:2px; padding-left:5px;'><a class='breadCrumpLink' style='cursor:pointer;' "+linkTo+">" + childName[g] + "</a></li>";
	}
	childList += "</ul>";
	//alert(childList);
  //document.getElementById('breadCrump').innerHTML = headTitle;
	if (itemName == "type"){
		sessvars.breadCrumpType = "<div id='headType'>" +
			"<div id='headTypeTitle' style='height:18px; background-color:#db241b; color:#ffffff; padding-top:2px; padding-left:5px; cursor:pointer;' onmouseover=\"document.getElementById('headTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headTypeContent').style.display='none'\">"+ headTitle +" >>></div>" +
			"<div id='headTypeContent' style='background-image:url(img/images/system/blank.gif); filter:alpha(opacity=98); -moz-opacity:0.98; z-index:1; display:none; position:absolute; width:195px;' onmouseover=\"document.getElementById('headTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headTypeContent').style.display='none'\">"+ childList +"</div>" +
		"</div>";
		//sessvars.breadCrumpSubType = null;
		//sessvars.breadCrumpSubSubType = null;
	} else if (itemName == "subType"){
		sessvars.breadCrumpSubType = "<div id='headSubType'>" +
			"<div id='headSubTypeTitle' style='height:18px; background-color:#db241b; color:#ffffff; padding-top:2px; padding-left:5px; cursor:pointer;' onmouseover=\"document.getElementById('headSubTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headSubTypeContent').style.display='none'\">"+ headTitle +" >>></div>" +
			"<div id='headSubTypeContent' style='background-image:url(img/images/system/blank.gif); filter:alpha(opacity=98); -moz-opacity:0.98; z-index:1; display:none; position:absolute; width:195px;' onmouseover=\"document.getElementById('headSubTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headSubTypeContent').style.display='none'\">"+ childList +"</div>" +
		"</div>";
		//sessvars.breadCrumpSubSubType = null;		
	} else if (itemName == "subSubType"){
		sessvars.breadCrumpSubSubType = "<div id='headSubSubType'>" +
			"<div id='headSubSubTypeTitle' style='height:18px; background-color:#db241b; color:#ffffff; padding-top:2px; padding-left:5px; cursor:pointer;' onmouseover=\"document.getElementById('headSubSubTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headSubSubTypeContent').style.display='none'\">"+ headTitle +" >>></div>" +
			"<div id='headSubSubTypeContent' style='background-image:url(img/images/system/blank.gif); filter:alpha(opacity=98); -moz-opacity:0.98; z-index:1; display:none; position:absolute; width:195px;' onmouseover=\"document.getElementById('headSubSubTypeContent').style.display='block'\" onmouseout=\"document.getElementById('headSubSubTypeContent').style.display='none'\">" + childList + "</div>" +
		"</div>";
	}
}

function doValidateAccountAdd(){
  if (document.getElementById('firstName').value == ""){
	  alert('Ju lutemi plotësoni fushën: Emri');
		return false;
	} else if (document.getElementById('lastName').value == ""){
	  alert('Ju lutemi plotësoni fushën: Mbiemri');
		return false;	
	} else if (!document.addClient.genderId[0].checked && !document.addClient.genderId[1].checked){
	  alert('Ju lutemi plotësoni fushën: Gjinia');
		return false;
	} else if (document.getElementById('email').value == ""){
	  alert('Ju lutemi plotësoni fushën: Email');
		return false;
	} else if (document.getElementById('email').value.indexOf('@') == -1){
	  alert('Fusha: Email, nuk ka format të saktë!');
		return false;
	} else if (document.getElementById('email').value.indexOf('.') == -1){
	  alert('Fusha: Email, nuk ka format të saktë!');
		return false;		
	} else if (document.getElementById('password').value == ""){
	  alert('Ju lutemi plotësoni fushën: Fjalëkalimi!');
		return false;
	} else if (document.getElementById('password').value.length < 6){
	  alert('Fjalëkalimi juaj duhet të ketë së paku 6 shkronja!');
		return false;
	} else if (document.getElementById('confirmPassword').value == ""){
	  alert('Ju lutemi plotësoni fushën: Konfirmo fjalëkalimin!');
		return false;
	} else if (document.getElementById('password').value != document.getElementById('confirmPassword').value){
	  alert('Fjalëkalimi dhe konfirmimi i fjalëkalimit nuk përputhen!');
		return false;		
	} else if (document.getElementById('address').value == ""){
	  alert('Ju lutemi plotësoni fushën: Adresa!');
		return false;		
	} else if (document.getElementById('address').value == "Ju lutemi këtu shënoni adresën tuaj të saktë."){
	  alert('Ju lutemi verifikoni fushën: Adresa!');
		return false;
	} else if (document.getElementById('phone').value.length < 9 && document.getElementById('mobile').value.length < 9){
	  alert('Ju lutemi plotësoni së paku njërën nga fushat: Tel. ose Mob. duke perfshire edhe prefixin 038, 044, ose 049');
		return false;
	} else {
		return inserClient();
	  return false;
	}
}

function inserClient(){
var agree=confirm("Ju lutemi të verifikoni edhe njëhere të dhënat tuaja. Nëse janë të sakta klikoni OK");
	if (agree){
			if (document.addClient.genderId[0].checked){
				gjinia = 2;
			} else if (document.addClient.genderId[1].checked) {
				gjinia = 1;
			}
			emri = escape(document.getElementById('firstName').value);
			mbiemri = escape(document.getElementById('lastName').value);
			dataLindjes = escape(document.addClient.dtBirthYear.value + "-" + document.addClient.dtBirthMonth.value + "-" + document.addClient.dtBirthDay.value);
			email = escape(document.getElementById('email').value);
			password = escape(hex_md5(document.getElementById('password').value));
			adresa = escape(document.getElementById('address').value);
			bonusId = escape(document.getElementById('bonusCardId').value);
			tel = escape(document.getElementById('phone').value);
			mob	 = escape(document.getElementById('mobile').value);
			params = "firstName=" + emri + "&lastName=" + mbiemri + "&genderId=" + gjinia + "&dtBirth=" + dataLindjes + "&email=" + email + "&password=" + password + "&address=" + adresa + "&bonusCardId=" + bonusId + "&phone=" + tel + "&mobile=" + mob;
			var getUrl = "inc/account_insert.inc.php?id=1&" + params;
			loadHTML(getUrl, 'loginInterface');
			return false ;
	} else {
		return false;
	}
}

function doValidatePassReset(){
  if (document.getElementById('email').value == ""){
	  alert('Ju lutemi plotësoni fushën: Emaili i juaj');
		return false;	
	} else if (document.getElementById('email').value.indexOf('@') == -1){
	  alert('Fusha: Emaili i juaj, nuk ka format të saktë!');
		return false;
	} else if (document.getElementById('email').value.indexOf('.') == -1){
	  alert('Fusha: Emaili i juaj, nuk ka format të saktë!');
		return false;				
	} else {
		accountId = escape(document.getElementById('email').value);
		urlToReset = "inc/account_pwdResetProccess.inc.php?email=" + accountId;
		loadHTML(urlToReset, 'loginInterface');
    return false;
	}
}

function doShowHideAccountAdd(id){ 
  if (document.getElementById(id).style.display == "none"){
    document.getElementById(id).style.display = "block";
    document.getElementById('labelId').style.display = "block";
  } else {
    document.getElementById(id).style.display = "none";
    document.getElementById('labelId').style.display = "none";	
    document.getElementById(id).value = "";		
  }
}


function checkUserLogin(){
  if (document.userLogin.username.value == ""){
     alert("Please fill your username !")
  return false
  }else if (document.userLogin.password.value == ""){
     alert("Please fill your password !")
  return false
  }else{
  return true
  }	
}
 
function check_form()
	{
		/*var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/ */
		if(document.newsletter.email.value == "")
		{
			alert("mungon e-maili !!");
			return false;
		}

		else if(document.newsletter.email.value.indexOf('@') == -1)
		{
			alert("adresa jokorekte !");
			return false;
		}	
		else if(document.newsletter.email.value.indexOf('.') == -1)
		{
			alert("adresa jokorekte !");
			return false;
		}
	}
	
		function check_form1()
		{
			/*var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/ */
			if(document.newsletter.username.value == "")
			{
				alert("mungon e-maili !!");
				return false;
			}
	
			else if(document.newsletter.username.value.indexOf('@') == -1)
			{
				alert("adresa jokorekte !");
				return false;
			}	
			else if(document.newsletter.username.value.indexOf('.') == -1)
			{
				alert("adresa jokorekte !");
				return false;
			}
		}	

//////////////// ADV ARDAll

   var request;
   var dest;
	 var finalDeliveryDt = "";
	 var isExpressDelivery = "";

	function gel(a){
		return document.getElementById(a);
	}

   function processStateChange(){
	   //alert(dest);
     if (request.readyState == 4){
			  //alert(dest);
        contentDiv = document.getElementById(dest);
        window.status
          if (request.status == 200){
             response = request.responseText;
             contentDiv.innerHTML = response;
						 var productLoaded = 1;
						 if (dest == "listBasket"){
						   document.getElementById('basketMain').style.display = "block"
						 }
						 // per me reload edhe njehere basketin
						 if (extraVars == "removeElement"){
						   loadHTML('inc/listBasket.php?id=98745687', 'listBasket');
						 }
						 // per me reload edhe njehere basketin
						 if (extraVars == "editElement"){
						   //alert('here');
							 loadHTML('inc/listBasket.php?id=98745687', 'listBasket');
						 }
						 if (extraVars == "editElementExtra"){ // edit element edhe frce ekspres delivery
							 loadHTML('inc/listBasket.php?id=98745687&expressId=1', 'listBasket', 'express');
						 }
						 if (extraVars == "postedOrder"){
						   doCloseList(); // reset the basket, DUHET EDHE SESSIONIN ME E PASTRU
							 document.getElementById('addOrder').style.display = "block";
							 loadHTML('inc/basket_listSimple.php?id=98745687', 'dynamicBasket');
						 }	
						 if (extraVars == "orderDetails"){
							 var hideDIV = "hide_" + dest;
							 var showDIV = "show_" + dest;
							 document.getElementById(hideDIV).style.display = "block";
							 document.getElementById(showDIV).style.display = "none";
						 }
						 contentDiv.style.display = "block";
						 	 //alert(' ********* ' + productLoaded);
						 // per me reload edhe njehere basketin
						 if (extraVars == "hide"){
						   document.getElementById(dest).style.display = "none";
						 }
						 if (extraVars == "express"){
							 doForceExpressDelivery();
						 }						 
          } else {
						 //alert(request.status);
             contentDiv.innerHTML = "Error: Status "+request.status;
          }
     }
   }
   
   function loadHTML(URL, destination, other){
		 extraVars = other;
     dest = destination;
       if (window.XMLHttpRequest){
          request = new XMLHttpRequest();
          request.onreadystatechange = processStateChange;
          request.open("GET", URL, true);
          request.send(null);
       } else if (window.ActiveXObject) {
          request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
               request.onreadystatechange = processStateChange;
               request.open("GET", URL, true);
               request.send();
            }
       }
   }	
	
	function doShowProduct(ids, img){
		tdId = "td_" + ids;
		imgId = "img_" + ids;
		moreId = "more_" + ids;
		gel(tdId).style.height = '260px';
		gel(imgId).src = 'img/images/content/products/' + img;
		gel(moreId).style.display = "block";
	}
	
	function doCloseProduct(idc){
		tdId = "td_" + idc;
		moreId = "more_" + idc;
		gel(tdId).style.height = '65px';
		gel(moreId).style.display = 'none';
	}
	
	function doForceExpressDelivery(){
		gel('expressDelivery').checked = 1;
	  gel('expressDelivery').disabled = 'true';
	}
	
	function addToChart(productId, price, productName){
	  //alert('id: ' + productId);
		divId = "product_" + productId;
		topOffset = document.getElementById(divId).offsetTop;
		leftOffset = document.getElementById(divId).offsetLeft;
		document.getElementById('addToBasket').innerHTML = "" +
		"<div>" +
		"<div style='color:ff0000; float:left;'><b>Shto artikullin në shportë</b></div>" +		
		"<div style='color:ff0000; width:15px; float:right; cursor:pointer;' onClick='doClose();'><b>X</b></div>" +
		"</div>" +
		"<div style='padding-top:5px;'>" + 
		"Sasia: <input type='text' id='qty_" + productId + "' class='frmInput' name='" + productId + "' value='' style='width:50px;'> &nbsp;" +
		"<input type='button' class='frmSubmit' name='doAddToBasket' onClick=\"doFillTheBasket("+productId+", "+price+", '"+productName+"')\" value='Shto' style='width:50px;'>" +
		"</div>" + 
    "<div></div>"	
		;
		document.getElementById('addToBasket').style.top = topOffset;
		document.getElementById('addToBasket').style.left = leftOffset;
		document.getElementById('addToBasket').style.display = "block";
	}	
	
	function doClose(){
		document.getElementById('addToBasket').style.display = "none";
		document.getElementById('addToBasket').innerHTML = "";
	}

  function doClearTrolleyDisplay(trlId){
		if (gel(trlId)){
		document.getElementById(trlId).innerHTML = "";
		document.getElementById(trlId).style.display = "none";			
		}
	}
	
	function doEditItem(keyToEditId, productId){
		var pPrice = "priceOf_" + productId;
		var keyId = "quantityMainInput_" + productId;
		var itemSubTotalName = "mainBasketItemSubTotal_" + productId;
		myPrice = document.getElementById(pPrice).value;
		newQyantity = document.getElementById(keyId).value;
		var totalActualBasket = parseFloat(document.getElementById('mainBasketTotalValue').innerHTML);
		//alert(totalActualBasket);
		var itemSubTotalValue = parseFloat(gel(itemSubTotalName).innerHTML);		
		document.getElementById(keyId).value = itemSubTotalValue/myPrice;
			
    if (isExpressDelivery == 1){ // nese expres delivery
			if (newQyantity > 0){
				var theUrl = "inc/editBasket.php?rowId=" + keyToEditId + "&newQty=" + newQyantity;
				loadHTML(theUrl, 'manageBasket', "editElementExtra");
			}else{
				document.getElementById(keyId).value = itemSubTotalValue/myPrice;
				alert("Sasia duhet te jete me e madhe se 0!");
			}		
		} else { // nese nuk o express delivery
					
			if (newQyantity > 0){
				//alert(itemSubTotalValue);
				var estimateTotalValue = totalActualBasket-itemSubTotalValue+(myPrice*newQyantity);
				if (estimateTotalValue < 29){
					alert("Ndryshimi i sasise se ketij artikulli zbret vleren totale te blerjes nen minimumit e lejuar!");
				} else {
					var theUrl = "inc/editBasket.php?rowId=" + keyToEditId + "&newQty=" + newQyantity;
					//alert(theUrl);
					loadHTML(theUrl, 'manageBasket', "editElement");				
				}
			}else{
				document.getElementById(keyId).value = itemSubTotalValue/myPrice;			
				alert("Sasia duhet te jete me e madhe se 0!");
			}
		}
		doGetTotalBasketValue();
	}	
	
	function doEditBasketItem(productId, price, action){
		//alert(action);
		if (action == "add"){
			  //alert("A " + action); 
				doFillTheBasket(productId, price, '', '1');
		} else if (action == "del") {
			  //alert("B " + action); 			
				doFillTheBasket(productId, price, '', '-1');			
		} else if (action == "fromMainBasket"){
			var newInputName = "quantityInput_" + productId;
			alert('current ' + gel(newInputName).value);
		}
	}	
	
	function doRemoveProduct(keyId, productId){
		subTotalIdName = "subTotal_" + productId;
		subTotalValue = parseFloat(gel(subTotalIdName).innerHTML);

		//alert(subTotalValue);
		//alert(parseFloat(gel(subTotalValue).innerHTML));
		//alert(keyId + " : " + productId);
		
		currentTotalValue = Math.round(parseFloat(parseFloat(gel('basketTotalValue').innerHTML))*100)/100;
		newTotalValue = Math.round((parseFloat(gel('basketTotalValue').innerHTML) - subTotalValue)*100)/100;
		//alert(newTotalValue);
		
		gel('basketTotalValue').innerHTML = newTotalValue + "&euro;"
		
		gel('basketBody').removeChild(gel("product_" + productId));
		
		doGetTotalBasketValue();
		
		removeURL = "inc/basket_removeItemSimple.php?element=" + keyId + "";
		loadHTML(removeURL, 'manageBasket');
	}	
	
	function doRemoveItemFromMainBasket(myKey, myTotal){
    //if (){
		//}
		var mainBasketActualTotalValue = parseFloat(gel('mainBasketTotalValue').innerHTML);
		var mainBasketActualItemValue = parseFloat(myTotal);
		var possibleNewValue = mainBasketActualTotalValue-mainBasketActualItemValue;
		if (possibleNewValue < 29){
			alert("Anulimi i këtij artikulli zbret vleren totale te blerjes nen minimumit e lejuar!");
		} else {
			var removeURL = "inc/removeFromBasket.php?element="+myKey;
	    loadHTML(removeURL, 'manageBasket', 'removeElement');			
		}
	}
	
	function doFillTheBasket(productId, price, productName, extraInfo){
		var inputId = "qty_" + productId;
		var trolleyId = "trolley_" + productId;
		var trolleyMainId = "trolleyMain_" + productId;
		// nese produkti osht shtu ne ka ardhe prej 1/2
		if (extraInfo){
			var qty = extraInfo;
			if (extraInfo == "-1"){
			  var deleteItem = 1;
				if(gel("quantityInput_" + productId).value < 2){
					return false;
				}
			}
		} else {
			var qty = document.getElementById(inputId).value;
		}		
		if(qty != ""){
			if (!isNaN(qty)){
				if (qty.indexOf(".") == -1 && qty.indexOf(",") == -1){
					//alert(productId);
					//alert(price);
					//alert(qty);			
					var theUrl = "inc/basket_addItemSimple.php?productId=" + productId + "&price=" + price + "&qty=" + qty + "&productName=" + encodeURIComponent(productName) + "";
					//alert(theUrl);
					loadHTML(theUrl, 'manageBasket', 'hide');
					if (document.getElementById(trolleyMainId)){
						diplayQty = parseInt(qty) + parseInt(document.getElementById(trolleyMainId).innerHTML);
					} else {
						diplayQty = qty;
					}
					key = parseInt(gel("basketBody").childNodes.length);
				  inputItemId = "quantityInput_" + productId;
					subTotal = Math.round(price*qty*100)/100;
					//alert(subTotal);
					basketListId = "product_" + productId;
          productPriceId = "productPrice_" + productId;
					existingItem = 0;
					// cift / tek
					/*
					if (key%2 == 0){
					  color2 = "#ffffff";	
					} else {
					  color2 = "#eaeaea";							
					}	
					*/
					t = gel("basketBody");					
					// e update basketin e vogel
					//loadHTML('inc/basket_listSimple.php?id=98745687', 'dynamicBasket');
					for (i=0; i < t.childNodes.length; i++){
						// nese item ekziston ne basket
							//alert(t.childNodes[i].id + " " + t.childNodes[i].innerHTML);
							if (t.childNodes[i].id == basketListId){
                existingItem = 1;
								break;
							}
					}
					if (existingItem == 1){
						// rikalkulo sasine dhe totalin
						subTotalId = "subTotal_" + productId;
						//alert(gel(inputItemId).value);
						numOfItemsInBasket = parseInt(gel(inputItemId).value)+parseInt(qty);
						gel(inputItemId).value = numOfItemsInBasket;
						priceOfItem = Math.round(parseFloat(gel(productPriceId).innerHTML)*100)/100;
						nrOfItems = parseInt(gel(inputItemId).value);
						gel(subTotalId).innerHTML = Math.round(priceOfItem*nrOfItems*100)/100;
					} else {
            newItem = "<div style='width:110px; float:left; padding-bottom:1px;'>"+productName+"</div><div id='"+productPriceId+"' style='width:40px; float:left; padding-top:2px;'>"+price+"</div><div style='width:40px; float:left;'><div style='float:left; padding-top:1px;'><input type='text' id='" + inputItemId + "' name='" + inputItemId + "' style='width:25px;' class='frmInput' value='"+qty+"' /></div><div align='left' style='width:14px; padding-top:1px; padding-left:1px; float:right;'><img onClick=\"doEditBasketItem('"+productId+"','"+price+"', 'add');\" width='9' src='img/system/plus2.gif' /><img onClick=\"doEditBasketItem('"+productId+"','"+price+"', 'del');\" width='9' src='img/system/minus2.gif' /></div></div><div style='width:60px; float:right;'><div id='subTotal_" + productId + "' style='width:45px; float:left; padding-top:2px;'>"+subTotal+"</div><div style='width:15px; float:right; padding-top:2px;'><input type='image' src='img/images/system/itemDeleteFromBasket.gif' value='Anulo' style='cursor:pointer;' onClick=\"doRemoveProduct('" + key + "', '"+ productId +"')\"></div></div>";						
						d = document.createElement("div");
						d.setAttribute("id","product_"+productId);
						d.style.width = "250px";
						//d.style.borderBottom = "1px solid #ff0033;";
						d.style.borderBottomColor = "#cccccc";
						d.style.borderWidth = "1px";
						d.style.borderBottomStyle = "solid";

            if (navigator.appName != "Microsoft Internet Explorer"){
						  //alert(navigator.appName);
						d.style.display = "table";
						}
						//d.style.paddingTop = "1px";						
						d.innerHTML = newItem;
						gel("basketBody").appendChild(d);
						numOfItemsInBasket = qty;
					}					
					
					if (document.getElementById(trolleyId)){
						document.getElementById(trolleyId).innerHTML = "" + 
						"<div style='display:table;'>" +
						"<div style='margin:0px; padding-top:2px;'>" + numOfItemsInBasket + " tanimë në shportë</div>" +	
						"</div>"
						;
						document.getElementById(trolleyId).style.display = "block";
					}
					
					// kalkulo vleren totale te shportes
					currentTotalValue = parseFloat(parseFloat(gel('basketTotalValue').innerHTML));
					newTotalValue = Math.round((parseFloat(gel('basketTotalValue').innerHTML)+subTotal)*100)/100;
					//alert(newTotalValue);
					gel('basketTotalValue').innerHTML = newTotalValue + " &euro;"
					//gel("basketBody").innerHTML = gel("basketBody").innerHTML + newItem;\
					//gel("basketBody").childNodes[key].innerHTML = newItem;
					
					//alert(gel("basketBody").childNodes.length);
					//alert(gel("basketBody").innerHTML);
					
					doGetTotalBasketValue();
					
					if (document.getElementById(inputId)){
						document.getElementById(inputId).value = "";						
					}
				} else {
				alert("Sasia duhet të jetë numër i plotë!");			
				}
			}else{
				alert("Sasia duhet të jetë numër!");
			}
		}else{
				alert("Ju lutemi plotësoni sasinë!");		
		}
	}
	
	function doGetTotalBasketValue(){
		document.getElementById('showActualBasketValue').innerHTML = document.getElementById('basketTotalValue').innerHTML;
	}
	
	function doCheckOut(total, dlvType, cuurentTime, cuurentDay){
		var basketTotal = parseFloat(total);		
		var timeNow = parseInt(cuurentTime);	
		if (dlvType == "normal"){
			if (basketTotal < 29){
				gel('warningMsg').style.display = "block";
				setTimeout("gel('warningMsg').style.display='none'", 15000);
			} else {
				//alert('OK ' + basketTotal);
				// mi dhone kohe pak new itemve
				setTimeout("doShowBasket()", 500);
			}
		} else if (dlvType == "express"){
			if ((timeNow > 9 && timeNow < 22) && parseInt(cuurentDay) != 7){
				if (basketTotal > 0){
					isExpressDelivery = 1;
					setTimeout("doShowBasket('expressTrue');", 500);		
				}				
			} else {
			  alert("MAXI eShop dërgesat realizohen prej orës 9:00 deri në ora 22:00. Ju falenderojmë për mirëkuptim.");	
			}
		}
	}
	
	function doShowBasket(extraStyle){
		//doClose();
		document.getElementById('basketMain').style.top = 0;
		document.getElementById('basketMain').style.left = 0;
		if (navigator.appName != "Microsoft Internet Explorer"){
			document.getElementById('basketMain').style.width = document.body.offsetWidth;
			document.getElementById('basketMain').style.height = document.body.offsetHeight;
		} else {
			document.getElementById('basketMain').style.width = document.body.clientWidth;
			document.getElementById('basketMain').style.height = document.body.clientHeight;
		}
		if (extraStyle == "expressTrue"){
			document.getElementById('basketMain').style.paddingTop = 10;
			loadHTML('inc/listBasket.php?id=98745687&expressId=1', 'listBasket', 'express');
		} else {
			document.getElementById('basketMain').style.paddingTop = 10;
			loadHTML('inc/listBasket.php?id=98745687', 'listBasket');
		}
	}	
	
	  function doSetDeliveryValue(hour,day){
			if (gel('expressDelivery').checked == 1){
				if ((parseInt(hour) < 9 || parseInt(hour) > 22) || day == 7){
					alert('Maxi eShop pranon dergesa Ekspres nga e Hena deri te Shtunen, prej ores 09:00 deri 22:00. Ju falenderojme per mirekuptim!');
					gel('expressDelivery').checked = 0;
	        gel('expressDelivery').disabled = 'true';
				} else {
					gel('deliveryCost').innerHTML = "10";
					gel('deliveryCalendar').style.display = "none";
				}
			} else {
				if (parseFloat(gel('mainBasketTotalValue').innerHTML) < 100){
				gel('deliveryCost').innerHTML = "2.5";
				} else {
				gel('deliveryCost').innerHTML = "0";					
				}
				gel('deliveryCalendar').style.display = "block";				
			}
		}
	  
	    function doChangePaymentMethod(paymentTypeIds){
			if (paymentTypeIds == 1){
				gel('paymentTypeCashId').checked = false;				
				gel('paymentTypePosId').checked = true;
            } else {
				gel('paymentTypePosId').checked = false;
				gel('paymentTypeCashId').checked = true;
			}			
		}
		
		function doPostOrder(){			
			if (gel('paymentTypePosId').checked == 1){
				paymentTypeIds = 1;
			} else {
				paymentTypeIds = 2;			
			}
			//alert(" test ");
					if (gel('expressDelivery').checked != 1 && finalDeliveryDt == ""){
						alert('Ju lutemi zgjidhni orarin e dërgeses!');
					} else {
						var orderComments = encodeURIComponent(gel('orderComments').value);
						if (gel('expressDelivery').checked == 1){
							var deliveryTypeId = 2;
							alert(deliveryTypeId);
							submitBasketURL = "inc/basket_submit.php?deliveryTypeId="+deliveryTypeId+"&paymentType="+paymentTypeIds+"&comments="+orderComments+"";
						} else {
							var deliveryTypeId = 1;
							submitBasketURL = "inc/basket_submit.php?deliveryTypeId="+deliveryTypeId+"&paymentType="+paymentTypeIds+"&dateOfDelivery="+finalDeliveryDt+"&timeOfDeliveryFrom="+finalDeliveryTmFrom+"&timeOfDeliveryTo="+finalDeliveryTmTo+"&comments="+orderComments+"";
						}			
						loadHTML(submitBasketURL, 'addOrder', 'postedOrder');
					}
		}
		
		// orari i dergesave
		function doCheckDeliveryDtTm(){
		  if (finalDeliveryDt != ""){
				alert('ka');
			} else {
				doSetDeliveryDtTm();
			}
		}
		
	  function doSetDeliveryDtTm(){
			var deliveryDate = this.attributes.getNamedItem("dlvDt").value;
			var deliveryTmFrom = this.attributes.getNamedItem("dlvTmFromH").value;
			var deliveryTmTo = this.attributes.getNamedItem("dlvTmToH").value;			
			var deliveryTmFromH = parseInt(deliveryTmFrom);
			var deliveryTmToH = parseInt(deliveryTmTo);	
			
		  if (finalDeliveryDt == ""){
				var newSlot;
				for (k=deliveryTmFromH; k<deliveryTmToH; k++){
					newSlot = document.getElementById("slot_" + deliveryDate + "_" + k);
					newSlot.style.backgroundColor = "#febd01";
					newSlot.style.borderRightColor = "#febd01";
					newSlot.style.color = "#febd01";
					if (k==deliveryTmFromH){
						newSlot.style.color = "#000000";
					} else if (k==deliveryTmToH-1){
						newSlot.style.color = "#000000";
					}
				}
				// GLOBAL dtDelivery
				finalDeliveryDt = deliveryDate;
				finalDeliveryTmFrom = deliveryTmFrom;
				finalDeliveryTmTo = deliveryTmTo;
			} else {
				//alert('ka');
				//alert(finalDeliveryDt + ": " + finalDeliveryTmFrom + " - " + finalDeliveryTmTo)
				
				for (m=parseInt(finalDeliveryTmFrom); m<parseInt(finalDeliveryTmTo); m++){
					var dtTmDivName = "slot_" + finalDeliveryDt + "_" + m;
					//alert(dtTmDivName + " - " + finalDeliveryTmTo);
					oldSlot = document.getElementById(dtTmDivName);
          oldSlot.style.backgroundColor = "#d40b41";
					oldSlot.style.borderRightColor = "#d40b41";
					oldSlot.style.color = "#d40b41";
					if (m==parseInt(finalDeliveryTmFrom)){
						oldSlot.style.color = "#ffffff";
					} else if (m==parseInt(finalDeliveryTmTo)-1){
						oldSlot.style.color = "#ffffff";
					} else {
						oldSlot.style.color = "#d40b41";
					}
				}
				var newSlot;
				for (k=deliveryTmFromH; k<deliveryTmToH; k++){
					newSlot = document.getElementById("slot_" + deliveryDate + "_" + k);
					newSlot.style.backgroundColor = "#febd01";
					newSlot.style.borderRightColor = "#febd01";
					newSlot.style.color = "#febd01";
					if (k==deliveryTmFromH){
						newSlot.style.color = "#000000";
					} else if (k==deliveryTmToH-1){
						newSlot.style.color = "#000000";
					}
				}
				// GLOBAL dtDelivery
				finalDeliveryDt = deliveryDate;
				finalDeliveryTmFrom = deliveryTmFrom
				finalDeliveryTmTo = deliveryTmTo;
			}
		}
		
	  function doHighlightSlots(dtSchedule, tmFromH, tmToH, tmFromAll, tmToAll){
		  //alert(tmFromAll + " " + tmToAll);
			var dtTmFrom = parseInt(tmFromH);
			var dtTmTo = parseInt(tmToH);
		  //alert(dtSchedule + ": " + dtTmFrom + " " + dtTmTo);
			var intervalId = "";
			/*
			if (dtTmFrom == "18"){
				dtTmFrom = 17;
			}
			*/
			for (i=dtTmFrom; i<dtTmTo; i++){
			  var slotName = "slot_" + dtSchedule + "_" + i;
				var slotObject = document.getElementById(slotName);
			  //alert(slotName);
				slotObject.style.backgroundColor = "#d40b41";
				slotObject.style.borderRightColor = "#d40b41";
				slotObject.style.color = "#d40b41";
				slotObject.style.cursor = "pointer";
				//document.getElementById(slotName).setAttribute('onclick', 'alert("blabla")');
				slotObject.onclick = doSetDeliveryDtTm;
				
				slotObject.setAttribute("dlvDt", dtSchedule);
				slotObject.setAttribute("dlvTmFrom", tmFromAll);
				slotObject.setAttribute("dlvTmTo", tmToAll);
				slotObject.setAttribute("dlvTmFromH", tmFromH);
				slotObject.setAttribute("dlvTmToH", tmToH);				
				
				slotObject.onclick = doSetDeliveryDtTm;
				
				
				if (i == dtTmFrom){
				document.getElementById(slotName).innerHTML = tmFromAll.substring(0,5);
				document.getElementById(slotName).style.color = "#ffffff";
				}
				if (i == dtTmTo-1){
				//document.getElementById(slotName).innerHTML = tmToAll;
				//alert(document.getElementById(slotName).innerHTML);
				var setValue = document.getElementById(slotName).innerHTML;
				var setValueHour = setValue.substring(0,3);
				document.getElementById(slotName).innerHTML = setValueHour + "59";
				document.getElementById(slotName).style.color = "#ffffff";
				}		
			}
			var slotName = "slot_" + dtSchedule
		}	
	
	
	function doFillTheBasketORIGINAL(productId, price, productName){
		var inputId = "qty_" + productId;
	  var qty = document.getElementById(inputId).value;
		if(qty != ""){
			if (!isNaN(qty)){
				if (qty.indexOf(".") == -1 && qty.indexOf(",") == -1){
					//alert(productId);
					//alert(price);
					//alert(qty);			
					var theUrl = "inc/addToBasket.php?productId=" + productId + "&price=" + price + "&qty=" + qty + "&productName=" + productName + "";
					//alert(theUrl);
					loadHTML(theUrl, 'manageBasket');
					document.getElementById('addToBasket').innerHTML = "" + 
					"<div style='display:table;'>" +
					"<div style='margin:0px; padding-top:2px;'>Artikulli #"+productId+" u shtua me sukses.</div>" +		
					"<div style='margin:0px; color:ff0000; cursor:pointer;' onClick='doClose();'><b>Vazhdo blerjen</b></div>" +							
					"<div style='margin:0px; color:666666; cursor:pointer;' onClick=\"doShowBasket();\"><b>Shko në shportë</b></div>" +
					"</div>"
					;
				} else {
				alert("Sasia duhet të jetë numër i plotë!");			
				}
			}else{
				alert("Sasia duhet të jetë numër!");
			}
		}else{
				alert("Ju lutemi plotësoni sasinë!");		
		}
	}	
	
	function doCloseList(){
		if (parseFloat(gel('basketTotalValue').innerHTML) == parseFloat(gel('mainBasketTotalValue').innerHTML)){ // nese ka pase ndryshim te vleres totale
			document.getElementById('listBasket').innerHTML = "";
			document.getElementById('basketMain').style.display = "none";		
		}else{
			document.getElementById('listBasket').innerHTML = "";
			document.getElementById('basketMain').style.display = "none";
			urlSimpleBasket = "inc/basket_listSimple.php?id=1312";
			loadHTML(urlSimpleBasket, 'dynamicBasket');
		}
		doGetTotalBasketValue();
	}
	
	function doPrintProInvoice(data){
	  window.open('inc/proInvoive.php?data='+data+'');
		doClosePrintProInvoice();
	}	
	
	function doPrintProInvoiceForAdmin(data){
	  window.open('../inc/proInvoive.php?data='+data+'');
		doClosePrintProInvoice();
	}		
	
	function doClosePrintProInvoice(){
	  document.getElementById('addOrder').innerHTML = "";
	  document.getElementById('addOrder').style.display = "none";		
	}
	
	function doSetDate(date){
		URL = "inc/setBasketDeliveryDate.php?date=" + date;
		loadHTML(URL, 'test');
	}	
	
	function doCloseOrderDetail(orderDIVId){
		document.getElementById(orderDIVId).style.display = "none";
	  var hideDIV = "hide_" + dest;
	  var showDIV = "show_" + dest;
	  document.getElementById(hideDIV).style.display = "none";
	  document.getElementById(showDIV).style.display = "block";		
	}		
	
	
	
	
	
// JAVASCRIPT MB5

/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

