/* script for popup window */

function showPopup( width, height, file) {
	x = (640 - width)/2, y = (480 - height)/2;

	if (screen) {
	y = (screen.availHeight - height)/2;
	x = (screen.availWidth - width)/2;
	}
	if (screen.availWidth > 1800) {
	x = ((screen.availWidth/2) - width)/2;
	}

   	var newWindow =

	window.open(file,'','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,status=no');

}





function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

function compare(a, b) {
	// I didn't really need this, but it's a good function for sorting in numerical order and removing duplicates
	// psudeo code.
	if (a < b) {
		return -1;
	}
	if (a > b) {
		return 1;
	}
	if (a == b) {
		return 0;
	}
}	

function setTheHighlights() {
	if (Get_Cookie("categorySelection")) {
		forcedSelection = Get_Cookie("categorySelection");
		document.categories.selection.value = forcedSelection;
		highlight();
	}	
	
}	

function change(id, newClass) {
	identity = document.getElementById(id);
	identity.className = newClass;
}



// this is for validating the articles form

/* script for form validation */

var invalidaddress = new Array();
invalidaddress[0] = "shaw";
invalidaddress[1] = "telus";
invalidaddress[2] = "yahoo";
invalidaddress[3] = "hotmail";
invalidaddress[4] = "bluebottle";
invalidaddress[5] = "lycos";
invalidaddress[6] = "canada";
invalidaddress[7] = "excite";
invalidaddress[8] = "fastmail";
invalidaddress[9] = "looksmart";
invalidaddress[10] = "mymail";
invalidaddress[11] = "gmail";
//extend or shorten this list if neccessary

var testresults;


function validate() {
	if(document.signup.name.value == ""){
		alert("Please fill in your name in the name field.");
		document.signup.name.focus();
		return false;
	}	

	else if(document.signup.company.value == ""){
		alert("Please fill in your company name in the company field.");
		document.signup.company.focus();
		return false;
	}
	
	else if(document.signup.email.value == ""){
		alert("Please fill in your E-mail address.");
		document.signup.email.focus();
		return false;
	}
	
	else if(document.signup.email.value != document.signup.confirm.value){
		alert("E-mail addresses don't match.");
		document.signup.confirm.focus();
		return false;
	}
	
	var emailID = document.signup.email;
		
	if (checkemail(emailID.value) == false) {
		emailID.value= "";
		emailID.focus();
		return false;
	}

	else {
		return true;
	}
}

function checkemail(str) {
	var invalidcheck = 0;	
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)) {
		var tempstring = str.split("@");
		tempstring = tempstring[1].split(".");
		for (i=0;i<invalidaddress.length;i++) {
			if (tempstring[0]==invalidaddress[i]) {
				invalidcheck = 1;
			}
		}
		if (invalidcheck!=1) {
			testresults=true;
		}
		else {
			alert("Please input a more official email address!");
			testresults = false;
		}
	}
	else {
		alert("Please input a valid email address!");
		testresults = false;
	}
	return (testresults);
}