// des bonbon
function getObj(id) {
	var obj = document.getElementById(id);
	return obj;
}

/* 	data: 
tabel = 859; div = 179; 
	left1 = (latime - 859)/2
	left = left1 + 179;
*/

var isShown = '';

function genCoord(obj) {
/* first hide other shown elements */
	turnOff();
	var id2 = obj.id + 2; 
	if (isShown == id2 && document.getElementById(isShown).style.display == "block") {return;}
	if (isShown) {document.getElementById(isShown).style.display = "none";}

/* then show what you want */
	var left1 = parseInt(document.body.clientWidth - 859)/2;
	if (left1 < 0) left1 = 0; 
	var left = left1;
	var width = 210;
	var top = 260 + 31*(parseInt(obj.title)); 
	obj2 = getObj(id2);
	if (getObj(id2))
	{
		obj2.style.display = "block"; 
		obj2.style.left = parseInt(left) + parseInt(width);
		obj2.style.top = parseInt(top);
		/* need to keep isShown alive! */
		isShown = obj2.id;
		/* here you stop the timer that clears the menu after 2 secs */
	}
}
function clearMenu() {
	if (isShown) {document.getElementById(isShown).style.display = "none";}
}
var running = 0;
var secunde = 0;

function turnOn() {
	running = 1; timeOn();
}

function timeOn() {
	if (running) {
		secunde++;
		if (secunde >=3) {clearMenu();}
		else { setTimeout("timeOn()",1000);}
	}
}

function turnOff() {
	running = 0;
	secunde = 0;
}


function IEHoverPseudo() {

	var navItems = document.getElementById("primary-nav-menu").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; this.style.zindex="500"; }
			navItems[i].onmouseout=function() { this.className = "menuparent";  this.style.zindex="auto"; }
		}

		if(navItems[i].className == "current") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "current"; }
		}
	}

}

function IEHoverPseudo2() {

	var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent"; }
		}
	}
}

function ValidateRegisterNewUser()
	{
		var fields = new Array();
		var i=0;
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		
		if ( document.getElementById( 'reg_username' ).value.length == 0 )
		fields[ i++ ] = "Username (Username)\n";
		if (( document.getElementById( 'reg_password' ).value.length == 0) || (document.getElementById( 'reg_password_2' ).value.length == 0) || (document.getElementById( 'reg_password' ).value != document.getElementById( 'reg_password_2' ).value))
		fields[ i++ ] = "Parola (Password)\n";
		if ( document.getElementById( 'reg_name' ).value.length == 0 )
		fields[ i++ ] = "Nume (Name)\n";
		if ( !filter.test( document.getElementById('reg_email').value ) )
		fields[ i++ ] = "Email (Email)\n";
		if ( document.getElementById( 'reg_address' ).value.length == 0 )
		fields[ i++ ] = "Adresa (Address)\n";
		if ( document.getElementById( 'reg_telephone' ).value.length == 0 )
		fields[ i++ ] = "Telefon (Telephone)\n";
		if ( document.getElementById( 'reg_city' ).value.length == 0 && document.getElementById( 'reg_city_selection' ).value == 0 )
		fields[ i++ ] = "Oras (City)\n";
		if ( document.getElementById( 'reg_zipcode' ).value.length == 0 )
		fields[ i++ ] = "Cod postal (Zip code)\n";		
		if ( fields.length > 0 )
		{
			var str = "";
			for ( i = 0;i < fields.length;i++ )
			str += fields[ i ];
			alert( "Urmatoarele campuri n-au fost completate sau sunt introduse eronat:\n ( The following fields were not completed correctly: ) \n\n" + str );
			return false;
		}
		else
		{			
			document.getElementById( 'reguser' ).submit();
		}

	}
