


/* Verificare input
*****************************************************************/

function checkValid(id, msg, regula) {
	var prefix = "* ";
	var suffix = "\n";
	
	
	switch(regula) {
		case 'required':
						if (document.getElementById(id).value=="")
							return prefix+msg+suffix;
						break;
		case 'select':
						if (document.getElementById(id).options[document.getElementById(id).selectedIndex].value=="")
							return prefix+msg+suffix;
						break;
		case 'numeric':
						var validch = "0123456789.";
						var isNumber=true;
						var ch;
						var val = document.getElementById(id).value;
						
						for (i=0; i<val.length && isNumber == true; i++) { 
							ch = val.charAt(i); 
							if (validch.indexOf(ch) == -1) 								
								return prefix+msg+suffix;
						}
						break;
		case 'email':
						var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'integer':
						var filter=/^\d{0,9}$/;
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'limitpercent':
						if (document.getElementById(id).value<0 || document.getElementById(id).value>100)
							return prefix+msg+suffix;
						break;
	}
	return "";
}

function checkIdentical(id1, id2, msg) {

	var prefix = "* ";
	var suffix = "\n";

	if (document.getElementById(id1).value != document.getElementById(id2).value)
	return prefix+msg+suffix
	else
	return ''

}

function checkLength(id, min, max, msg) {

	var prefix = "* ";
	var suffix = "\n";

	if (document.getElementById(id).value.length < min || document.getElementById(id).value.length > max )
	return prefix+msg+suffix
	else
	return ''

}

function checkRadio(form_name,radio_name,msg)
{
	
	var radio_choice = false;	
	var prefix = "* ";
	var suffix = "\n";
	radio_obj = eval('document.'+form_name+'.'+radio_name);
	
	if (radio_obj.checked) {
		radio_choice = true; 	
	} else {	
		for (counter = 0; counter < radio_obj.length; counter++)
		{
			
			if (radio_obj[counter].checked) {
				radio_choice = true; 
				break;
			}
		}
	}
	
	if (!radio_choice) {
		return prefix+msg+suffix;
	}
	    return '';
}

function verificaFormular(which) {
	msg_alert = "______________________________________________________\n\n"
	msg_alert += "Your request was not acomplished for the folowing reasons:\n";
	msg_alert += "Please fill in and check again:\n";
	msg_alert += "______________________________________________________\n";
	msg_alert += "\n";
	switch(which) {
		
		case "trimite_mail":				
					msg = "";	
					msg += checkValid("nume", "You must spcify your name.", "required");
					msg += checkValid("numar_casa", "You must provide us your House number.", "required");
					msg += checkValid("Street", "You must fill in your street adress.", "required");
					msg += checkValid("oras", "You must specify the Town/City.", "required");
					msg += checkValid("cod_postal", "Please fill in your Postcode.", "required");
					msg += checkValid("nr_tel", "Please specify your phone number.", "required");
					break;
		
	}
	if (msg!="") {
		alert(msg_alert+msg);
		return false;
	}
	return true;
}
