function NewWindow(mypage, myname, w, h, scroll, resizable) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) {win.window.focus(); }
}

function checkCuponAjax(values,path,idcountry) {
	var req = null; //Initialize the AJAX variable.
	if (window.XMLHttpRequest) { //Are we working with mozilla?
	req=new XMLHttpRequest(); //Yes -- this is mozilla.
	} else { //Not Mozilla, must be IE
	req=new ActiveXObject("Microsoft.XMLHTTP"); //Wheee, ActiveX, how do we format c: again?
	} //End setup Ajax.
	if (req==null) { //If we couldn't initialize Ajax...
	alert("Your browser doesn't support AJAX."); //Sorry msg.
	return false //
	}




		if(req){
			newImage = '<a onClick="checkCupon(\''+path+'\','+idcountry+');" style="cursor:pointer;"><img src="'+path+'/images/bttn_check-coupon.gif" border="0" /></a>';
			newImageLoad = '<img src="'+path+'/images/bttn_check-coupon-on.gif" border="0" />';
			req.onreadystatechange = function () {
			if (req.readyState == 4) {
		      if(req.status == 200) {	    		
	    		var xml = req.responseXML;
	    		var textout = xml.getElementsByTagName('amountramas').item(0).firstChild.nodeValue;                
	    		var okcoupon = xml.getElementsByTagName('couponok').item(0).firstChild.nodeValue;
	    		document.getElementById('errorcupon').innerHTML="";
	    		document.getElementById('checkcupon').innerHTML=newImage;	    		
				if(parseInt(textout,10)>=0){    				
	    				document.getElementById('amountcuponcupon').innerHTML = "Total Plata: "+textout+" Lei";
	    				if(parseInt(okcoupon,10)==1) {
	    					var coupondescr = xml.getElementsByTagName('coupondescr').item(0).firstChild.nodeValue;
	    					document.getElementById('couponvalueid').innerHTML = "Cupon reducere: -"+coupondescr;
	    				}
	    				else {
	    					document.getElementById('couponvalueid').innerHTML = "";
	    					document.getElementById('errorcupon').innerHTML='Cuponul introdus este invalid';
	    				}
	    				    			
	    		}
				else if (parseInt(textout,10)==-3) {
				    document.getElementById('errorcupon').innerHTML='Total 0';
				}
				else if (parseInt(textout,10)==-2) {
				    document.getElementById('errorcupon').innerHTML='Nu puteti folosi un cupon de reducere la cumpararea unui card cadou';
				}
	    		else{	    			
	    			document.getElementById('errorcupon').innerHTML='Cuponul introdus este invalid';
	    		}
			  }
			}
			};
			req.open("GET", path+"/prodcart/viewcupon.php?name=" +values+"&idcountry="+idcountry,true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			req.send(null);
			document.getElementById('checkcupon').innerHTML=newImageLoad;
		}else {
		  alert("Not req");
		}
	}
function checkCupon(path, idcountry){
	var cuponElement = document.getElementById('cocupon');
	var t='';
	
	 if (cuponElement != null)
			t=cuponElement.value;
	if(t.length>0) checkCuponAjax(t,path,idcountry);	
}
function checkGiftCertificateAjax(values,path,idcountry) {
	var req = null; //Initialize the AJAX variable.
	if (window.XMLHttpRequest) { //Are we working with mozilla?
		req=new XMLHttpRequest(); //Yes -- this is mozilla.
	} else { //Not Mozilla, must be IE
		req=new ActiveXObject("Microsoft.XMLHTTP"); //Wheee, ActiveX, how do we format c: again?
	} //End setup Ajax.
	if (req==null) { //If we couldn't initialize Ajax...
		alert("Your browser doesn't support AJAX."); //Sorry msg.
		return false //
	}

	if(req){
		newImage = '<a onClick="checkGiftCertificate(\''+path+'\','+idcountry+');" style="cursor:pointer;"><img src="'+path+'/images/bttn_check-coupon.gif" border="0" /></a>';
		newImageLoad = '<img src="'+path+'/images/bttn_check-coupon-on.gif" border="0" />';
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
		      if(req.status == 200) {	    		
	    		var xml = req.responseXML;
	    		var textout = xml.getElementsByTagName('amountramas').item(0).firstChild.nodeValue;                
	    		var okgiftcertificate = xml.getElementsByTagName('giftcertificateok').item(0).firstChild.nodeValue;
	    		document.getElementById('errorgiftcertificate').innerHTML="";
	    		document.getElementById('checkgiftcertificate').innerHTML=newImage;	    		
				if(parseInt(textout,10)>=0){    				
	    				document.getElementById('amountcuponcupon').innerHTML = "Total Plata: "+textout+" Lei";
	    				if(parseInt(okgiftcertificate,10)==1) {
	    					var giftcertificatedescr = xml.getElementsByTagName('giftcertificatedescr').item(0).firstChild.nodeValue;
	    					document.getElementById('giftcertificatevalueid').innerHTML = "Card cadou: -"+giftcertificatedescr;
	    				}						
	    				else {
	    					document.getElementById('giftcertificatevalueid').innerHTML = "";
	    					document.getElementById('errorgiftcertificate').innerHTML='Card cadou invalid';
	    				}
	    				    			
	    		}
				else if (parseInt(textout,10)==-3) {
					document.getElementById('errorgiftcertificate').innerHTML='Total 0';
				}
				else if (parseInt(textout,10)==-2) {
					document.getElementById('errorgiftcertificate').innerHTML='Nu puteti folosi un card cadou la cumpararea unui alt card cadou';
				}
	    		else{	    			
	    			document.getElementById('errorgiftcertificate').innerHTML='Card cadou invalid';
	    		}
			  }
			}
			};
			req.open("GET", path+"/prodcart/viewgift.php?name=" +values+"&idcountry="+idcountry,true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			req.send(null);
			document.getElementById('checkgiftcertificate').innerHTML=newImageLoad;
		}else {
		  alert("Not req");
		}
	}
