var unfolded = false;

function getOffsetTop(idfather) {
	elm = document.getElementById('main_menu');
	var mOffsetTop = elm.offsetLeft; 
	
	var mOffsetParent = elm.offsetParent;
	var parents_up = 2; //the positioning div is 2 elements up the tree
	parents_up = 9; //the positioning div is 2 elements up the tree

	while(parents_up > 0) {
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetTop;
} 

function getOffsetLeft(idfather) {
	elm = document.getElementById('main_' + idfather);
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	var parents_up = 9;
	while(parents_up > 0) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetLeft;
}
var id;
function showSubmenu(idfather){
	var submenu = document.getElementById('submenu_' + idfather);
	hideAllDivs();
	if (submenu != null)
		if (submenu.style.display == 'none'){
			hideAllDivs();
			submenu.style.position ='absolute';
			submenu.style.top = getOffsetTop(idfather) + 21;
			submenu.style.left = getOffsetLeft(idfather)+15;
			//parseInt(submenu.style.top, getOffsetTop(idfather) + 30);
			//parseInt(submenu.style.top, getOffsetLeft(idfather)+50);
			submenu.style.display = 'block';
			submenu.onmouseover=function(){this.style.display='block';}
			//submenu.onmouseout=function(){setTimeout("document.getElementById('submenu_"+ idfather +"').style.display='none';",2000)}
			submenu.onmouseout=function(){hideWithDelay();}
			
		} else {
			submenu.style.display = 'none'
		}
	
}
function hideWithDelay(type){
 	
	//this.id = setTimeout("hideAllDivs()",2000);
	hideAllDivs();
}
function hideSubmenu(el){
	//alert(unfolded);
	unfolded = true;
	el.style.display = 'none';
	
}

function hideAllDivs(){
	var alltags=document.all? document.all : document.getElementsByTagName("*"); 
	for (i=0; i<alltags.length; i++){ 
   		if (alltags[i].tagName=='DIV') {
     		var n = alltags[i].id;
			rExp = /submenu_/gi;
			result = n.search(rExp)
			if (result != -1)
				alltags[i].style.display = 'none';
		}
 	} 
	
     
	
}



function viewPic(idpic,type){
	window.open('lib/poza_preview.php?type='+type+'&idpicture=' + idpic,'View_picture','width=300,height=300,scroll=yes');
}

function viewFile(idpic){
	window.open('lib/viewFile.php?idattach=' + idpic,'','width=800,height=600,scroll=yes');
}

function validateEmail(){
	var email = document.getElementById('email').value;
	
	if (!echeck(email)){
		alert('Adaugati o adresa de e-mail valida !');
		return;
	} else {
		var frm = document.getElementById('form1');
		frm.submit();
	}
}

function clearEmail(){
	var email = document.getElementById('email');
	email.value = '';

}
function addEmail(){
	var email = document.getElementById('email');
	email.value = 'e-mail ... ';
	
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		//   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 //  alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		 //   alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		  // alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   //// alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left="30px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" //extra
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function valideazaTrimiteFormular2(){
	var societate = document.getElementById('societate');
	
	if (societate.value == ''){
		alert ('Trebuie completat numele societatii !');
		societate.focus();
		return;
	}
	
	
	var contact = document.getElementById('contact'); 
	if (contact.value == ''){
		alert ('Trebuie completata persoana de contact si functia !')	;
		contact.focus();
		return;
	}
	
	var tel = document.getElementById('tel');
	if (tel.value == ''){
		alert ('Trebuie completat numarul de telefon sau fax !');
		tel.focus();
		return;
	}
	
	var marfa = document.getElementById('marfa');
	if (marfa.value == ''){
		alert ('Trebuie completata marfa manipulata !');
		marfa.focus();
		return;
	}
	
	var sarcina = document.getElementById('sarcina');
	if (sarcina.value == ''){
		alert ('Trebuie comletata sarcina maxima !');
		sarcina.focus();
		return;s
	}
	
	var inaltime = document.getElementById('inaltime');
	if (inaltime.value == ''){
		alert ('Trebuie completata inaltimea maxima !');	
		inaltime.focus();
		return;
	}
	
	var frm = document.getElementById('form1');
	frm.submit();
	
}
function valideazaTrimiteFormular1(){
	var societate = document.getElementById('societate');
	
	if (societate.value == ''){
		alert ('Please insert the name of the society !');
		societate.focus();
		return;
	}
	
	
	var contact = document.getElementById('contact'); 
	if (contact.value == ''){
		alert ('Please insert the name of the contact person !')	;
		contact.focus();
		return;
	}
	
	var tel = document.getElementById('tel');
	if (tel.value == ''){
		alert ('Please insert the phone or fax no. !');
		tel.focus();
		return;
	}
	
	var marfa = document.getElementById('marfa');
	if (marfa.value == ''){
		alert ('Please insert the type of handled goods!');
		marfa.focus();
		return;
	}
	
	var sarcina = document.getElementById('sarcina');
	if (sarcina.value == ''){
		alert ('Please insert the max. capacity!');
		sarcina.focus();
		return;s
	}
	
	var inaltime = document.getElementById('inaltime');
	if (inaltime.value == ''){
		alert ('Please insert the maximum height !');	
		inaltime.focus();
		return;
	}
	
	var frm = document.getElementById('form1');
	frm.submit();
	
}
