	function GetCookie (name) {
		// used to get the contents of a cookie
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)	return getCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0)	break;
		}
	   return null;

		function getCookieVal(offset) {
			// supporting function
			var endstr = document.cookie.indexOf (";", offset);
			if (endstr == -1)
			endstr = document.cookie.length;
			return unescape(document.cookie.substring(offset, endstr));
		}

	}
	
	function SetCookie (name, value, exp, dmn) {
		// used to save a cookie
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var expires = exp;
		var domain = dmn;
		document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() + "; domain=" + domain;
	}
	
	function saveSignup(){
		// this marks the current computer browser as signed up
		var expDays = 60;
		var expire = new Date(); 
		expire.setTime(expire.getTime() + (expDays+24*60*60*1000));
		SetCookie('Signup', 'Yes', expire, '.powercore.com');
		window.opener.gotoLastLink();
	}
	
	function deleteSignup(){
		// this deletes the current computer browser's signed up cookie
		var expDays = 60;
		var expire = new Date(); 
		expire.setTime(expire.getTime() + (expDays-24*60*60*1000));
		SetCookie('Signup', 'Yes', expire, '.powercore.com')
		window.opener.gotoLastLink();
	}


	function popupSmall(pageURL){
		// this function creates a popup to a given url
		thewindow = window.open(pageURL, "_popup", config='toolbar=no, height=350, width=700, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=yes');
	}

	function popupFull(pageURL){
		// this function creates a popup to a given url
		thewindow = window.open(pageURL, "_blank", config='toolbar=yes, height=600, width=800, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, directories=no, status=yes');
	}

	function checkSignup(obj){
		// this is used by the download link to 
		// insure signup has taken place
		
		saveLastLink(obj);
		
		if(GetCookie('Signup') == 'Yes'){
			return true;
		}
		else{
			popupSmall('downloadForm.htm');
			return false;
		}
	}

	function email_check(str) {
		// verifies a proper email address is used
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
			return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
			return false
		 }
		 if (str.indexOf(" ")!=-1){
			return false
		 }
		 return true					
	}

	var lastLinkClicked; // needs to be available to multiple functions
	function saveLastLink(obj){
		// this saves the last link for later use
		lastLinkClicked = obj;
	}
	
	function gotoLastLink(){
		// this creates a popup to the last link
		popupFull(lastLinkClicked.toString());
	}
	
	
	function checkDownloadForm(formObj){
		// this verifies the required fields are filled in

		var isError = false;
		var errorMsg = '';
		if(formObj.Name.value == ''){
			isError = true;
			errorMsg += "\nYour name must be included.";
		}

		if(formObj.Phone.value == ''){
			isError = true;
			errorMsg += "\nYour phone number must be included.";
		}

		if(formObj.Email.value == ''){
			isError = true;
			errorMsg += "\nYour email address must be included.";
		}
		else if(email_check(formObj.Email.value) == false){
			isError = true;
			errorMsg += "\nYour email address is invalid.";
		}
		
		if(isError == true){
			alert(errorMsg);
			return false;
		}
		
		saveSignup();
		return true;
	}
	
	window.focus();