function checkGiftCertificate(path, idcountry){
	var giftcertificateElement = document.getElementById('giftcertificateid');
	var t='';
	
	 if (giftcertificateElement != null)
			t=giftcertificateElement.value;
	if(t.length>0) checkGiftCertificateAjax(t,path,idcountry);	
}

function changeDescription() {
   var b=changeDescription.arguments;
   document.getElementById('galdescription').innerHTML = b[0];		
}
function changeOnClick() {
   var c=changeOnClick.arguments;
   var newlink = c[2]+'/gallery/gallery.php?id='+c[0]+'&idbound='+c[1];
   document.getElementById('linkpopup').setAttribute('href',newlink);   
}
function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}

/*function checkCuponReload(path,idevent,value){
	var t='';
	 if (value != null)
			t=value;
	if(t.length>0) checkCuponAjax(t,idevent,path);	
}*/
/******FORM OUT OF STOCK****************/
var whitespace = " \t\n\r";	
	function isEmpty(s)
	{
	   var i;
	   if((s == null) || (s.length == 0))
		  return true;
	   // Search string looking for characters that are not whitespace
	   for (i = 0; i < s.length; i++)    
		{   
		  var c = s.charAt(i);
		  if (whitespace.indexOf(c) == -1) 
			return false;
		}
		// At this point all characters are whitespace.
		return true;
	}
