/**
* changeDisplay - schimba modul de afisare (ascuns sau vizibil)
* @param - int elementId, string setTo
* @return - void
**/

function changeDisplay( elementId, setTo ) {
  
  setTo = (setTo == 'block') ? 'none' : 'block';

   var theElement;
  if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( elementId );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ elementId ];
  }
  if( !theElement ) {
    /* The page has not loaded, or the browser claims to
    support document.getElementById or document.all but
    cannot actually use either */
    return;
  }
  //Reference the style ...
  if( theElement.style ) { theElement = theElement.style; }
  if( typeof( theElement.display ) == 'undefined' ) {
    //The browser does not allow us to change the display style
    //Alert something sensible (not what I have here ...)
    window.alert( 'Your browser does not support this' );
    return;
  }
  //Change the display style
  theElement.display = setTo;
}


/**
* expand - afiseaza sau ascunde bloc
* @param - int curobj_id
* @return - void
**/

function expand(curobj_id){

var id = curobj_id;


 var theElement;
  if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( id );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ id ];
  }
  if( !theElement ) {
    /* The page has not loaded, or the browser claims to
    support document.getElementById or document.all but
    cannot actually use either */
    return;
  }
  //Reference the style ...
  if( theElement.style ) { theElement = theElement.style; }

changeDisplay(id, theElement.display)

}


function check(elem,name) {
	if(elem.checked == false){
		alert(name);
		return false;
	} else {
		return true;
	};
}

function checkR(elem,name) {

	onechecked = false;
	for(i=0; i < elem.length; i++){
		if (elem[i].checked)
			onechecked = true;
	}
	
	if(!onechecked) {
		alert ('Completati '+name+"!");
		return false;
	}
	else 
		return true;
	
}

function isTop()
{
	if (this.location != top.location)
	{
		top.location = this.location;
	}
}

function clearFrm() {
	if (confirm('Are you sure you want to clear all data in the form?'))
		window.location=window.location;
}

function confDel() {
	if (!confirm('Are you sure you want to delete this?')) {
		return false;
	}
}

function checkUrl(elem, name) {
	var def = "http://";
	if ((elem.value == 0) || (elem.value.indexOf(def) == -1)) {
		alert("Completati "+ name +".")
		elem.value = def;
	    elem.focus();
	    return false;
	}
	if (elem.value.length <= def.length) {
		alert("Completati valabila "+ name +".")
	    elem.focus();
	    return false;
	}
	return true;
}

function full(elem, name) {
	if (elem.value == 0) {
		alert("Completati "+ name +".")
	    elem.focus();
	    return false;
	}
	return true;
}

function sel(elem, name) {
	if (elem.options[elem.options.selectedIndex].value == 0) {
        alert ("Selectati "+ name +".");
        elem.focus();
        return false;
    }
	return true;
}

function comparePwd(sPwd,sPwd2) {
	if (!full(sPwd, 'password')) return false;
	if (!full(sPwd2, 'password again')) return false;
	if (sPwd.value != sPwd2.value) {
		alert("Passwords do not match. Please try again.");
		sPwd2.value = "";
		sPwd.value = "";
		sPwd.focus();
		return false;
	}
	return true;
}

function checkEmail(eml) {
	if (eml.value == 0) {
		alert("Va rugam sa introduceti o adresa e e-mail.");
	    eml.focus();
	    return false;
	} else {
//		var re=/^[\w\.\+-]*@[\w\+-]+(\.[\w\+-]+)*\.[\w\+-]+$/;
		var re=/^[\w\.\_\+-]*@[\w\_\+-]+(\.[\w\_\+-]+)*\.[\w\+-]+$/;
		if (eml.value.search(re)==-1) {
			alert("Va rugam sa introduceti o adresa e e-mail valabila.");
			eml.focus();
			return false;
		}
		return true;
	}
}

function checkValidEmail(eml) {
	if (eml.value != "") {
		var re=/^[\w\.\+-]*@[\w\+-]+(\.[\w\+-]+)*\.[\w\+-]+$/;
		if (eml.value.search(re)==-1) {
			alert("Va rugam sa introduceti o adresa e e-mail valabila.");
			eml.focus();
			return false;
		}
		return true;
	}
	return true;
}

function popup(url, wname, wid, hei) {
	newWindow = window.open(url, wname, "toolbar=no,menubar=no,scrollbars=yes,resizable=no,status=no,location=no,height="+hei+",width="+wid);
	newWindow.focus();
}
