// Javascript Functions
// Helios Design http://www.heliosdesign.ro/

function rowOverEffect(object) {
  if (object.className == 'dataTableRow1') object.className = 'dataTableRowOver1';
  if (object.className == 'dataTableRow2') object.className = 'dataTableRowOver2';
}

function rowOutEffect(object) {
  if (object.className == 'dataTableRowOver1') object.className = 'dataTableRow1';
  if (object.className == 'dataTableRowOver2') object.className = 'dataTableRow2';
}










































function confirm_action(path, text) {
	if(text == '') {
		text = 'Confirmati ?';
	}
	var answer = confirm (text);
	if (answer) {
	  location.href = path;
	}
}
function open_popup(path, file_name) {


    var width = 500;
    var height = 400;

	var winleft = (screen.width - width) / 2;
	if (winleft < 0) winleft = 0;
	var wintop = (screen.height - height) / 2;
	if (wintop < 0) wintop = 0;
    //alert(winleft);
    var parameters = "width="+width+", height="+height+", left="+winleft+", top="+wintop+", toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes";
	//window.open(\'includes/open_popup.php?path=download/051124_214101_29.jpg\',\'name\',\'width=+width+, height=+height+, left=+winleft+, top=+wintop+, toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes\');

	var file_to_open = '/includes/open_popup.php?directory='+path+'&file_name='+file_name;

	window.open(file_to_open, '', parameters);
}
/*function admin_open_popup(directory, file_name, width, height, window_name, position) {

	if(width == '') {width = 500;}
	if(height == '') {height = 450;}
    //var width = 500;
    //var height = 450;

    if(position == 'right') {
		var winleft = (screen.width - width);
		//var winleft = 30;
		if (winleft < 0) winleft = 0;
		var wintop = 0;
    }
    else if(position == 'left') {
    	var winleft = 0;
    	var wintop = 0;
    }
    else {
		var winleft = (screen.width - width) / 2;
		if (winleft < 0) winleft = 0;
		var wintop = (screen.height - height) / 2;
		if (wintop < 0) wintop = 0;
    }
    //alert(winleft);
    var parameters = "width="+width+", height="+height+", left="+winleft+", top="+wintop+", toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes";
	//window.open(\'includes/open_popup.php?path=download/051124_214101_29.jpg\',\'name\',\'width=+width+, height=+height+, left=+winleft+, top=+wintop+, toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes\');

	if(directory == '') {
		var file_to_open = '../'+file_name;
	}
	else {
		var file_to_open = '../'+directory+'/'+file_name;
	}
	
	var new_window;
	
	new_window = window.open(file_to_open, window_name, parameters);
	//alert(window_name+'rrrr');
	new_window.focus();
}*/

//		FORM VALIDATION

function trim(sString) {

	while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
}

function empty_field(val) {

    if(trim(val) == ""){return false;}
	return true;
    }
/*function checkEmail(val) {

    if(trim(val) == ""){return false;}
	return true;
    }*/

