// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    //form validation
function valButton1(btn) {
	var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function validateform() {
    valid = true;
	errormsg = "Please complete the following fields: \n";
	var formName = validateform.arguments[0];
	for(i=1; i < validateform.arguments.length; i=i+2) {
    	var fieldName = validateform.arguments[i];
		var displayName = validateform.arguments[i+1];
		//alert (eval("document."+formName+"."+fieldName+".type"));
		if ((eval("document."+formName+"."+fieldName+".type") == "text") || (eval("document."+formName+"."+fieldName+".type") == "select-one")) {
			if (eval("document."+formName+"."+fieldName+".value") == "") {
				valid = false;
				errormsg += displayName + "\n";
			}
			
			//Check to ensure a valid email address has been entered
			if (fieldName == "email") {
				var emailFilter = /^.+@.+\..{2,3}$/;
				var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
				emailAddress = eval("document."+formName+"."+fieldName+".value");
				if (!(emailFilter.test(emailAddress))) { 
					valid = false;
					errormsg += "Please Enter a Valid Email Address\n";
				}
				if (emailAddress.match(illegalChars)) {
					valid = false;
					errormsg += "Please Check your email address, it contains illegal characters.\n";
				}
			}
			//Check for valid second email address matches first email address
			if (fieldName == "email2") {
				emailAddress2 = eval("document."+formName+"."+fieldName+".value");
				if (!(emailAddress2 == emailAddress)) { 
					valid = false;
					errormsg += "Please ensure your confirmation email address matches your email address.\n";
				}
			}
		} else {
			var btn = valButton1(eval("document."+formName+"."+fieldName+""));
			if (btn == null) {
				valid = false;
				errormsg += displayName + "\n";
			} else {
				//alert('Button value ' + btn + ' selected'); 
			}
		}
	}
	
	// Custom Dependant Fields
	if (eval("document."+formName+".client.checked")) {
		var btn = valButton1(eval("document."+formName+".yes"));
		if (btn == null) {
			valid = false;
			errormsg += "Are you a client\n";
		}
		var btn = valButton1(eval("document."+formName+".no"));
		if (btn == null) {
			valid = false;
			errormsg += "Are you a client\n";
		}
	}
	
	


	// End Custom Dependant
	if (valid == false) {
		alert(errormsg);
	}
    	return valid;
}


///End Validation
//----------------------------------------------------------------------//
///Start Collapsable div
animatedcollapse.addDiv('broadband', 'fade=1,height=1050px')
animatedcollapse.addDiv('wireless', 'fade=1,height=1640px')
animatedcollapse.addDiv('terms', 'fade=1,height=12750px')
animatedcollapse.addDiv('e911', 'fade=1,height=720px')
animatedcollapse.addDiv('privacy', 'fade=1,height=2899px')
animatedcollapse.addDiv('warranty', 'fade=1,height=650px')
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
	//$: Access to jQuery
	//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
	//state: "block" or "none", depending on state
}
animatedcollapse.init()
animatedcollapse.addDiv('jason', 'optional_attribute_string')
//additional addDiv() call...
//additional addDiv() call...
animatedcollapse.init()
//Tabs
$(document).ready(function () {
	$('#menuTab').tabify();
});


