//sare popup cu poza
function PopupPic(sPicURL) { 
     window.open( "popup.htm?"+sPicURL, "",  
     "resizable=1,HEIGHT=200,WIDTH=200"); 
   } 
//--sare popup cu poza	 
	 
//face divuri ascunse pentru departamnete	 
function SchimbaStil(nr)
	{
	e=document.getElementById(nr);
	if (e.style.display=='none') {e.style.visibility = "visible";e.style.display = "block";document.getElementById("t"+nr).innerHTML="- ";} 
 		else {e.style.visibility = "hidden";e.style.display='none';document.getElementById("t"+nr).innerHTML="+ ";}
	}
//--face divuri ascunse pentru departamnete	
	
//selecteaza state in functie de country	
function select_state()
	{
	
	state=document.getElementById('statele').value;
	country=document.getElementById('country');
	states=document.getElementById('states');
	var k;
  while(states.options.length > 0)
			{
       states.options[0] = null;
      }
	state=state.split(",");
	k=0;
	for(i=0;i<state.length;i++)
			{
			state[i]=state[i].split("-");
			if (state[i][0]==country.value)
				 {
				 states.options[k]=new Option(state[i][2],state[i][1],false,false);
				 k++
				 }
			}																										
	}	
//--selecteaza state in functie de country	
	
//verifica o adresa de email	
function emailCheck(emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
 //   alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	      //  alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
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) {
   // the address must end in a two letter or three letter word.
  // alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
  // alert(errStr)
   return false
}
return true	
}	
//--verifca o adresa de email	
	
//verifca daca un cuvant are numai litere	
function all_letters(str)
	{
	var letters=new Array ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  str=str.toString();
  str=str.toLowerCase();
	isok=true
  for(i=0;i<str.length;i++)
			{
			 islet=false;
       for(j=0;j<letters.length;j++)
			 	  {
            if(str.substring(i,i+1)==letters[j])
				  		{
                islet=true;
               }
           }
			 if (islet==false) isok=false;	  
      }
	if (str.length==0) isok=false;		
  return isok;
	}	
//--verifca daca un cuvant are numai litere	
	
//verifca daca un cuvant are numai litere si cifre	
function all_letters_numbers(str)
	{
	var letters=new Array ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","_","-");
  str=str.toString();
  str=str.toLowerCase();
	isok=true
  for(i=0;i<str.length;i++)
			{
			 islet=false;
       for(j=0;j<letters.length;j++)
			 	  {
            if(str.substring(i,i+1)==letters[j])
				  		{
                islet=true;
               }
           }
			 if (islet==false) isok=false;	  
      }
	if (str.length<6) isok=false;		
  return isok;
	}		
//--verifca daca un cuvant are numai litere si cifre	
	
	
//verifca daca forma usermanagement indelipneste conditiile	
function verify_usermanagement()
	{
	//a = document.getElementById("code");
	//a.value = document.getElementById("email").value;
	var eror="The next field are incorrect:\n";
	var corect=true;
	if (!(all_letters(document.getElementById("first_name").value))) {eror=eror+"- First Name\n";corect=false;}
	if (!(all_letters(document.getElementById("last_name").value))) {eror=eror+"- Last Name\n";corect=false;}
	if (!(emailCheck(document.getElementById("email").value))) {eror=eror+"- E-mail\n";corect=false;}
	if ((document.getElementById("street").value.length==0)) {eror=eror+"- Address\n";corect=false;}
	if (document.getElementById("zip").value==0) {eror=eror+"- Zip\n";corect=false;}	
	if ((document.getElementById("city").value.length==0)) {eror=eror+"- City\n";corect=false;}
//	if (!(all_letters_numbers(document.getElementById("code").value))) {eror=eror+"- Username must have at least 6 characters, only : letters,numbers,- and _\n";corect=false;}	
	if ((document.getElementById("pass").value.length<6)) {eror=eror+"Password must have at least 6 characters\n";corect=false;}
	if (document.getElementById("pass").value!=document.getElementById("repass").value) {eror=eror+"Password doesn't match\n";corect=false;}			
	if (!(corect)) alert(eror);
	return corect;
	}				 											
//--verifca daca forma usermanagement indelipneste conditiile

