/*
-------------------------------------------------
Ecellar common javascript file.
common functions used across the website.
-------------------------------------------------

-emailcheck(cur)
-IsFormComplete(FormName)
-MM_openBrWindow(theURL,winName,features)
-checkPass(field1,field2,minChars)
-radioCheck(radioarray)

*/


function emailcheck(cur)
	//loose email check
	{
	var string1 = cur.txtEmail.value
	if (string1.indexOf("@")==-1)
	{
	alert("Please enter a valid email address")
	return false
	}
	}
	
function IsFormComplete(FormName,aFields)
	//checks for blank form fields
	{
	var x       = 0
	var FormOk  = true
	var match = false
		
	while ((x < document.forms[FormName].elements.length) && (FormOk))
	   {
	   	//if its not blank or selected index is not '0'	   		
	     if ((document.forms[FormName].elements[x].value == '')||(document.forms[FormName].elements[x].value == '0'))
				     { 
					
					
					 
					 //array of fields that should be ignored
					for (var loop = 0; loop < aFields.length; loop++)
					{
 										 
					//alert(aFields[loop]);
					//alert(document.forms[FormName].elements[x].name);
					
					if(document.forms[FormName].elements[x].name == aFields[loop])	
						{
						//alert("they match");
						match = true;
						//found a match get out of loop
						loop = aFields.length;		 
					 	}
					else
						{
						match = false;
						}
					
					}
					 	 
									
					//alert(match);	 
					 
					 //make sure hidden fields are allowed through
					 if ((document.forms[FormName].elements[x].type != 'hidden') && (match==false))
					 	{
					 	
				        alert('Please enter all of the required fields and try again.')
				  		//place focus on offending field
						document.forms[FormName].elements[x].focus()
				      
					    FormOk = false 
				     	}
					 
					 
					
					 
					 }
	     x ++
	   }
	return FormOk
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  //Dreamweaver window opener
  window.open(theURL,winName,features);
}

function checkPass(field1,field2,minChars){
	//checks two password fields and min length of pass
	if (field1.value.length < minChars || field2.value.length < minChars ) 
		{
		alert("Your password must be at least "+ minChars +" charters");
		return false;
	   	}
	
	else if (field1.value!=field2.value)
		{
		alert("The two passwords do not match")
		return false;
		}
		
	else return true;
}

function radioCheck(radioarray)
		//checks if a group of radios have a selected value
		{ 
		if (isArray(radioarray))
		{
		
			for(i=0; i<radioarray.length; i++)
				{ 
			if(radioarray[i].checked) 
			//return radioarray[i].value; 
				return true;
				} 
				alert("Please make required address selections, and try again.");
				return false; 
				}
		else
		
			if(radioarray.checked)
				{
				return true;
								
				} 
				
				alert("Please make required address selections, and try again.");
				return false;
						
		}	
		
				
function dynamicSubmit(strFormName,strURL)
		//Dynamic submit
		{
		var objForm;
		objForm = document.forms[strFormName];
		objForm.action = strURL;
		objForm.method = "POST"
		objForm.submit();
		}

function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

