function isEmail (s) {
	if (isEmpty(s)) 
		if (isEmail.arguments.length == 1) return false;
		else return (isEmail.arguments[1] == true);

	if (isWhitespace(s)) return false;

	var i = 1;
	var sLength = s.length;

	while ((i < sLength) && (s.charAt(i) != "@")) {
		i++
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	while ((i < sLength) && (s.charAt(i) != ".")) {
		i++
	}

	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}

var whitespace = " \t\n\r";
function isWhitespace (s) {
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

function tellFriend(act){
	if (document.FTELL.my_name.value.length <=0){
		alert("Please enter your name");
		document.FTELL.my_name.focus();
		return;
	}
	if (document.FTELL.my_email.value.length <=0){
		alert("Please enter your email");
		document.FTELL.my_email.focus();
		return;
	}
	if (!validateEmailAddress(document.FTELL.my_email.value)){
		alert("Please enter your valid email address");
		document.FTELL.my_email.focus();
		return;
	}
	if (document.FTELL.friend_name.value.length <=0){
		alert("Please enter friend name");
		document.FTELL.friend_name.focus();
		return;
	}
	if (document.FTELL.friend_email.value.length <=0){
		alert("Please enter friend email");
		document.FTELL.friend_email.focus();
		return;
	}
	if (!validateEmailAddress(document.FTELL.friend_email.value)){
		alert("Please enter your friend valid email address");
		document.FTELL.friend_email.focus();
		return;
	}
	win_tell_friend = window.open("", "win_tell_friend", "left=100, top=100, width=247, height=171, resizable=0");
	document.FTELL.TELLACT.value=1;
	document.FTELL.action= act;
	document.FTELL.target = "win_tell_friend";
	document.FTELL.submit();
	document.FTELL.my_name.value="";
	document.FTELL.my_email.value="";
	document.FTELL.friend_name.value="";
	document.FTELL.friend_email.value="";
}

function validateEmailAddress(email){
	return email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)!=null;
}

function openVisitPath(url){
	visit = window.open(url, "visit", "width=600, height=400, resizable=0, scrollbars=yes, left=50, top=50");
}

function openWindow(){
	window.open("color_chart_picker.html","cccc",'width=552, height=612, left=100, top=100, resizable=0');
}

function contact_us(){
	if (document.FCONTACT.FIRSTNAME.value.length <=0){
		alert("Please enter your first name!");
		document.FCONTACT.FIRSTNAME.focus();
		return;
	}
	if (document.FCONTACT.LASTNAME.value.length <=0){
		alert("Please enter your last name!");
		document.FCONTACT.LASTNAME.focus();
		return;
	}
	if (document.FCONTACT.EMAIL.value.length <=0){
		alert("Please enter your email address!");
		document.FCONTACT.EMAIL.focus();
		return;
	}
	if (document.FCONTACT.PHONE.value.length <=0){
		alert("Please enter your phone!");
		document.FCONTACT.PHONE.focus();
		return;
	}
	if (document.FCONTACT.COMPANY.value.length <=0){
		alert("Please enter your company name!");
		document.FCONTACT.COMPANY.focus();
		return;
	}
	if (document.FCONTACT.MESSAGE.value.length <=0){
		alert("Please enter your message!");
		document.FCONTACT.MESSAGE.focus();
		return;
	}
	document.FCONTACT.action = "contact_us.php";
	document.FCONTACT.submit();
}

function showTrackInfo(id){
	if (typeof id == "undefined") {
		document.all['TRACKINFO'].style.visibility = "visible";
		document.all['IPINFO'].style.visibility = "hidden";
	} else {
		document.all['TRACKINFO'+id].style.visibility = "visible";
		document.all['IPINFO'+id].style.visibility = "hidden";
	}
}

function showIPInfo(id){
	if (typeof id == "undefined") {
		document.all['IPINFO'].style.visibility = "visible";
		document.all['TRACKINFO'].style.visibility = "hidden";
	} else {
		document.all['IPINFO'+id].style.visibility = "visible";
		document.all['TRACKINFO'+id].style.visibility = "hidden";
	}
}

function isValidUsername(str){
	var toRet = true;
	
	if ( str.length < 5 ) return false;

	for(var i=0; i< str.length; i++){
		var x = str.charCodeAt(i);
		if (    !( x >= 65 && x <= 90 )
			 && !( x >= 97 && x <= 122 )
			 && !( x >= 48 && x <= 57 )
		) {
			return false;
		} else {
			
		}
	}
	return toRet;
}


function popupAlert(message){
	alert(message);
//	var paw = window.open("alert.php?msg=" +message+ "", "AlertPopup", "width=300; height=100; left=200; top=200; resizable=1; scrollbars=1;");
/*
	var paw = window.open("", "AlertPopup", "width=300; height=300; left=0; top=0;");
	paw.document.open();
	paw.document.writeln("<IMG SRC='images/alert.gif' ALIGN=ABSMIDDLE BORDER=0 >" + message +"");
	paw.document.close();
*/
}
	
