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

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 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();
}

//-----------------------------------------------------------------------
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';
}
//-----------------------------------------------------------------------

//------------------------------------------------
//		FORM VALIDATION FUNCTIONS
//------------------------------------------------

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) {		// v. 0.1

	var x = value;
	//var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,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;
}

// 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 age_check(value) {			// check between 10 - 99 years only
	
	var x = value;
	//var filter  = /^([1-9]{1})([0-9]{0,2})$/;
	var filter  = /^[1-9]{1}[0-9]{1}$/;
	if (filter.test(x)) return true;
	else return false;
}
//------------------------------------------------
//------------------------------------------------

/*
function check_application_form() {                                                // verificare date formular   xxxxxxxxxxxxx
	
     if (empty_field(document.application.last_name.value) == false) {
     		alert("Va rugam sa completati campul 'Nume' !");
        	return false;
    	}
     if (empty_field(document.application.first_name.value) == false) {
     		alert("Va rugam sa completati campul 'Prenume' !");
        	return false;
    	}
     if (empty_field(document.application.age.value) == false) {
     		alert("Va rugam sa completati campul 'Varsta' !");
        	return false;
    	}
     if (age_check(document.application.age.value) == false) {
     		alert("Cimpul varsta nu este completat corect !");
        	return false;
    	}
     if (empty_field(document.application.phone.value) == false && empty_field(document.application.email.value) == false) {
     		alert("Va rugam sa completati cel putin unul din campurile 'Telefon' sau 'Email' !");
        	return false;
    	}
     if (empty_field(document.application.email.value) == true && check_email(document.application.email.value) == false) {
     		alert("Campul email nu este completat corect !");
        	return false;
    	}

     if (document.application.work_place_period_id.value == '' | document.application.work_place_period_id.value == 0) {
     		alert("Va rugam sa selectati vechimea la actualul loc munca !");
        	return false;
    	}
     if (empty_field(document.application.income.value) == false) {
     		alert("Va rugam sa completati campul 'Venituri nete' !");
        	return false;
    	}
    if (document.application.income_currency_id.value == '' | document.application.income_currency_id.value == 0) {
     		alert("Va rugam sa selectati moneda in care aveti veniturile !");
        	return false;
    	}

	if (!document.application.marital_status[0].checked && !document.application.marital_status[1].checked) {
     		alert("Va rugam sa selectati campul 'Starea civila' !");
        	return false;
    	}
    else if (document.application.marital_status[0].checked) {
		
	     if (empty_field(document.application.spouse_age.value) == false) {
	     		alert("Va rugam sa completati campul 'Varsta sot/sotie' !");
	        	return false;
	    	}
	     if (age_check(document.application.spouse_age.value) == false) {
	     		alert("Cimpul varsta sot/sotie nu este completat corect !");
	        	return false;
	    	}
	     if (document.application.spouse_work_place_period_id.value == '' | document.application.spouse_work_place_period_id.value == 0) {
	     		alert("Va rugam sa selectati vechimea sotului/sotiei la actualul loc munca !");
	        	return false;
	    	}
	     if (empty_field(document.application.spouse_income.value) == false) {
	     		alert("Va rugam sa completati campul 'Venituri nete sot/sotie' !");
	        	return false;
	    	}
	    if (document.application.spouse_income_currency_id.value == '' | document.application.spouse_income_currency_id.value == 0) {
	     		alert("Va rugam sa selectati moneda in care sotul/sotia are veniturile !");
	        	return false;
	    	}
    }
    	

    	
    if (document.application.credit_type_id.value == '' | document.application.credit_type_id.value == 0) {
     		alert("Va rugam sa selectati tipul de credit !");
        	return false;
    	}
    	
     if (empty_field(document.application.credit_amount.value) == false) {
     		alert("Va rugam sa completati campul 'Suma solicitata' !");
        	return false;
    	}

    if (document.application.credit_currency_id.value == '' | document.application.credit_currency_id.value == 0) {
     		alert("Va rugam sa selectati moneda in care doriti creditul !");
        	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.phone.value) == false && empty_field(document.contact.email.value) == false) {
     		alert("Va rugam sa completati cel putin unul din campurile 'Telefon' sau 'Email' !");
        	return false;
    	}
     if (empty_field(document.contact.email.value) == true && 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";
		}
		
	}

}*/


function show_hide_div(div_id, action) {
		
	//var div_less = div_id + '_less';
	//var div_more = div_id + '_more';
	
	//var div_id;
	//var action;
	
	if (action == 'show') {action = 'block'}
	if (action == 'hide') {action = 'none'}
//	var link_less = div_id + '_link_less';
//	var link_more = div_id + '_link_more';
		
	if (document.getElementById)
	{
		document.getElementById(div_id).style.display = action;
	}
	else if (document.all)
	{
		document.all[div_id].style.display = action;
	}
	else if (document.layers)
	{
		document.layers[div_id].style.display = action;
	}
}

function openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// ROLL OVER DREAMWEAVER
/*
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
*/