
function easy_CheckRequired(form,Action,formaction,formtarget,req1,req2,req3,req4,req5,req6,req7,req8,req9,req10,req11,req12,req13,req14,req15,req16,req17,req18,req19,req20,req21,req22,req23,req24,req25,req26,req27,req28,req29,req30,req31,req32,req33,req34,req35,req36,req37,req38,req39,req40){
	
	if (formtarget && formtarget!='')
	{
		document.forms[form].target=formtarget;				
	}
	if (formaction && formaction!='')
	{
		document.forms[form].action=formaction;						
	}
	
	var reqFieldsCaption="";
	var noOfParams=40;
	var i=0;
	var r=0;	
	var noOfRequired=0;
	
	// Pre-count required
	while (i < noOfParams)
    {
      i++;
	  if (eval("req"+i))
	  {		  
		  reqField=eval("req"+i);
		  if (eval("document.forms[form]."+reqField+".value")=='') 
		  {
			noOfRequired++;			
		  }
	  }   
    }
	
	var i=0;	
	
	while (i < noOfParams)
    {
      i++;
	  if (eval("req"+i))
	  {		  	  	 
		  reqField=eval("req"+i);
		  if (eval("document.forms[form]."+reqField+".value")=='')
		  {			  	
			r++;
			reqFieldCaption=eval("document.forms[form]."+reqField+"_caption.value");	
			if (r==noOfRequired && noOfRequired!=1) reqFieldsCaption=reqFieldsCaption+' and ';		
		  	reqFieldsCaption=reqFieldsCaption+' \"'+reqFieldCaption+'\"';			
		  }		 
		  if (eval("req"+i) && i<noOfRequired-1 && r>0) reqFieldsCaption=reqFieldsCaption+", ";
	  }   
    }
	
	if (reqFieldsCaption=='')
	{		
		if (
				    (document.forms[form].password && document.forms[form].password_confirm)
				&& !(document.forms[form].password.value == document.forms[form].password_confirm.value)
		   )
		{				
			alert("The two passwords you have entered do not match. Please try again.");			
		}
		else if (document.forms[form].email_isemail && !isValidEmail(document.forms[form].email.value))
		{			
			alert("The email address you have entered is invalid. Please try again.");	
		}
		else
		{			
			document.forms[form].status.value=Action;					
			document.forms[form].submit();		
		}
	}		
	else
	{
		if (r>1) 
		{
			plural="s";
			isAre="are";	
		}
		else
		{
			plural="";
			isAre="is";	
		}
		alert("Field"+plural+' '+reqFieldsCaption+" "+isAre+" required");			
	}	
}

function allValidChars(email) {
  var parsed = true;			
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";			
  for (var i=0; i < email.length; i++) {			
    var letter = email.charAt(i).toLowerCase();			
    if (validchars.indexOf(letter) != -1)			
      continue;			
    parsed = false;			
    break;			
  }			
  return parsed;			
}			 

function isValidEmail(email, required) {			
    if (required==undefined) {   // if not specified, assume it's required			
        required=true;			
    }			
    if (email==null) {			
        if (required) {			
            return false;			
        }			
        return true;			
    }			
    if (email.length==0) {  			
        if (required) {			
            return false;			
        }			
        return true;			
    }			
    if (! allValidChars(email)) {  // check to make sure all characters are valid			
        return false;			
    }			
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character			
        return false;			
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @			
        return false;			
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character			
        return false;			
    }		
    return true;			
}

// OPENS A POPUP RESIZED ACCORDING TO IMAGE SIZE
function imagePopup(path)
{
  if (path)
  {
	  TopDistance = (screen.height/2)-200;
	  LeftDistance = (screen.width/2)-20;
	
	  HTML = "<html><style>body{margin:0px 0px 0px 0px}</style><body onBlur='top.close()'><img src='"+path+"' border=0 name=load_image onLoad='window.resizeTo(document.load_image.width+10,document.load_image.height+30)'></body></html>";
	  popupImage = window.open('','_blank','left='+LeftDistance+',top='+TopDistance+',width=0,height=0,toolbar=no,scrollbars=no');
	  popupImage.document.open();
	  popupImage.document.write(HTML);
	  popupImage.document.close();
  }
  else
  {
  	alert("No Image Defined.");
  }
}


/* CHECKBOXES */
 function checkAll(form, fieldname) {
 	 myStatus=eval("document.forms[form]."+fieldname+"_all.checked")
 
 if (myStatus==0)
 {
   	for (var i=0;i<document.forms[form].elements.length;i++) {
		var e=document.forms[form].elements[i];
		if (e.name == fieldname) {
           e.checked=0;
   	    }		
	}
 }
 else
 {
	 for (var i=0;i<document.forms[form].elements.length;i++) {
		var e=document.forms[form].elements[i];
		if (e.name == fieldname) {
           e.checked=1;
   	    }		
	}
 }
 }


function doNothing() {}

