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;
}

//var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function getCheckAction(formName, formAction, fieldGet, fieldSet, fieldAction, debug){
//	alert( formName + "\n" + formAction + "\n" + fieldGet + "\n" + fieldSet + "\n" + fieldAction+ "\n");
	var s = "0";
	var x =0;
	for(var i =0 ; i < eval("document."+formName+".elements.length"); i++) {

		if (debug==true) alert( eval("document."+formName+".elements[" + i + "].name") + " : " + eval("document."+formName+".elements[" + i + "].value") + " : " + eval("document."+formName+".elements[" + i + "].checked") );

		if (   eval("document."+formName+".elements[" + i + "].name") == fieldGet 
			&& eval("document."+formName+".elements[" + i + "].checked") ) {
			if (debug==true) alert(eval("document."+formName+".elements[" + i + "].name") + " : " + eval("document."+formName+".elements[" + i + "].value"));
			s += "," + "" + eval("document."+formName+".elements[" + i + "].value") + "";
			x = 1;
		}
	}
	if (x == 0 ) return;
	eval("document."+formName+"." + fieldSet + ".value = '" + s + "'" );
	if ( fieldAction.length > 0 ) eval("document."+formName+"." + fieldAction + ".value = 1");
	eval("document."+formName+".action = '" + formAction + "'");

	if (debug==true) alert( "set value = " + eval("document."+formName+"." + fieldSet + ".value") );

	eval("document."+formName+".submit()");
}

function gotoPage(s, formAction, existGet){
	if (!existGet ) document.F.action = eval("'" + formAction + "?page="+s + "'");
	else document.F.action = eval("'" + formAction + "&page="+s + "'");
//	alert(document.F.action);
	document.location.href = document.F.action;
	return;
	document.F.submit();
}

function login(act){
	if (document.FLOGIN.username.value.length == 0 ) {
		alert("Please enter username!");
		document.FLOGIN.username.focus();
		return;
	}
	document.FLOGIN.action= act;
	document.FLOGIN.submit();
}

function mailing_list(act){
//	alert("mailing list");
	if (document.FMAILING.email.value.length == 0 ){
		alert("Please enter email address");
		document.FMAILING.email.focus();
		return;
	}
	if (!validateEmailAddress(document.FMAILING.email.value)){
		alert("Please enter a valid email address");
		document.FMAILING.email.focus();
		return;
	}
	document.FMAILING.MAILINGACT.value = 1;
	document.FMAILING.action = "mailing_list.php";
//	alert(document.FMAILING.action);
	document.FMAILING.submit();
}

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 payment(){
	if (document.FPAY.x_card_num.value.length <=0){
		alert("Please enter your card number!");
		document.FPAY.x_card_num.focus();
		return;
	}
	if (document.FPAY.x_exp_date.value.length <=0){
		alert("Please enter your card expiration date!");
		document.FPAY.x_exp_date.focus();
		return;
	}
	if (document.FPAY.x_first_name.value.length <=0){
		alert("Please enter your first name!");
		document.FPAY.x_first_name.focus();
		return;
	}
	if (document.FPAY.x_last_name.value.length <=0){
		alert("Please enter your last name!");
		document.FPAY.x_last_name.focus();
		return;
	}
	if (document.FPAY.x_address.value.length <=0){
		alert("Please enter your address!");
		document.FPAY.x_address.focus();
		return;
	}
	if (document.FPAY.x_city.value.length <=0){
		alert("Please enter your city!");
		document.FPAY.x_city.focus();
		return;
	}
	if (document.FPAY.x_zip.value.length <=0){
		alert("Please enter your zip code!");
		document.FPAY.x_zip.focus();
		return;
	}
	if (document.FPAY.x_email.value.length <=0){
		alert("Please enter your email address!");
		document.FPAY.x_email.focus();
		return;
	}

	document.FPAY.target = "_blank";
	document.FPAY.method = "GET";
	document.FPAY.action = "https://secure.authorize.net/gateway/transact.dll";
	document.FPAY.submit();
}

function filterAction(selectObj, pid, rid, page, showperpage, start_date, end_date){
//	alert(document.F.FILTERACTION.options.selectedIndex);
	var aid = document.F.FILTERACTION.options[document.F.FILTERACTION.options.selectedIndex].value;
//	alert(aid);
	var addr = "reports.php?pid="+pid
		+"&rid="+rid
		+"&page="+page
		+"&showperpage="+showperpage
		+"&start_date="+start_date
		+"&end_date="+end_date
		+"&aid="+aid;
//	alert(addr);
	document.location.href = addr;
}

function showBaseInfo(id){
	if (typeof id == "undefined") {
		document.all['BASEINFO'].style.visibility = "visible";
		document.all['EXTRAINFO'].style.visibility = "hidden";
	} else {
		document.all['BASEINFO'+id].style.visibility = "visible";
		document.all['EXTRAINFO'+id].style.visibility = "hidden";
	}
}

function showExtraInfo(id){
	if (typeof id == "undefined") {
		document.all['EXTRAINFO'].style.visibility = "visible";
		document.all['BASEINFO'].style.visibility = "hidden";
	} else {
		document.all['EXTRAINFO'+id].style.visibility = "visible";
		document.all['BASEINFO'+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;
}

/*Credit JavaScript Kit www.javascriptkit.com*/
var dragapproved=false
var z,x,y
function move(){
	if (event.button==1&&dragapproved){
		z.style.pixelLeft=temp1+event.clientX-x
		z.style.pixelTop=temp2+event.clientY-y
		return false
	}
}

function drags(){
	if (!document.all)
		return
	if (event.srcElement.className=="drag"){
		dragapproved=true
		z=event.srcElement
		temp1=z.style.pixelLeft
		temp2=z.style.pixelTop
		x=event.clientX
		y=event.clientY
		document.onmousemove=move
	}
}
