function setVisibility(objectID, state) {
	var object = document.getElementById(objectID);
	object.style.visibility = state;
}

function openWindow(URL, windowName, windowFeatures) {
	newWindow = window.open(URL, windowName, windowFeatures) 	
}

/* 	FUNCTIONS FOR GET EMAIL WITH CASE STUDY 	*/
function initForms() {
	for (var i=0; i< document.forms.length; i++) {
		document.forms[i].onsubmit = function() {return validForm();}
	}
}

function validForm() {
	var allGood = true;
	var allTags = document.csform.getElementsByTagName("*");

	for (var i=0; i<allTags.length; i++) {
		if (!validTag(allTags[i])) {
			allGood = false;
		}
	}
	return allGood;

	function validTag(thisTag) {
		var outClass = "";
		var allClasses = thisTag.className.split(" ");
	
		for (var j=0; j<allClasses.length; j++) {
			outClass += validBasedOnClass(allClasses[j]) + " ";
		}
	
		thisTag.className = outClass;
	
		if (outClass.indexOf("invalid") > -1) {
			invalidLabel(thisTag.parentNode);
			thisTag.focus();
			if (thisTag.nodeName == "INPUT") {
				thisTag.select();
			}
			return false;
		}
		return true;
		
		function validBasedOnClass(thisClass) {
			var classBack = "";
		
			switch(thisClass) {
				case "":
				case "invalid":
					break;
				case "reqd":
					if (allGood && thisTag.value == "") {
						classBack = "invalid ";
					}
					classBack += thisClass;
					break;
				case "radio":				
				case "email":
					if (allGood && !validEmail(thisTag.value)) {
						classBack = "invalid ";
					}
					classBack += thisClass;
					break;
					
			}
			return classBack;
		}
		
		function validEmail(email) {
			var invalidChars = " /:,;";
		
			if (email == "") {
				return false;
			}
			for (var k=0; k<invalidChars.length; k++) {
				var badChar = invalidChars.charAt(k);
				if (email.indexOf(badChar) > -1) {
					return false;
				}
			}
			var atPos = email.indexOf("@",1);
			if (atPos == -1) {
				return false;
			}
			if (email.indexOf("@",atPos+1) != -1) {
				return false;
			}
			var periodPos = email.indexOf(".",atPos);
			if (periodPos == -1) {	
				return false;
			}
			if (periodPos+3 > email.length)	{
				return false;
			}
			return true;
		}
				
	
		
		function invalidLabel(parentTag) {
			if (parentTag.nodeName == "LABEL") {
				parentTag.className += " invalid";
			}
		}
	}
}

window.onload = enterClient;

/* THIS IS THE JAVASCRIPT FUNCTION THAT COMPARES WHAT A USER TYPES IN ON THE
CLIENT LOGIN/ENTRY PAGE AGAINST POSSIBLE VALID ENTRIES  */

function clickHandler() {
	var companyname = document.clientEntry.compname.value; 
	switch(companyname) {
	/* duplicate contents below from 'case "amcap": up to and including "break;" (first "break" that goes with amcap group of code), 
		Place duplicate code where indicated below.
		In the duplicate version replace the possible valid entries you think the client might type for their name (any amount). (replace amcap, am cap, etc.)
		Then replace the folder name (americancapital) in the line: document.location.href = "http://www.wayfindersf.com/americancapital";
		with whatever the password protected folder for the client. 
		Be sure to save this scripts.js file and upload it to the live site. 
	*/	
	
			
	//COPY FROM THE NEXT LINE...	
		case "amcap":
		case "am cap":
		case "american capital":
		case "ACAS":
		case "am capital":
		case "Am capital":
		case "Am Capital":
			document.location.href = "http://www.wayfindersf.com/americancapital";
			return false;
			break;
	//...TO THE LINE ABOVE and paste where indicated below		
			
			
	//duplicated and edited code for other clients goes right after this line 
	
	
		case "UBOC BOOMER":
		case "uboc boomer":
		case "UBOC Boomer":
		case "Boomer":
		case "boomer":

			document.location.href = "http://www.wayfindersf.com/UBOC_boomertrad";
			return false;
			break;
			
		case "UBOC FAMILY":
		case "uboc family":
		case "Family":
		case "family":

			document.location.href = "http://www.wayfindersf.com/UBOC_family";
			return false;
			break;	
		
		
		case "neopost":
		case "Neopost":
		case "neo post":
		case "Neo post":
		case "NEOPOST":
			document.location.href = "http://www.wayfindersf.com/neopost";
			return false;
			break;
			
	//DIGITAL CATALOG, NON-PASSWORD PROTECTED	
	/*	case "American Capital":
		case "americancapital":
			document.location.href = "http://www.wayfindersf.com/AmericanCapital_digitalcatalog/";
			return false;
			break;	
			
		case "Studio Velo":
		case "StudioVelo":
		case "STUDIO VELO":
			document.location.href = "http://www.wayfindersf.com/Studio_Velo_digitalcatalog/";
			return false;
			break;		
			
		case "Irwin":
		case "Irwin Home Equity":
		case "irwinhomeequity":
			document.location.href = "http://www.wayfindersf.com/Irwin_digitalcatalog/";
			return false;
			break;		
			
		case "MindJet":
		case "Mindjet":
		case "Mind Jet":
		case "mindjet": 
			document.location.href = "http://www.wayfindersf.com/Mindjet_digitalcatalog/";
			return false;
			break;	
			
		case "Presto":
		case "presto":
			document.location.href = "http://www.wayfindersf.com/Presto_digitalcatalog/";
			return false;
			break;	
			
		case "Union Bank Catalog":
			document.location.href = "http://www.wayfindersf.com/UnionBank_digitalcatalog/";
			return false;
			break;		*/		
			
		default:
			alert("Please enter a valid company name");	
			return false;

			
	}
}