function check_email(value) {

	var x = value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

// atentie la ++++++++++++++++++
function check_date(value) {
	//	minimal date check
	var x = value;
	var filter  = /^([0-3]{1})+([0-9]{1})+(\/)+([0-1]{1})+([0-9]{1})+(\/)+([0-9]{4})+$/;
	//var filter  = /^([a-zA-Z0-9_\.\-])(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}
/*function isBlank(val)
	{
    if(val==null){return true;}
    for(var i=0;i<val.length;i++)
    	{
	    if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
        {return false;}
    	}
    return true;
    }*/

function check_accreditation_form() {                                                // verificare date formular   xxxxxxxxxxxxx

     if (empty_field(document.accreditation_form.last_name.value) == false) {
     		alert("Va rugam sa completati campul 'Nume' !");
        	return false;
    	}
     if (empty_field(document.accreditation_form.first_name.value) == false) {
     		alert("Va rugam sa completati campul 'Prenume' !");
        	return false;
    	}
     if (empty_field(document.accreditation_form.birth_date.value) == false) {
     		alert("Va rugam sa completati campul 'Data nasterii' !");
        	return false;
    	}

   	if (check_date(document.accreditation_form.birth_date.value) == false) {
     		alert("Format incorect. Data nasterii trebuie sa fie in format ZZ/LL/AAAA !");
        	return false;
    	}
    if (empty_field(document.accreditation_form.birth_place.value) == false) {
     		alert("Va rugam sa completati campul 'Locul nasterii' !");
        	return false;
    	}

    if (empty_field(document.accreditation_form.nationality.value) == false) {
     		alert("Va rugam sa completati campul 'Nationalitatea' !");
        	return false;
    	}

    if (empty_field(document.accreditation_form.identity_act_no.value) == false) {
     		alert("Va rugam sa completati campul 'Act de identitate: Serie / Numar' !");
        	return false;
    	}

    if (empty_field(document.accreditation_form.address_1_address.value) == false) {
     		alert("Va rugam sa completati campul 'Adresa redatiei: Adresa' !");
        	return false;
    	}
    if (empty_field(document.accreditation_form.address_1_email.value) == false) {
     		alert("Va rugam sa completati campul 'Adresa redatiei: Email' !");
        	return false;
    	}
    if (check_email(document.accreditation_form.address_1_email.value) == false) {
     		alert("Format invalid in campul 'Adresa redatiei: Email' !");
        	return false;
    	}
    if (empty_field(document.accreditation_form.address_1_phone.value) == false) {
     		alert("Va rugam sa completati campul 'Adresa redatiei: Telefon' !");
        	return false;
    	}
    if (empty_field(document.accreditation_form.address_1_fax.value) == false) {
     		alert("Va rugam sa completati campul 'Adresa redatiei: Fax' !");
        	return false;
    	}

//		LOCUL DE MUNCA

    if (empty_field(document.accreditation_form.work_institution.value) == false) {
     		alert("Va rugam sa completati campul 'Denumirea institutiei' !");
        	return false;
    	}
	if (empty_field(document.accreditation_form.work_contact_person.value) == false) {
     		alert("Va rugam sa completati campul 'Persoana de contact' !");
        	return false;
    	}

//		DROP LISTS

    if (document.accreditation_form.media_statute_type_id.value == ''
    	&& empty_field(document.accreditation_form.media_statute_type_other.value) == false) {
     		alert("Va rugam sa selectati sau completati, dupa caz, campul 'Statut / actionariat' !");
        	return false;
    	}
    if (document.accreditation_form.media_institution_type_id.value == ''
    	&& empty_field(document.accreditation_form.media_institution_type_other.value) == false) {
     		alert("Va rugam sa selectati sau completati, dupa caz, campul 'Tip institutie' !");
        	return false;
    	}
    if (document.accreditation_form.media_function_type_id.value == ''
    	&& empty_field(document.accreditation_form.media_function_type_other.value) == false) {
     		alert("Va rugam sa selectati sau completati, dupa caz, campul 'Functia' !");
        	return false;
    	}



	//document.contact.submit();
	return true;
}

//document.write('<hr>test<hr>');

function check_contact_form() {                                                // verificare date formular CONTACT

     if (empty_field(document.contact.name.value) == false) {
     		alert("Va rugam sa completati campul 'Nume' !");
        	return false;
    	}
     if (empty_field(document.contact.email.value) == false) {
     		alert("Va rugam sa completati campul 'Email' !");
        	return false;
    	}
     if (check_email(document.contact.email.value) == false) {
     		alert("Adresa de email nu este valida!");
        	return false;
    	}
     if (empty_field(document.contact.msg.value) == false) {
     		alert("Va rugam sa completati campul 'Mesaj' !");
        	return false;
    	}
	//document.contact.submit();
	return true;
}



function show_hide_div_content(div_id) {
		
	var div_less = div_id + '_less';
	var div_more = div_id + '_more';
	
	var link_less = div_id + '_link_less';
	var link_more = div_id + '_link_more';
		
	if (document.getElementById)
	{
		// this is the way the standards work
		//var style2 = document.getElementById(div_id).style;
		//style2.display = style2.display? "":"block";
		
		if(document.getElementById(div_less).style.display == "block") {
			
			document.getElementById(div_less).style.display = "none";
			//document.getElementById(div_more).style.display = "block";
			
			document.getElementById(link_less).style.display = "none";
			document.getElementById(link_more).style.display = "block";
			
		}
		else {
			document.getElementById(div_less).style.display = "block";
			//document.getElementById(div_more).style.display = "none";
			
			document.getElementById(link_less).style.display = "block";
			document.getElementById(link_more).style.display = "none";		
		}
	}

	else if (document.all)
	{
		// this is the way old msie versions work
		//var style2 = document.all[div_id].style;
		//style2.display = style2.display? "":"block";

		if(document.getElementById(div_less).style.display == "block") {
			
			document.all[div_less].style.display = "none";
			document.all[div_more].style.display = "block";
		}
		else {
			document.all[div_less].style.display = "block";
			document.all[div_more].style.display = "none";
		}		
	}

	else if (document.layers)
	{
		// this is the way nn4 works
		//var style2 = document.layers[div_id].style;
		//style2.display = style2.display? "":"block";
		
		if(document.getElementById(div_less).style.display == "block") {
			
			document.layers[div_less].style.display = "none";
			document.layers[div_more].style.display = "block";
		}
		else {
			document.layers[div_less].style.display = "block";
			document.layers[div_more].style.display = "none";
		}
		
	}

	//	focus pe un hidden field pt firefox, altfel nu mai poti face scroll pe pagina fara sa dai click pe ea
/*	var form_name = div_id + '_form';
	var input_name = div_id + '_input';
	document.forms[form_name].elements[input_name].focus();*/
}
