var d = document;

function FcheckForm(f){
	
	//------------------------------------------------------------------------
	// Whenever you add a line, the appropriate field will be checked when 
	// pressing the SUBMIT button
	//------------------------------------------------------------------------
	
	// Most functions need 2 parameters: 
	// Fieldname (eg Name) and html-reference (f.name.value)
	//
	// Other functions for textarea, multiple selectboxes and checkboxes
	// require 3 or 4 parameters:
	// Fieldname, html-reference, min value, max value
	//
	// Function:
	// FcheckFilled       : checks if a fiels is filled
	// FcheckMinLength    : checks if the given amount or more characters are filled in
	// FcheckMaxLength    : checks if the filled in chars do not succeed the given amount of chars
	// FcheckNumber       : checks if teh filled in chars are numeric
	// FcheckEmail        : email validation
	// FcheckDropOne      : checks if a value in a selectbox is selected
	// FcheckRadio        : checks if on of the checkboxes is selected
	// FcheckDropMultiple : checks if a given amount of selections in a multiple selectbox are selected
	// FcheckChars        : checks the amount of typed chars do not succeed the given amount 

		
	
	//if(!FcheckFilled('שם פרטי',f.dbTxt_FirstName.value)){ f.dbTxt_FirstName.focus();return false; }
	//if(!FcheckFilled('שם משפחה',f.dbTxt_Last_Name.value)){ f.dbTxt_Last_Name.focus();return false; }
	if(!FcheckFilled('דואר אלקטרוני',f.email.value)){ f.email.focus();return false; }
	if(!FcheckEmail('דואר אלקטרוני אינו במבנה תקין',f.email.value)){ f.email.focus();return false; }
	
	return true;
}

//------------------------------------------------------------------------
//  Everything below this should not be changed, unless you want to use
//  this script for another language. then change text between "" in all
//  functions you are going to use.
//------------------------------------------------------------------------
function Fconfirm(){
	var agree=confirm("All data is filled incorrect!\nSend now?");
	if (agree)
		return true ;
	else
		return false ;
}

function FcheckFilled(n,v){ 
	if(v==""){ alert(" יש לציין " +n);return false; }
	else { return true; }
}

function FcheckMinLength(n,v,num){ 
	if(v.length<num){ alert("Min. chars for "+n+" is "+num+"!");return false; }
	else { return true; }
}

function FcheckMaxLength(n,v,num){ 
	if(v.length>num){ alert("Max. chars for "+n+" is "+num+"!");return false; }
	else { return true; }
}

function FcheckNumber(n,v){
	if((isNaN(v))||(v=="")){ alert("יש לציין " +n);return false; }
	else { return true; }
}

function FcheckChars(n,v,num){ 
	if(v.length>num){ alert( num+ " Maximum\n"+(v.length-num)+" unnecessary characters");return false; }
	else { return true; }
}

function FcheckEmail(n,v){
	var a=0
	var p=0
	for(var i=1;i<v.length;i++){
		if(!v.charAt(i))return false
		else if(v.charAt(i)=='@'){a++;if(v.charAt(i+1)==''){ alert(n+ " ");return false; }}
		else if(v.charAt(i)=='.'){p++;if(v.charAt(i+1)==''||v.charAt(i+1)=='@'||v.charAt(i-1)=='@'){ alert(n+ " incorrect");return false; }}
	}
	if(a==1&&p){ return true; }
	else { alert(" " +n);return false; }
}

function FcheckRadio(n,v){
	var r = false;
	var i;
	for (i = 0;  i < v.length;  i++){
    if (v[i].checked)
        r = true;
  }  
	if (!r){ alert("Select a value for "+n+"!");return (false); }
	else { return true; }
}

function FcheckDropOne(n,v){
	if(v.selectedIndex<=0){ alert("required selection "+n);return false; }
	else { return true; }
}

function FcheckDropMultiple(n,v,mi,ma){
	var sel = 0;
  var i;
  for (i = 0;  i < v.length;  i++){ if (v.options[i].selected) sel++; }
	
	if(mi>0){
		if (sel < mi) { alert("Min "+mi+" items for "+n+"!");return false; }
	}
	if(ma>0){
  	if (sel > ma) { alert("Max. "+ma+" items for "+n+"!");return false; }
	}
 	return true;
}

function FcheckBoxes(n,v,mi,ma){
  var sel = false;
	var i;
  for (i = 0;  i < v.length;  i++){ if (v[i].checked) sel++; }
	
	if(mi>0){
		if (sel < mi) { alert("Min "+mi+" items for "+n+"!");return false; }
	}
	if(ma>0){
  	if (sel > ma) { alert("Max. "+ma+" items for "+n+"!");return false; }
	}
 	return true;
}