//reseteaza usermanagement la volorile initiale
function reset_usermanagement()
	{
	document.getElementById('first_name').value="";
	document.getElementById('last_name').value="";
	document.getElementById('email').value="";			
	document.getElementById('phone').value="";			
	document.getElementById('company').value="";			
	document.getElementById('function').value="";			
	document.getElementById('street').value="";
	document.getElementById('zip').value="";			
	document.getElementById('city').value="";			
	document.getElementById('code').value="";			
	document.getElementById('pass').value="";			
	document.getElementById('repass').value="";			
	}				 											
//--reseteaza usermanagement la volorile initiale	

//verifca daca forma userchangedetails indelipneste conditiile	
function verify_userchangedetails()
	{
	var eror="The next field are incorrect:\n";
	var corect=true;
	if (!(all_letters(document.getElementById("first_name").value))) {eror=eror+"- First Name\n";corect=false;}
	if (!(all_letters(document.getElementById("last_name").value))) {eror=eror+"- Last Name\n";corect=false;}
	if (!(emailCheck(document.getElementById("email").value))) {eror=eror+"- E-mail\n";corect=false;}
	if ((document.getElementById("street").value.length==0)) {eror=eror+"- Address\n";corect=false;}
	if (document.getElementById("zip").value==0) {eror=eror+"- Zip\n";corect=false;}	
	if ((document.getElementById("city").value.length==0)) {eror=eror+"- City\n";corect=false;}
	if (!(corect)) alert(eror);
	return corect;
	}				 											
//--verifca daca forma userchangedetails indelipneste conditiile

//reseteaza userchangedetails la volorile initiale
function reset_userchangedetails()
	{
	document.getElementById('first_name').value="";
	document.getElementById('last_name').value="";
	document.getElementById('email').value="";			
	document.getElementById('phone').value="";			
	document.getElementById('company').value="";			
	document.getElementById('function').value="";			
	document.getElementById('street').value="";	
	document.getElementById('zip').value="";			
	document.getElementById('city').value="";			
	}				 											
//--reseteaza userchangedetails la volorile initiale	

//reseteaza userchangepassword la volorile initiale
function reset_userchangepassword()
	{
	document.getElementById('pass').value="";			
	document.getElementById('repass').value="";			
	}				 											
//--reseteaza userchangepassword la volorile initiale

//verifca daca forma userchangepassword indelipneste conditiile	
function verify_userchangepassword()
	{
	var eror="The next field are incorrect:\n";
	var corect=true;
	if ((document.getElementById("pass").value.length<6)) {eror=eror+"Password must have at least 6 characters\n";corect=false;}
	if (document.getElementById("pass").value!=document.getElementById("repass").value) {eror=eror+"Password doesn't match\n";corect=false;}			
	if (!(corect)) alert(eror);
	return corect;
	}				 											
//--verifca daca forma userchangepassword indelipneste conditiile

	
function change_carrier(specialtax,shipvalue,totalprice)
	{
	document.getElementById("totalinvoice").innerHTML=eval(eval(specialtax)+eval(shipvalue)+eval(totalprice)).toFixed(2);
  document.paycc.totalinvoice.value=document.getElementById("totalinvoice").innerHTML;
  document.paycc.discount.value=document.getElementById("discountval").innerHTML;
  document.paycc.shippingprice.value=eval(shipvalue);			
//	document.payecheck.totalinvoice.value=document.getElementById("totalinvoice").innerHTML;
//	document.payinvoice.totalinvoice.value=document.getElementById("totalinvoice").innerHTML;
	}
	
function new_itemcart(nr)
	{
	but=document.getElementById("but"+eval(nr));
	but.style.visibility = "hidden";but.style.display='none';

	nr++;
	itemcart=document.getElementById("itemcart"+nr);
	itemcart.style.visibility = "visible";itemcart.style.display='block';
	but=document.getElementById("but"+nr);
	but.style.visibility = "visible";but.style.display='block';
	
	}
	
function mouse_over(nr)
	{
	stilu=document.getElementById("tcl"+eval(nr));
	stilu.color="#df0000";
	stilu.style.cursor="pointer";
	}
	
function mouse_out(nr)
	{
	stilu=document.getElementById("tcl"+eval(nr));
	stilu.color="#22488B";
	}		
	
function mouse_out1(nr)
	{
	stilu=document.getElementById("tcl"+eval(nr));
	stilu.color="#FFFFFF";
	}	