function emailCheck (emailStr) {
     var emailPat=/^(.+)@(.+)$/;
     var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
     var validChars="\[^\\s" + specialChars + "\]";
     var quotedUser="(\"[^\"]*\")";
     var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
     var atom=validChars + '+';
     var word="(" + atom + "|" + quotedUser + ")";
     var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
     var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

     var matchArray=emailStr.match(emailPat);
     if (matchArray==null) {
        //alert("Email address seems incorrect (check @ and .'s)")
        return false;
     }
     var user=matchArray[1];
     var domain=matchArray[2];

     if (user.match(userPat)==null) {
        //alert("The username doesn't seem to be valid.")
        return false;
     }

     var IPArray=domain.match(ipDomainPat);
     if (IPArray!=null) {
        for (var i=1;i<=4;i++) {
           if (IPArray[i]>255) {
               //alert("Destination IP address is invalid!")
               return false;
           }
         }
     return true;
     }

     var domainArray=domain.match(domainPat);
     if (domainArray==null) {
       //alert("The domain name doesn't seem to be valid.")
       return false;
     }

     var atomPat=new RegExp(atom,"g");
     var domArr=domain.match(atomPat);
     var len=domArr.length;
     if ((domArr[domArr.length-1].length<2) || (domArr[domArr.length-1].length>3)) {
       //alert("The address must end in a three-letter domain, or two letter country.")
       return false;
     }

     if (len<2) {
       //var errStr="This address is missing a hostname!"
       //alert(errStr)
       return false;
    }

     return true;
   }
   function ltrim(stringToTrim) {
	   return stringToTrim.replace(/^\s+/,"");
    }
	function createRequestObject(){
	var req = false;
  	
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		
		if(req.overrideMimeType){ req.overrideMimeType('text/xml'); }
	} 
	else if(window.ActiveXObject){
		try{ req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e){
			try{ req = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e){}
		}
	}
	
	if(!req){
		document.getElementById('progress_info').innerHTML = "Error: Your browser does not support AJAX";
		return false;
	}
	else{ return req; }	
}
function isInteger(s)
		{ 
		  var i=0, c;

		  for (i = 0; i < s.length; i++)   
		   { 
			// Check if all characters are numbers
			
			c = s.charAt(i);
			
			if (!isDigit(c)) 
			  return false;
		   }
		  return true;
	}
	
	function isDigit(c)
	{   
	
	 return ((c >= "0") && (c <= "9"))
	 
	}
	

function validprodofs(show, path){	//show = true => afisare eroare
		if (isEmpty(document.prodOutOfStock.nume.value)){
			if (show){
				alert("Va rugam specificati numele!");
				document.prodOutOfStock.nume.focus();
			}
			return false;
		}
		
		if (isEmpty(document.prodOutOfStock.telefon.value) && isEmpty(document.prodOutOfStock.email.value)){
			if (show){
				alert("Va rugam completati cel putin unul dintre campurile telefon sau email!");
				document.prodOutOfStock.telefon.focus();
			}
			return false;
		}
		if (!isEmpty(document.prodOutOfStock.email.value)) {
		  if(!emailCheck(ltrim(document.prodOutOfStock.email.value))) {
			if (show){
			    alert("Adresa de email este incorecta, \n nume@domeniu.ro");
                document.prodOutOfStock.email.focus();    
		     }	
		   return false;
		  }	
		}		
		
		if(!isInteger(document.prodOutOfStock.idproduct.value)) {
		   if (show){
				alert("Nu este selectat un produs");
				document.prodOutOfStock.idproduct.focus();
			}
			return false;
		   }else {
		     	sendReqProdOFS(path);
			}
	   }
	
	function sendReqProdOFS(path){
		var req = false;
    	var pofsclientnume = document.prodOutOfStock.nume.value;
		var pofsclienttelefon = document.prodOutOfStock.telefon.value;
		var pofsclientemail = document.prodOutOfStock.email.value;
		var pofsclientcomentariu = document.prodOutOfStock.comentariu.value;
				
		var idproduct = document.prodOutOfStock.idproduct.value;
		getparamidproduct = "&idproduct=" + idproduct;
		
		
        req = createRequestObject();
		if(req){    
		            req.onreadystatechange = function() {
						if(req.readyState == 4){
							if(req.status == 200){
								var xml = req.responseXML;
								idMail = xml.getElementsByTagName('idmail').item(0).firstChild.nodeValue;
								if (idMail > 0){
									alert("Comanda dvs a fost trimisa!");
									document.prodOutOfStock.nume.value="";
		                			document.prodOutOfStock.telefon.value="";
		                			document.prodOutOfStock.email.value="";
		                			document.prodOutOfStock.comentariu.value="";
									return true;
								}
								else{
									alert("Mail problem");
									return false;
								}
							}else {
			   					//alert("Not req status:"+req.status);
						}
					  }else  {
		    			//alert("Not req state");
					  }
					}    
					var params = "?clientnume=" + pofsclientnume + "&clienttelefon=" + pofsclienttelefon + "&clientemail=" + pofsclientemail + "&clientcomentariu=" + pofsclientcomentariu + getparamidproduct;
     				req.open("GET", path+"/reqprodofs/add.php"+params, true);

					req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
					req.send(null);
		}
		else {
		 alert("Not req");
		}	

}