function ValidateUpdateUser()
	{
		var fields = new Array();
		var i=0;
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;

		if ( document.getElementById( 'reg_username' ).value.length == 0 )
		fields[ i++ ] = "Username (Username)\n";
		if (( document.getElementById( 'reg_password' ).value.length == 0) || (document.getElementById( 'reg_password_2' ).value.length == 0) || (document.getElementById( 'reg_password' ).value != document.getElementById( 'reg_password_2' ).value))
		fields[ i++ ] = "Parola (Password) \n";
		if ( document.getElementById( 'reg_name' ).value.length == 0 )
		fields[ i++ ] = "Nume (Name)\n";
		if ( !filter.test( document.getElementById('reg_email').value ) )
		fields[ i++ ] = "Email (Email)\n";
		if ( document.getElementById( 'reg_address' ).value.length == 0 )
		fields[ i++ ] = "Adresa (Address)\n";
		if ( document.getElementById( 'reg_telephone' ).value.length == 0 )
		fields[ i++ ] = "Telefon (Telephone)\n";
		if ( document.getElementById( 'reg_city' ).value.length == 0  && document.getElementById( 'reg_city_selection' ).value == 0 )
		fields[ i++ ] = "Oras (City)\n";
		if ( document.getElementById( 'reg_zipcode' ).value.length == 0 )
		fields[ i++ ] = "Cod postal (Zip code)\n";
		if ( fields.length > 0 )
		{
			var str = "";
			for ( i = 0;i < fields.length;i++ )
			str += fields[ i ];
			alert( "Urmatoarele campuri n-au fost completate sau sunt introduse eronate:\n( The following fields were not completed correctly: )\n\n" + str );
			return false;
		}
		else
		{		
			document.getElementById( 'upduser' ).submit();
		}

	}


/* display a pop-up window with the product contents of some box */
var winPop = null;
function openProdContent(sURL, sWinName, iWidth, iHeight) {
  var strParams;
  if (!winPop || winPop.closed) {
    strParams = "dependent=yes,scrollbars=yes,toolbar=no,directories=no,location=no,menubar=no,resizable=yes,status=no,width=" + iWidth + ",height=" + iHeight;
    winPop = open(sURL,sWinName,strParams);
  } else {
    winPop.location = sURL;
    winPop.focus();
  }
}


function showImage(strUrl)
{
	myImage = new Image();
	myImage.src = strUrl;
	//alert('Inaltimea '+ myImage.height);
	//alert('Width:  '+ myImage.width);
	var width = Math.round(myImage.width + 40);
	var height = Math.round(myImage.height + 30);

	
	var NewWin=window.open('','NwWin','width=550,height=500,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
	var str='';
	str='<html><head><title> :: Picture ::</title></head><body style="margin: 1px 1px 1px 1px;">';			
	str+='<div align="center"><img src="'+strUrl+'" border="0" hspace="10" vspace="10"></div>';
	str+='</body></html>';
	NewWin.document.write(str);
}

function CheckEmail(form,email)
	{
		var fields = new Array();
		var i=0;
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		if ( !filter.test( document.getElementById(email).value ) )
		fields[ i++ ] = "Email\n";		
		if ( fields.length > 0 )
		{
			var str = "";
			for ( i = 0;i < fields.length;i++ )	
				str += fields[i];
			alert( "Please insert a valid account" + "\n" + "Va rugam sa introduceti un email valid");
			return false;
		}
		else
		{		
			document.getElementById( form ).submit();
		}

	}


function showDiv(div)
{
	element = document.getElementById('menu'+div);
	
	if (element.style.display=="none"){
		element.style.display="block";
	}
}

function hideDiv(div)
{
	element = document.getElementById('menu'+div);
	
	if (element.style.display=="block"){
		element.style.display="none";
	}
	element.style.display="none";
}

function hideAllDivs()
{
	hideDiv(2);hideDiv(3);
}



function modifyInput(inputTriggerat, inputCareTriggereaza)
{
	if(document.getElementById( inputCareTriggereaza ).value == 0)
	{
		document.getElementById(inputTriggerat).className="text_meniu";
		document.getElementById(inputTriggerat).readOnly="";		
	}
	else
	{
		document.getElementById(inputTriggerat).className="inp-rdonly";
		document.getElementById(inputTriggerat).readOnly="true";
		document.getElementById(inputTriggerat).value="";
	}
}