//::Highlight Form Items
var highlightcolor="#FFD99C"
var originalcolor="#F0F0F0"
var ns6=document.getElementById&&!document.all
var previous=''
var eventobj
var intended=/INPUT|TEXTAREA|SELECT|OPTION/
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true}
else
return false
}
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=originalcolor
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj}
}

//::Auto-centering Pop-Up Window
var win = null;
function CiPopWin(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+'';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Auto-centering Print Window
var win = null;
function CiPrintWin(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',menubar=no'+',resizable='+resize+'';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Auto-centering Print Window
var win = null;
function CiAdminWin(mypage){
iHeight = window.screen.availHeight-89;
iWidth = 650;
LeftPosition = (screen.width) ? (screen.width-iWidth)/2 : 0;
TopPosition = 0;
myname = "AdminWindow";
settings =
'height='+iHeight+',width='+iWidth+',top='+TopPosition+',left='+LeftPosition+',status=1,scrollbars=1,toolbar=1,menubar=0,location=0,resizable=0';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Print Pop-Up Window
var win = null;
function PrintWin(mypage,myname,w,h){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
settings =
'height='+h+',width='+w+',left='+LeftPosition+',top=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Top-Left Pop-Up Window
var win = null;
function CiTopLeftWin(mypage,myname,w,h,scroll,resize){
LeftPosition = 0;
TopPosition = 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+'';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Auto-centering Enlarged Pop-Up Window
var win = null;
function Enlarge(mypage){
w = 300;
h = 200;
myname = 'EnlargeWindow';
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Resize Window Dynamically
function resizeWin(maxX,maxY,speed,delay,win){
	this.obj = "resizeWin" + (resizeWin.count++);
	eval(this.obj + "=this");
	if (!win)     this.win = self;    else this.win = eval(win);
	if (!maxX)    this.maxX = 400;    else this.maxX = maxX;
	if (!maxY)    this.maxY = 300;    else this.maxY = maxY;
	if (!speed)   this.speed = 1/7;   else this.speed = 1/speed;
	if (!delay)   this.delay = 30;    else this.delay = delay;
	this.doResize = (document.all || document.getElementById);
	this.stayCentered = false;
	this.initWin = 	function(){
		if (this.doResize){
			this.resizeMe();
			}
		else {
			this.win.resizeTo(this.maxX + 10, this.maxY - 20);
			}
		}
	this.resizeMe = function(){
		this.win.focus();
		this.updateMe();
		}
	this.resizeTo = function(x,y){
		this.maxX = x;
		this.maxY = y;
		this.resizeMe();
		}
	this.stayCentered = function(){
		this.stayCentered = true;
		}
	this.updateMe = function(){
		this.resizing = true;
		var x = Math.ceil((this.maxX - this.getX()) * this.speed);
		var y = Math.ceil((this.maxY - this.getY()) * this.speed);
		if (x == 0 && this.getX() != this.maxX) {
			if (this.getX() > this.maxX) x = -1;
			else  x = 1;
			}
		if (y == 0 && this.getY() != this.maxY){
			if (this.getY() > this.maxY) y = -1;
			else y = 1;
			}
		if (x == 0 && y == 0) {
			this.resizing = false;
    		}
		else {
			this.win.top.resizeBy(parseInt(x),parseInt(y));
			if (this.stayCentered == true) this.win.moveTo((screen.width - this.getX()) / 2,(screen.height - this.getY()) / 2);
			setTimeout(this.obj + '.updateMe()',this.delay)
			}
		}
	this.write =  function(text){
		if (document.all && this.win.document.all["coords"]) this.win.document.all["coords"].innerHTML = text;
		else if (document.getElementById && this.win.document.getElementById("coords")) this.win.document.getElementById("coords").innerHTML = text;
		}
	this.getX =  function(){
		if (document.all) return (this.win.top.document.body.clientWidth + 10)
		else if (document.getElementById)
			return this.win.top.outerWidth;
		else return this.win.top.outerWidth - 12;
	}
	this.getY = function(){
		if (document.all) return (this.win.top.document.body.clientHeight + 29)
		else if (document.getElementById)
			return this.win.top.outerHeight;
		else return this.win.top.outerHeight - 31; 
	}
	this.onResize =  function(){
		if (this.doResize){
			if (!this.resizing) this.resizeMe();
			}
		}
	return this;
}
resizeWin.count = 0;

//::disable enter key function
function DisableEnterKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = DisableEnterKey;

//::Auto-Tab Form Field
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;
}

//::Copy Fields Function
function CopyFields(){
	var objForm = document.forms[0];
	if(objForm.copy.checked){
		objForm.s_firstname.value = objForm.b_firstname.value;
		objForm.s_lastname.value = objForm.b_lastname.value;
		objForm.s_companyname.value = objForm.b_companyname.value;
		objForm.s_address1.value = objForm.b_address1.value;
		objForm.s_address2.value = objForm.b_address2.value;
		objForm.s_city.value = objForm.b_city.value;
		objForm.s_state.value = objForm.b_state.value;
		objForm.s_country.value = objForm.b_country.value;
		objForm.s_zip.value = objForm.b_zip.value;
		objForm.s_phonearea.value = objForm.b_phonearea.value;
		objForm.s_phonepre.value = objForm.b_phonepre.value;
		objForm.s_phonesuf.value = objForm.b_phonesuf.value;
		objForm.s_faxarea.value = objForm.b_faxarea.value;
		objForm.s_faxpre.value = objForm.b_faxpre.value;
		objForm.s_faxsuf.value = objForm.b_faxsuf.value;
		objForm.s_email.value = objForm.b_email.value;
	}
	else{
		objForm.s_firstname.value = "";
		objForm.s_lastname.value = "";
		objForm.s_companyname.value = "";
		objForm.s_address1.value = "";
		objForm.s_address2.value = "";
		objForm.s_city.value = "";
		objForm.s_state.value = "";
		objForm.s_country.value = "";
		objForm.s_zip.value = "";
		objForm.s_phonearea.value = "";
		objForm.s_phonepre.value = "";
		objForm.s_phonesuf.value = "";
		objForm.s_faxarea.value = "";
		objForm.s_faxpre.value = "";
		objForm.s_faxsuf.value = "";
		objForm.s_email.value = "";
	}

	FocusFields();
}

//::Swap Payment Method Function
function PaymentMethodCheck(){
	var objForm = document.forms[0];
	switch (objForm.paymentmethod.value) {
		case "1": //Credit Card
			cc1.style.display='';
			cc2.style.display='';
			cc3.style.display='';
			cc4.style.display='';
			pp1.style.display='none';
			pp2.style.display='none';
			break;
		case "2": //PayPal
			cc1.style.display='none';
			cc2.style.display='none';
			cc3.style.display='none';
			cc4.style.display='none';
			pp1.style.display='';
			pp2.style.display='';
			break;
	}
}

//::Navigate using drop down menu
function MenuNavigate(page,id,level){
	document.location.href = page + "?catid=" + id + "&level=" + level;
}

//::Copy e-mail address for new registration
function CopyEmailAddress(){
	var objForm = document.forms[0];
	for(var i=0; i<document.forms[0].elements.length; i++){
		if(document.forms[0].elements[i].name== "registeremail"){
			objForm.registeremail.value = objForm.b_email.value;
		}
	}
	objForm.newaccountemail.value = objForm.b_email.value;
}

//::Copy new e-mail address for new registration
function CopyNewEmailAddress(){
	var objForm = document.forms[0];
	objForm.b_email.value = objForm.registeremail.value;
}

//::Hide/Show Payment Methods
function HidePaymentMethods(pType){
	switch (pType) {
		case "1": //::Credit Card
			//Credit Card
			CC1.style.display='';
			CC2.style.display='';
			CC3.style.display='';
			CC4.style.display='';

			//Check
			// ----------------------

			//Phone
			P1.style.display='none';
			P2.style.display='none';
			break;

		case "2": //::Check or Money Order
			//Credit Card
			CC1.style.display='none';
			CC2.style.display='none';
			CC3.style.display='none';
			CC4.style.display='none';
			
			//Check
			// ----------------------

			//Phone
			P1.style.display='none';
			P2.style.display='none';
			break;

		case "3": //::Phone
			//Credit Card
			CC1.style.display='none';
			CC2.style.display='none';
			CC3.style.display='none';
			CC4.style.display='none';
			
			//Check
			// ----------------------

			//Phone
			P1.style.display='';
			P2.style.display='';
			break;

		default:
			//Credit Card
			CC1.style.display='none';
			CC2.style.display='none';
			CC3.style.display='none';
			CC4.style.display='none';
			
			//Check
			// ----------------------

			//Phone
			P1.style.display='none';
			P2.style.display='none';
	}
}

//::Trim String Function
function Trim(str){
	str = str.replace(/^\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Focus All Form Fields
function FocusFields(intStart){
	var fcnt = document.forms[0].elements.length;

	if(intStart == null){
		intStart = 6;
	}

	for(i=intStart; i<fcnt;i++){
		window.onerror=ignore
		function ignore(){return true}
		document.forms[0].elements[i].focus();
	}
	return false;
}

//::Focus All Form Fields
function FocusFieldsCustomer(){
	var fcnt = document.forms[0].elements.length;

	for(i=4; i<fcnt;i++){
		window.onerror=ignore
		function ignore(){return true}
		document.forms[0].elements[i].focus();
	}

	document.forms[0].elements[5].focus();
	return false;
}

//::Pop-Up Calendar
function showCalendar(str_target, str_datetime) {
	var arr_months = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	var week_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
	var n_weekstart = 0; // day week starts from (normally 0 or 1)
	
	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt4(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	if (dt_datetime.getMonth()%12 != (dt_prev_month.getMonth()+1)%12) {
		dt_prev_month.setMonth(dt_datetime.getMonth());
		dt_prev_month.setDate(0);
	}
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	if ((dt_datetime.getMonth() + 1)%12 != dt_next_month.getMonth()%12)
		dt_next_month.setDate(0);
	
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<HTML>"+
		"<HEAD>"+
		"	<TITLE>» Calendar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TITLE>"+
		"<style>"+
		"a.{color:#AOAOA4;text-decoration:none}"+
		"a:link{color:#AOAOA4;}"+
		"a:active{color:#A0A0A4;}"+
		"a:visited{color:#A0A0A4;}"+
		"a:hover{color:#FFFFFF; text-decoration:none}"+
		"</style>"+
		"<SCRIPT>"+
		"var isIE4 = false;"+
		"function CheckBrowser(){ "+
		"	if (navigator.appName == \"Microsoft Internet Explorer\" && navigator.appVersion.charAt(0) >= 4) { isIE4 = true; }"+
		"}"+
		"function mOvr(src,clrOver){"+
		"	if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver;}"+
		"}"+
		"function mOut(src,clrIn){"+
		"	if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn;}"+
		"}"+
		"</SCRIPT>"+
		"</HEAD>"+
		"<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" TOPMARGIN=3 LEFTMARGIN=3 MARGINWIDTH=3 MARGINHEIGHT=3 STYLE='border:0;'>"+
			"<TABLE BORDER=0 BGCOLOR=\"#000000\" CELLSPACING=1 CELLPADDING=0 WIDTH=\"100%\" >"+
				"<TR>"+
					"<TD WIDTH=29 BGCOLOR=\"#808080\" HEIGHT=15 style=\"cursor:hand\" onClick=\"javascript:window.opener.showCalendar('"+
				str_target+"', '"+ dt2dtstr4(dt_prev_month)+"');\">"+
						"<P ALIGN=CENTER><a href=\"javascript:window.opener.showCalendar('"+
				str_target+"', '"+ dt2dtstr4(dt_prev_month)+"');\"><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">«</FONT></P></a>"+
					"</TD>"+
					"<TD COLSPAN=5 BGCOLOR=\"#808080\" style=\"cursor:default\">"+
						"<P ALIGN=CENTER><B><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">"+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</FONT></B></P>"+
					"</TD>"+
					"<TD WIDTH=28 BGCOLOR=\"#808080\" style=\"cursor:hand\" onClick=\"javascript:window.opener.showCalendar('"
				+str_target+"', '"+dt2dtstr4(dt_next_month)+"');\">"+
						"<P ALIGN=CENTER><a href=\"javascript:window.opener.showCalendar('"
				+str_target+"', '"+dt2dtstr4(dt_next_month)+"');\"><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">»</FONT></P></a>"+
					"</TD>"+
				"</TR>"+
				"<TR>"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	//str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "<TD WIDTH=29 BGCOLOR=\"#D2D2D2\" HEIGHT=15 style=\"cursor:default\"><P ALIGN=CENTER><B><FONT SIZE=\"-2\" FACE=\"Verdana\">"+
		week_days[(n_weekstart+n)%7]+"</FONT></B></P></TD>";
	// print calendar table
	//str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row header
		str_buffer += "<tr>\n";

		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				
				if ((dt_current_day.getMonth() == dt_datetime.getMonth()) && (dt_current_day.getDate() == dt_datetime.getDate()))
					// print current date
					str_buffer += "	<td bgcolor=\"#FF9900\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#FFCC00');\" onmouseout=\"mOut(this,'#FF9900');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#F0F0F0\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#FFCC00');\" onmouseout=\"mOut(this,'#F0F0F0');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#FFCC00');\" onmouseout=\"mOut(this,'white');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"verdana\" size=\"-2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">"+
					"<font color=\"#A0A0A4\" face=\"verdana\" size=\"-2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	str_buffer +=
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";

	var w = 200;
	var h = 131;
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var vWinCal = window.open("", "Calendar", 
		"width="+w+",height="+h+",status=no,resizable=no,top="+TopPosition+",left="+LeftPosition);
	vWinCal.opener = self;
	vWinCal.focus();
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routines. modify them if you wish other datetime format
function str2dt4 (str_datetime) {
	var re_date = /(\d+)\/(\d+)\/(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Invalid Date format: "+ str_datetime);
	return (new Date (RegExp.$3, RegExp.$1-1, RegExp.$2));
}
function dt2dtstr4 (dt_datetime) {
	return (new String (
			(dt_datetime.getMonth()+1)+"/"+dt_datetime.getDate()+"/"+dt_datetime.getFullYear()));
}

//::Expand Menu Options
function ExpandMenuOptions(id,icon){
	if (id.style.visibility == 'hidden'){
		id.style.visibility = '';
	}else{
		id.style.visibility = 'hidden';
	}
}

//::Confirm Delete
function del(url,msg){
	if (confirm(msg)) {
		document.location.href = url;
	}else{}
}

//::Confirm Submit
function ConfirmSubmit(msg){
	if (confirm(msg)) {
		return true;
	}else{return false;}
}

//::Pass List Items Function
function PassListItems(){
	var srcList = document.forms[0].categoryassociation;
	var ListItems = "";

	for(var i = 0; i < srcList.options.length; i++) { 
		if (srcList.options[i] != null)
		ListItems = ListItems + srcList.options[i].value + ",";
	}

	CiPopWin('sc_admin_categoryassociation.asp?ids='+ListItems,'CategoryAssociation','321','300','yes','no');return false
}

//::Pass Category Discount Function
function PassCategoryDiscount(){
	var srcList = document.forms[0].categoryassociation;
	var ListItems = "";

	for(var i = 0; i < srcList.options.length; i++) { 
		if (srcList.options[i] != null)
		ListItems = ListItems + srcList.options[i].value + ",";
	}

	CiPopWin('sc_admin_categorydiscount.asp?ids='+ListItems,'CategoryDiscount','321','300','yes','no');return false
}

//::Return List Items Function
//	ex. ReturnListItems(document.forms[0].CHECKBOXNAMES)
function ReturnListItems(chkItems) {
	arrCnt = 0;
	arrSubCnt = 0;
	arrayList = 0;

	if(chkItems.length != null){
		for(var index = 0; index < chkItems.length; index++){
			if(chkItems[index].checked){
				chkd = true;
				break;
			}
			else{
				chkd = false
			}
		}

		if (chkd){
			arrItems = new Array(1);
			for (i = 0; i < chkItems.length; i++) {
				if(chkItems[i].checked == true){
					arrItems[arrCnt] = new Array(1)
					for (arrSubCnt = 0; arrSubCnt < 2; arrSubCnt++) {
						str = chkItems[i].value;
						dlp = str.indexOf("-");
						len = str.length;
						val = str.substr(0,dlp);
						txt = str.substr(dlp+1,len);
						if(arrSubCnt == 0){
							arrItems[arrCnt][arrSubCnt] = val; //value
						}
						else{
							arrItems[arrCnt][arrSubCnt] = txt; //text
						}
					}
					arrCnt++;
				}
			}
			arrayList = arrItems;
		}
		else{
			arrayList = 0;
		}
	}
	else{
		if(chkItems.checked){
			arrItems = new Array(1);
			arrItems[0] = new Array(1);

			str = chkItems.value;
			dlp = str.indexOf("-");
			len = str.length;
			val = str.substr(0,dlp);
			txt = str.substr(dlp+1,len);

			arrItems[0][0] = val; //value
			arrItems[0][1] = txt; //text

			arrayList = arrItems;
		}
		else{
			arrayList = 0;
		}
	}

	self.opener.DisplayListItems(arrayList);
}

//::Display List Items Function
function DisplayListItems(arrayList){
	objList = document.forms[0].categoryassociation;
	document.all.categoryassociation.options.length = 0;

	if(arrayList.length > 0){
		for(i = 0; i < arrayList.length; i++) {
			for (j = 0; j < 2; j++) {
				if(j == 0){
					lstValue = arrayList[i][j]; //value
				}
				else{
					lstName = arrayList[i][j]; //text
				}
			}
			objList.options[i] = new Option(lstName, lstValue);
		}
	}
}

//::Check Checkbox Function
function CheckCheckbox(chk){
	//::OnError = Ignore
	window.onerror=ignore
	function ignore(){return true}
	chkbox = eval(chk);
	chkbox.checked = !chkbox.checked;
}

//::check mass update checkbox
function CheckMassUpdate(chk){
	if ((chk.checked == true) || (chk == true)){
		document.forms[0].massupdate.checked = true;
	}
}

//::Remove All Check Box Items
function RemoveAllCheckBox(objChk){
	//::OnError = Ignore
	window.onerror=ignore
	function ignore(){return true}

	if (confirm("Are you sure you want to clear all category associations?")){
		for(i = 0; i < objChk.length; i++){
			objChk[i].checked = false;
		}
	}
}

//::Select List Function
//	ex. document.FORMNAME.LISTBOXNAME
function SelectList(lst) {
	for (i = 0; i < lst.length; i++) {
		lst.options[i].selected = true;
	}
}

//::Add to List Function
function AddToList(txt,val,loc){
	switch (loc) {
		case "manufacturer":
			objListBox = document.forms[0].manufacturer;
			break;
		case "shippingcompany":
			objListBox = document.forms[0].shippingcompany;
			break;
	}
	lenListBox = objListBox.length;
	objListBox.options[lenListBox] = new Option(txt,val);
	objListBox.options[lenListBox].selected = true;
	objListBox.options[lenListBox].focus();
}

//::Remove from List Function
function RemoveFromList(loc){
	switch (loc) {
		case "manufacturer":
			objListBox = document.forms[0].manufacturer;
			break;
		case "shippingcompany":
			objListBox = document.forms[0].shippingcompany;
			break;
	}
	objIndex = objListBox.selectedIndex;
	objListBox.options.remove(objIndex);
}

//::Remove Characters from String
function RemoveChar(sStr,sChar){
	newStr = sStr.replace(sChar,"");
	return newStr;
}

//::Confirm Delete w/ window.close on cancel
function delclose(url,msg){
	if (confirm(msg)) {
		document.location.href = url;
	}else{window.close();}
}

//::Valid String
function ValidString(str){
	str = Trim(str);
	if (str != "" && !IsNumeric(str)){
		return true
	}else{return false}
}

//::Valid Number
function ValidNumber(num){
	str = Trim(num);
	if (str != "" && IsNumeric(str) && str.indexOf(" ") < 0){
		return true
	}else{return false}
}

//::Valid Currency
function ValidCurrency(num){
	str = Trim(num);
	str = str.replace("$","");
	str = str.replace(",","");
	str = str.replace(".","");
	if (str != "" && IsNumeric(str)){
		return true
	}else{return false}
}

//::Valid Percent
function ValidPercent(num){
	str = Trim(num);
	str = str.replace("%","");
	str = str.replace(".","");
	if (str != "" && IsNumeric(str)){
		return true
	}else{return false}
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Password
function ValidPassword(p1,p2){
	if (p1 != "" && p2 != ""){
		if (p1 == p2) {
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf,empty){
	if (empty == 1){
		if ((Trim(PhoneArea) == "") || 
			(Trim(PhonePre) == "") ||
			(Trim(PhoneSuf) == "")){
			return false;
		}else{
			return true;
		}
	}else{
//			(ValidNumber(PhoneArea) && PhoneArea.length == 3) &&
//			(ValidNumber(PhonePre) && PhonePre.length == 3) &&
//			(ValidNumber(PhoneSuf) && PhoneSuf.length == 4)
		if (ValidNumber(PhoneArea) &&
			ValidNumber(PhonePre) &&
			ValidNumber(PhoneSuf)){
			return true;
		}else{
			return false;
		}
	}
}

//::Valid Credit Card Number
function ValidCreditCard(s){
	var i, n, c, r, t;
	r = "";
	for (i = 0; i < s.length; i++) {
		c = parseInt(s.charAt(i), 10);
		if (c >= 0 && c <= 9)
			r = c + r;
	}
	if (r.length <= 12)
		return false;
	t = "";
	for (i = 0; i < r.length; i++) {
		c = parseInt(r.charAt(i), 10);
		if (i % 2 != 0) 
			c *= 2;
			t = t + c;
	}
	n = 0;
	for (i = 0; i < t.length; i++) {
		c = parseInt(t.charAt(i), 10);
		n = n + c;
	}
	if (n != 0 && n % 10 == 0)
		return true;
	else
		return false;
}

//::Validate Fields (w/ image swap)
function ValidateFieldIMG(val,img,type,p1,p2,p3){
	var imgReq = "images/Icon_Required.gif"
	var imgAcc = "images/Icon_Acceptable.gif"
	var imgErr = "images/Icon_Error.gif"

	switch(type){
		case 1: //string
			if(Trim(val.value) == ""){
				img.src = imgReq;
			}
			else if(ValidString(val.value)){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 2: //numeric
			if(Trim(val.value) == ""){
				img.src = imgReq;
			}
			else if(ValidNumber(val.value)){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 3: //e-mail
			if(Trim(val.value) == ""){
				img.src = imgReq;
			}else if (ValidEmail(val.value)){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 4: //phone
			if(!ValidPhone(p1,p2,p3,1)){
				img.src = imgReq;
			}else if (ValidPhone(p1,p2,p3,0)){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 5: //multi-fields
			if ((p1 == "") ||  
				(p2 == "")) {
				img.src = imgReq;
			}else {
				img.src = imgAcc;
			}
			break;

		case 6: //passwords
			if(val.value == "") {
				img.src = imgReq;
			}else if (ValidPassword(p1,p2)) {
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 7: //credit card
			if(Trim(val.value) == ""){
				img.src = imgReq;
			}else if (ValidCreditCard(val.value) && ValidNumber(val.value)){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		case 8: //mixed
			if(Trim(val.value) == ""){
				img.src = imgReq;
			}
			else if(Trim(val.value) != ""){
				img.src = imgAcc;
			}
			else{
				img.src = imgErr;
			}
			break;

		default://blank
			img.src = imgReq;
	}
}

//::Validation Button Linker
function VLinker(lnkTitle,lnkMsg,pixHeight){
	if(pixHeight == null){
		pixHeight = 100;
	}
	CiPopWin('sc_validationwindow.asp?title='+lnkTitle+'&msg='+lnkMsg,'ValidationWindow','299',pixHeight,'no','no'); return false
}

//::Password Recovery Validation
function EmailValidate(){
	missinginfo = "";
	var objForm = document.forms[0];
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Password Recovery',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Fields
function ValidateFields(type) {
	missinginfo = "";
	var objForm = document.forms[0];

	//checkout page registration
	if (type == 1) {
		for(var i=0; i<document.forms[0].elements.length; i++){
			if(document.forms[0].elements[i].name== "registeremail"){
				if (objForm.createnewaccount.checked) {
					if (!ValidEmail(objForm.registeremail.value)) {
					missinginfo += "\n     »  Registration E-Mail";
					}
					if (!ValidPassword(objForm.registerpassword.value,objForm.registerpasswordrepeat.value)) {
					missinginfo += "\n     »  Registration Password";
					}

					if (missinginfo != "") {
						missinginfo += "\n----------------------------------------"
					}
				}
			}
		}
	}
	//login page registration
	else if (type == 2){
		if (!ValidEmail(objForm.registeremail.value)) {
		missinginfo += "\n     »  Registration E-Mail";
		}
		if (!ValidPassword(objForm.registerpassword.value,objForm.registerpasswordrepeat.value)) {
		missinginfo += "\n     »  Registration Password";
		}

		if (missinginfo != "") {
			missinginfo += "\n----------------------------------------"
		}
	}
	
	//universal billing and shipping addresses
	if (!ValidString(objForm.b_firstname.value)) {
	missinginfo += "\n     »  Billing First Name";
	}
	if (!ValidString(objForm.b_lastname.value)) {
	missinginfo += "\n     »  Billing Last Name";
	}
	if (!ValidString(objForm.b_address1.value)) {
	missinginfo += "\n     »  Billing Address";
	}
	if (!ValidString(objForm.b_city.value)) {
	missinginfo += "\n     »  Billing City";
	}
	if (objForm.b_country.value=="" || objForm.b_country.value==249){
		if (!ValidNumber(objForm.b_state.value)) {
		missinginfo += "\n     »  Billing State";
		}
	}
	if (!ValidNumber(objForm.b_country.value)) {
	missinginfo += "\n     »  Billing Country";
	}
	if (objForm.b_zip.value=="") {
	missinginfo += "\n     »  Billing Zip";
	}
	if (!ValidPhone(objForm.b_phonearea.value,objForm.b_phonepre.value,objForm.b_phonesuf.value,0)) {
	missinginfo += "\n     »  Billing Phone";
	}
	if (objForm.b_faxarea.value!="" || objForm.b_faxpre.value!="" || objForm.b_faxsuf.value!="") {
		if (!ValidPhone(objForm.b_faxarea.value,objForm.b_faxpre.value,objForm.b_faxsuf.value,0)) {
		missinginfo += "\n     »  Billing Fax";
		}
	}
	if (!ValidEmail(objForm.b_email.value)) {
	missinginfo += "\n     »  Billing E-Mail Address";
	}
	if (!ValidString(objForm.s_firstname.value)) {
	missinginfo += "\n     »  Shipping First Name";
	}
	if (!ValidString(objForm.s_lastname.value)) {
	missinginfo += "\n     »  Shipping Last Name";
	}
	if (!ValidString(objForm.s_address1.value)) {
	missinginfo += "\n     »  Shipping Address";
	}
	if (!ValidString(objForm.s_city.value)) {
	missinginfo += "\n     »  Shipping City";
	}
	if (objForm.s_country.value=="" || objForm.s_country.value==249){
		if (!ValidNumber(objForm.s_state.value)) {
		missinginfo += "\n     »  Shipping State";
		}
	}
	if (!ValidNumber(objForm.s_country.value)) {
	missinginfo += "\n     »  Shipping Country";
	}
	if (objForm.s_zip.value=="") {
	missinginfo += "\n     »  Shipping Zip";
	}
	if (!ValidPhone(objForm.s_phonearea.value,objForm.s_phonepre.value,objForm.s_phonesuf.value,0)) {
	missinginfo += "\n     »  Shipping Phone";
	}
	if (objForm.s_faxarea.value!="" || objForm.s_faxpre.value!="" || objForm.s_faxsuf.value!="") {
		if (!ValidPhone(objForm.s_faxarea.value,objForm.s_faxpre.value,objForm.s_faxsuf.value,0)) {
		missinginfo += "\n     »  Shipping Fax";
		}
	}
	if (!ValidEmail(objForm.s_email.value)) {
	missinginfo += "\n     »  Shipping E-Mail Address";
	}

//	//checkout payment information
//	if (type == 1){
//		if (objForm.paymentmethod.value == "") {
//		missinginfo += "\n     »  Payment Method";
//		}else{
//			switch (objForm.paymentmethod.value) {
//				case "1": //Credit Card
//					if (objForm.creditcard.value == "") {
//					missinginfo += "\n     »  Credit Card";
//					}
//					if (!ValidCreditCard(objForm.cardnumber.value) || !ValidNumber(objForm.cardnumber.value)) {
//					missinginfo += "\n     »  Credit Card Number";
//					}
//					//if (objForm.avscode.value == "") {
//					//missinginfo += "\n     »  AVS Code";
//					//}
//					if ((objForm.expdatemonth.value == "") ||  
//					(objForm.expdateyear.value == "")) {
//					missinginfo += "\n     »  Expiration Date";
//					}
//					if (objForm.cardholdername.value == "") {
//					missinginfo += "\n     »  Cardholder Name";
//					}
//					break;
//
//				case "2": //Check / Money Order
//					break;
//
//				case "3": //Phone
//					break;
//			}
//		}
//	}

	if (missinginfo != "") {
	missinginfo = "The following information is missing or was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	//VLinker('Checkout',missinginfo,(missinginfo.length/140)*90);
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Edit Profile Fields
function ValidateEditProfile() {
	missinginfo = "";
	var objForm = document.forms[0];

	//login page registration
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}

	if (objForm.oldpassword.value != ""){
		if (!ValidPassword(objForm.pw.value,objForm.oldpassword.value)) {
		missinginfo += "\n     »  Old Password";
		}
		if (!ValidPassword(objForm.newpassword.value,objForm.newpasswordrepeat.value)) {
		missinginfo += "\n     »  New Password";
		}

		if (missinginfo != "") {
			missinginfo += "|\n----------------------------------------"
		}
	}

	//universal billing and shipping addresses
	if (!ValidString(objForm.b_firstname.value)) {
	missinginfo += "\n     »  Billing First Name";
	}
	if (!ValidString(objForm.b_lastname.value)) {
	missinginfo += "\n     »  Billing Last Name";
	}
	if (!ValidString(objForm.b_address1.value)) {
	missinginfo += "\n     »  Billing Address";
	}
	if (!ValidString(objForm.b_city.value)) {
	missinginfo += "\n     »  Billing City";
	}
	if (objForm.b_country.value=="" || objForm.b_country.value==249){
		if (!ValidNumber(objForm.b_state.value)) {
		missinginfo += "\n     »  Billing State";
		}
	}
	if (!ValidNumber(objForm.b_country.value)) {
	missinginfo += "\n     »  Billing Country";
	}
	if (objForm.b_zip.value=="") {
	missinginfo += "\n     »  Billing Zip";
	}
	if (!ValidPhone(objForm.b_phonearea.value,objForm.b_phonepre.value,objForm.b_phonesuf.value,0)) {
	missinginfo += "\n     »  Billing Phone";
	}
	if (objForm.b_faxarea.value!="" || objForm.b_faxpre.value!="" || objForm.b_faxsuf.value!="") {
		if (!ValidPhone(objForm.b_faxarea.value,objForm.b_faxpre.value,objForm.b_faxsuf.value,0)) {
		missinginfo += "\n     »  Billing Fax";
		}
	}
	if (!ValidEmail(objForm.b_email.value)) {
	missinginfo += "\n     »  Billing E-Mail Address";
	}
	if (!ValidString(objForm.s_firstname.value)) {
	missinginfo += "\n     »  Shipping First Name";
	}
	if (!ValidString(objForm.s_lastname.value)) {
	missinginfo += "\n     »  Shipping Last Name";
	}
	if (!ValidString(objForm.s_address1.value)) {
	missinginfo += "\n     »  Shipping Address";
	}
	if (!ValidString(objForm.s_city.value)) {
	missinginfo += "\n     »  Shipping City";
	}
	if (objForm.s_country.value=="" || objForm.s_country.value==249){
		if (!ValidNumber(objForm.s_state.value)) {
		missinginfo += "\n     »  Shipping State";
		}
	}
	if (!ValidNumber(objForm.s_country.value)) {
	missinginfo += "\n     »  Shipping Country";
	}
	if (objForm.s_zip.value=="") {
	missinginfo += "\n     »  Shipping Zip";
	}
	if (!ValidPhone(objForm.s_phonearea.value,objForm.s_phonepre.value,objForm.s_phonesuf.value,0)) {
	missinginfo += "\n     »  Shipping Phone";
	}
	if (objForm.s_faxarea.value!="" || objForm.s_faxpre.value!="" || objForm.s_faxsuf.value!="") {
		if (!ValidPhone(objForm.s_faxarea.value,objForm.s_faxpre.value,objForm.s_faxsuf.value,0)) {
		missinginfo += "\n     »  Shipping Fax";
		}
	}
	if (!ValidEmail(objForm.s_email.value)) {
	missinginfo += "\n     »  Shipping E-Mail Address";
	}

	if (missinginfo != "") {
	missinginfo = "The following information is missing or was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	//VLinker('Edit Profile',missinginfo,(missinginfo.length/140)*90);
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Search form validation
function ValidateSearchFields() {
	keywordmsg = "Warning:\nYou must enter at least a keyword if no other search criteria is selected.";
	pricemsg = "Warning:\nYou must enter values for both price fields.";

	var objForm = document.frmSearch;
	var keywords = objForm.keywords.value;
	var manufacturer = objForm.manufacturer.value;
	var category = objForm.category.value;
	var pricefrom = objForm.pricefrom.value;
	var priceto = objForm.priceto.value;
	var itemnumber = objForm.itemnumber.value;
	var sale = objForm.sale;

	if (Trim(keywords) == "" && manufacturer == "" && category == "" && Trim(pricefrom) == "" && Trim(priceto) == "" && Trim(itemnumber) == "" && sale.checked == false){
		VLinker('Advanced Search',keywordmsg);
		return false;
	}
	
	if (Trim(pricefrom) != ""){
		if (priceto == ""){
			VLinker('Advanced Search',pricemsg);
			return false;
		}
	}
	
	if (Trim(priceto) != ""){
		if (pricefrom.value == ""){
			VLinker('Advanced Search',pricemsg);
			return false;
		}
	}
}

//::Validate Shipping Method
function ValidateShippingMethod(){
	var radioarr = document.forms[0].shippingmethod;
	if(radioarr.length > 0){
		for(var index = 0; index < radioarr.length; index++){
			if(radioarr[index].checked){
				rc = true;
				break;
			}
			else{
				rc = false
			}
		}
	}
	else{
		if(radioarr.checked == true){
			rc = true;
		}
		else{
			rc = false;
		}
	}

	if(rc == false){
		//VLinker('Shipping Method','Please select a shipping method before proceeding.');
		alert('Please select a shipping method before proceeding.');
		return false;
	}
	else{
		return true;
	}
}

//::Validate Shipping Rates Fields
function ValidateShippingRates() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (objForm.shippingcompany.value == "") {
	missinginfo += "\n     »  Shipping Company";
	}
	if (objForm.service.value == "") {
	missinginfo += "\n     »  Service";
	}
	if (objForm.servicedetail.value == "") {
	missinginfo += "\n     »  Service Detail";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	//VLinker('Shipping Rates',missinginfo);
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Payment Method
function ValidatePaymentMethod(){
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.paymentmethod.value == "") {
	missinginfo += "\n     »  Payment Method";
	}else{
		switch (objForm.paymentmethod.value) {
			case "1": //Credit Card
				if (objForm.creditcard.value == "") {
				missinginfo += "\n     »  Credit Card";
				}
				if (!ValidCreditCard(objForm.cardnumber.value) || !ValidNumber(objForm.cardnumber.value)) {
				missinginfo += "\n     »  Credit Card Number";
				}
				//if (objForm.avscode.value == "") {
				//missinginfo += "\n     »  AVS Code";
				//}
				if ((objForm.expdatemonth.value == "") ||  
				(objForm.expdateyear.value == "")) {
				missinginfo += "\n     »  Expiration Date";
				}
				if (objForm.cardholdername.value == "") {
				missinginfo += "\n     »  Cardholder Name";
				}
				break;

			case "2": //Check / Money Order
				break;

			case "3": //Phone
				break;

			case "4": //PayPal
				break;
		}
	}

	if (missinginfo != "") {
	missinginfo = "The following information is missing or was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	//VLinker('Checkout',missinginfo,(missinginfo.length/140)*90);
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::check if any items are selected
function CheckForSelectedItems(arr){
	for(var index = 0; index < arr.length; index++){
		if(arr[index].selected){
			return true;
			break;
		}
		else{
			return false;
		}
	}
}

//::check if form element exists
function FormElementExists(frmname){
	for(var i=0; i<document.forms[0].elements.length; i++){
		if(document.forms[0].elements[i].name == frmname){
			return true;
		}
	}
}

//::Validate Sale Item Fields
function ValidateSaleItems(id,amt) {
	missinginfo = "";
	var objForm = document.forms[0];

	if (id == "") {
		if (!CheckForSelectedItems(document.forms[0].categoryassociation) && objForm.massupdate.checked == false){
			missinginfo += "|\n     |Note: You must select at least one product or category to perform this action.";
			missinginfo += "|\n     ----------------------------------------------------"
		}
	}

	if (objForm.discounttype.value == "") {
	missinginfo += "\n     »  Discount Type";
	}
	if (!ValidCurrency(objForm.discountamount.value) && !ValidPercent(objForm.discountamount.value)) {
	missinginfo += "\n     »  Discount Amount";
	}
	switch (objForm.discounttype.value) {
		case "1":		//Amount
			if (parseFloat(objForm.discountamount.value.replace("$","")) >= parseFloat(amt)) {
				missinginfo += "\n     »  Amount must be less than or equal to <b>$" + amt + "</b>";
			}
			break;
		case "2":		//Percent
			if (parseFloat(objForm.discountamount.value.replace("%","")) <= 0 || 				
				parseFloat(objForm.discountamount.value.replace("%","")) > 100) {
				missinginfo += "\n     »  Percent must equal between <b>1%</b> and <b>100%</b>";
			}
			break;
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Sale Items',missinginfo,150);
	return false;
	}
	else return true;
}

//::Validate Product Entry Fields
function ValidateProductEntry() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (objForm.productname.value == "") {
	missinginfo += "\n     »  Product Name";
	}
	if (objForm.description.value == "") {
	missinginfo += "\n     »  Description";
	}
	if (objForm.categoryassociation.value == "") {
	missinginfo += "\n     »  Category Association";
	}
	if (objForm.price.value == "") {
	missinginfo += "\n     »  Price";
	}
	if (FormElementExists("qty")) {
		if (objForm.qty.value == "") {
		missinginfo += "\n     »  Stock Quantity";
		}
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Product Management',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Totals Table Fields
function ValidateTotalsTableEntry() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (!ValidCurrency(objForm.totallow.value)) {
	missinginfo += "\n     »  Total Low ($)";
	}
	if (objForm.totalhigh.value != "*") {
		if (!ValidCurrency(objForm.totalhigh.value)) {
		missinginfo += "\n     »  Total High ($)";
		}
	}
	if (!ValidCurrency(objForm.costpercent.value) && !ValidPercent(objForm.costpercent.value)) {
	missinginfo += "\n     »  Cost ($) / Percent (%)";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Totals Table',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Login Accounts Fields
function ValidateLoginAccountsEntry() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.password.value == "") {
	missinginfo += "\n     »  Password";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Login Accounts',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Manufacturer Quick Add Fields
function ValidateManQuickAddEntry() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (objForm.manufacturer.value == "") {
	missinginfo += "\n     »  Manufacturer Name";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Manufacturer Quick Add',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Shipping Company Quick Add Fields
function ValidateShipQuickAddEntry() {
	missinginfo = "";
	var objForm = document.forms[0];
	if (objForm.shippingcompany.value == "") {
	missinginfo += "\n     »  Shipping Company Name";
	}
	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Shipping Company Quick Add',missinginfo);
	return false;
	}
	else return true;
}

//::Validate Orders Process Fields
function ValidateOrdersProcessEntry() {
	missinginfo = "";
	var objForm = document.forms[0];

	//universal billing and shipping addresses
	if (!ValidString(objForm.b_firstname.value)) {
	missinginfo += "\n     »  Billing First Name";
	}
	if (!ValidString(objForm.b_lastname.value)) {
	missinginfo += "\n     »  Billing Last Name";
	}
	if (!ValidString(objForm.b_address1.value)) {
	missinginfo += "\n     »  Billing Address";
	}
	if (!ValidString(objForm.b_city.value)) {
	missinginfo += "\n     »  Billing City";
	}
	if (objForm.b_country.value=="" || objForm.b_country.value==249){
		if (!ValidNumber(objForm.b_state.value)) {
		missinginfo += "\n     »  Billing State";
		}
	}
	if (!ValidNumber(objForm.b_country.value)) {
	missinginfo += "\n     »  Billing Country";
	}
	if (objForm.b_zip.value=="") {
	missinginfo += "\n     »  Billing Zip";
	}
	if (!ValidPhone(objForm.b_phonearea.value,objForm.b_phonepre.value,objForm.b_phonesuf.value,0)) {
	missinginfo += "\n     »  Billing Phone";
	}
	if (objForm.b_faxarea.value!="" || objForm.b_faxpre.value!="" || objForm.b_faxsuf.value!="") {
		if (!ValidPhone(objForm.b_faxarea.value,objForm.b_faxpre.value,objForm.b_faxsuf.value,0)) {
		missinginfo += "\n     »  Billing Fax";
		}
	}
	if (!ValidEmail(objForm.b_email.value)) {
	missinginfo += "\n     »  Billing E-Mail Address";
	}
	if (!ValidString(objForm.s_firstname.value)) {
	missinginfo += "\n     »  Shipping First Name";
	}
	if (!ValidString(objForm.s_lastname.value)) {
	missinginfo += "\n     »  Shipping Last Name";
	}
	if (!ValidString(objForm.s_address1.value)) {
	missinginfo += "\n     »  Shipping Address";
	}
	if (!ValidString(objForm.s_city.value)) {
	missinginfo += "\n     »  Shipping City";
	}
	if (objForm.s_country.value=="" || objForm.s_country.value==249){
		if (!ValidNumber(objForm.s_state.value)) {
		missinginfo += "\n     »  Shipping State";
		}
	}
	if (!ValidNumber(objForm.s_country.value)) {
	missinginfo += "\n     »  Shipping Country";
	}
	if (objForm.s_zip.value=="") {
	missinginfo += "\n     »  Shipping Zip";
	}
	if (!ValidPhone(objForm.s_phonearea.value,objForm.s_phonepre.value,objForm.s_phonesuf.value,0)) {
	missinginfo += "\n     »  Shipping Phone";
	}
	if (objForm.s_faxarea.value!="" || objForm.s_faxpre.value!="" || objForm.s_faxsuf.value!="") {
		if (!ValidPhone(objForm.s_faxarea.value,objForm.s_faxpre.value,objForm.s_faxsuf.value,0)) {
		missinginfo += "\n     »  Shipping Fax";
		}
	}
	if (!ValidEmail(objForm.s_email.value)) {
	missinginfo += "\n     »  Shipping E-Mail Address";
	}

	if (objForm.orderstatus.value == "") {
	missinginfo += "\n     »  Order Status";
	}

	if (objForm.orderstatus.value == 4) {
		if (objForm.deliverydate.value == "") {
		missinginfo += "\n     »  Ship Date";
		}
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "||\n\nPlease re-enter the information and try again...";
	VLinker('Orders Process',missinginfo,(missinginfo.length/140)*90);
	return false;
	}
	else return true;
}

//::Display Upload message text
function DisplayUpload(){
	UploadMSG.style.display = '';
}

//::Check All Function
//ex.	onClick="CheckAll(document.forms[0].chkFields);"
var checkflag = "false";
function CheckAll(field){
	window.onerror=ignore
	function ignore(){return true}
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++){
		field[i].checked = true;}
		checkflag = "true";
	}
	else{
		for (i = 0; i < field.length; i++){
		field[i].checked = false; }
		checkflag = "false";
	}
}

//::Display/Hide Date Range
function DisplayDateRange(){
	if (document.forms[0].orderdate.value == 'Date Range'){
		dtfr.style.visibility = 'visible';
		dtto.style.visibility = 'visible';
	}else{
		dtfr.style.visibility = 'hidden';
		dtto.style.visibility = 'hidden';
	}
}

//::Display/Hide Shipping Menus
function SwapShippingMenus(){
	objForm = document.forms[0];
	loc = objForm.shippingmethodtype.value;

	//vals = String(vals);
	//arrVals = vals.split(",");

	switch (loc) {
		case "1":
			add1.style.display = 'block';
			add2.style.display = 'none';
			fld1.style.visibility = 'visible';
			fld2.style.visibility = 'hidden';
			txtTT.style.display = 'block';
			imgTT.style.display = 'block';
			//objForm.costpercent.value = arrVals[0];
			break;
		
		case "2":
			add1.style.display = 'none';
			add2.style.display = 'block';
			fld1.style.visibility = 'hidden';
			fld2.style.visibility = 'visible';
			txtTT.style.display = 'none';
			imgTT.style.display = 'none';
			//objForm.costpercent.value = arrVals[1];
			break;
	}
}

//::Remove Check
function RemoveCheck(loc){
	switch (loc) {
		case "manufacturer":
			id = document.forms[0].manufacturer.value;
			if(id > 0){
				url = "sc_admin_manquickadd.asp";
			}
			else{
				alt = "Note:\nYou must select a manufacturer to perform this action.";
			}
			break;
		case "shippingcompany":
			id = document.forms[0].shippingcompany.value;
			if(id > 0){
				url = "sc_admin_shipquickadd.asp";
			}
			else{
				alt = "Note:\nYou must select a shipping company to perform this action.";
			}
			break;
	}
	if(id > 0){
		CiPopWin(url+'?md=delete&id='+id,'RemoveWin','1','1','no','no');return false
	}
	else{
		VLinker('Delete',alt);
	}
}

//::JS Color Picker Utility
var CP = new ColorPicker();
function ColorPopup(field, palette) {
	var strHTML = new String (
	"<html><head><title>» Color Picker</title>"+
	"<style>"+
	".bd {border: 0px;"+
	"	border-color:black;}"+
	".s  {font-family: Verdana,Tahoma,Arial,Helvetica,Sans-serif,sans-serif; "+
	"	font-size: xx-small; "+
	"	background-color: rgb(240,240,240);"+ 
	"	border: 1pt solid rgb(0,0,0);"+
	"	width: 163;}"+
	"</style></head>"+
	"<body leftmargin='5' topmargin='4' marginheight='0' marginwidth='0' onload='P.C(P.initPalette)' style='border:0;'>"+
	"<table cellpadding=0 cellspacing=0 border=0 width=157>"+
	"<form><tr><td align='center'>"+
	"<select name='type' onchange='P.C(this.selectedIndex)' class='s'>"+
	"	<option>Web Safe Palette</option>"+
	"	<option>Windows System Palette</option>"+
	"	<option>Gray Scale Palette</option>"+
	"</select>"+
	"</td></tr>"+
	"<tr><td align='center'>"+
	"<script language='JavaScript'>"+
	"	var P = opener.CP;"+
	"	onload = 'P.show(P.initPalette)';"+
	"	document.forms[0].elements[0].selectedIndex = P.initPalette;"+
	"	P.draw(window, document);"+
	"</script>"+
	"</td></tr>"+
	"</form></table></body></html>");
	this.field = field;
	this.initPalette = !palette || palette > 2 ? 0 : palette;
	var w = 169, h = 149,
	move = screen ? 
		',left=' + ((screen.width - w) >> 1) + ',top=' + ((screen.height - h) >> 1) : '', 
	o_colWindow = window.open("", null, "help=no,status=no,scrollbars=no,resizable=no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
	o_colWindow.opener = self;
	o_colWindow.focus();
	var o_doc = o_colWindow.document;
	o_doc.write(strHTML);
	o_doc.close();
}
function BuildCell (R, G, B, w, h) {
	return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')"><img src="pixel.gif" width="' + w + '" height="' + h + '" border="0"></a></td>';
}
function ColorSelect(c) {
	this.field.value = '#' + c.toUpperCase();
	this.win.close();
}
function ColorPaint(c, b_noPref) {
	c = (b_noPref ? '' : '#') + c.toUpperCase();
	if (this.o_samp) 
		this.o_samp.innerHTML = '<font face=verdana size=-2>' + c +' <font color=white>' + c + '</font></font>'
	if(this.doc.layers)
		this.sample.bgColor = c;
	else { 
		if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
		else if (this.sample.background != null) this.sample.background = c;
	}
}
function GenerateSafe() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i ++)
				s += this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 8);
		s += "</tr>";
	}
	return s;
}
function GenerateWindows() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++)
				s += this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 8);
		s += "</tr>";
	}
	return s	
}
function GenerateGray() {
	var s = '';
	for (j = 0; j <= 15; j ++) {
		s += "<tr>";
		for (k = 0; k <= 15; k ++) {
			g = Math.floor((k + j * 16) % 256);
			s += this.bldCell(g, g, g, 9, 5);
		}
		s += '</tr>';
	}
	return s
}
function Dec2Hex(v) {
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}
function ChgMode(v) {
	for (var k in this.divs) this.hide(k);
	this.show(v);
}
function ColorPicker(field) {
	this.build0 = GenerateSafe;
	this.build1 = GenerateWindows;
	this.build2 = GenerateGray;
	this.show = document.layers ? 
		function (div) { this.divs[div].visibility = 'show' } :
		function (div) { this.divs[div].visibility = 'visible' };
	this.hide = document.layers ? 
		function (div) { this.divs[div].visibility = 'hide' } :
		function (div) { this.divs[div].visibility = 'hidden' };
	// event handlers
	this.C       = ChgMode;
	this.S       = ColorSelect;
	this.P       = ColorPaint;
	this.CP		 = ColorPopup;
	this.draw    = ColorDraw;
	this.dec2hex = Dec2Hex;
	this.bldCell = BuildCell;
	this.divs	 = [];
}
function ColorDraw(o_win, o_doc) {
	this.win = o_win;
	this.doc = o_doc;
	var 
	s_tag_openT  = o_doc.layers ? 
		'layer visibility=hidden top=39 left=1 width=172' : 
		'div style=visibility:hidden;position:absolute;left:1px;top:39px;width:172px;height:0',
	s_tag_openS  = o_doc.layers ? 'layer top=12 left=1' : 'div',
	s_tag_close  = o_doc.layers ? 'layer' : 'div'
		
	this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=163 align=center class=bd><tr><td align=center height=15><div id="samp"><font face=verdana size=-2>&nbsp;<font color=white>&nbsp;</font></font></div></td></tr></table></' + s_tag_close + '>');
	this.sample = o_doc.layers ? o_doc.layers['sam'] : 
		o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style

	for (var k = 0; k < 3; k ++) {
		this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding=0 cellspacing=1 border=0 align=center style="background-color:black;">' + this['build' + k]() + '</table></' + s_tag_close + '>');
		this.divs[k] = o_doc.layers 
			? o_doc.layers['p' + k] : o_doc.all 
				? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
	}
	if (!o_doc.layers && o_doc.body.innerHTML) 
		this.o_samp = o_doc.all 
			? o_doc.all.samp : o_doc.getElementById('samp');
	this.C(this.initPalette);
	if (this.field.value) this.P(this.field.value, true)
}
//::Examble of HTML usage
//<a href="javascript:CP.CP(document.forms[0].COLORFIELD,1);">
//<script language="JavaScript" src="colorpicker.js"></script>

//::Flashing Links<%=NavTableLoginTx%>
var lnkFlash=new Array()
function lnkColor(){
	for (i=0; i< lnkFlash.length; i++){
		var flashtype=document.getElementById? lnkFlash[i].getAttribute("flashtype")*1 : lnkFlash[i].flashtype*1
		var flashcolor=document.getElementById? lnkFlash[i].getAttribute("flashcolor") : lnkFlash[i].flashcolor
		if (flashtype==0){
			if (lnkFlash[i].style.color!=flashcolor)
				lnkFlash[i].style.color=flashcolor
			else
				lnkFlash[i].style.color=''
		}
		else if (flashtype==1){
			if (lnkFlash[i].style.backgroundColor!=flashcolor)
				lnkFlash[i].style.backgroundColor=flashcolor
			else
				lnkFlash[i].style.backgroundColor=''
		}
	}
}
function init(){
	var i=0
	if (document.all){
		while (eval("document.all.flashlink"+i)!=null){
			lnkFlash[i]= eval("document.all.flashlink"+i)
			i++
		} 
	}
	else if (document.getElementById){
		while (document.getElementById("flashlink"+i)!=null){
			lnkFlash[i]= document.getElementById("flashlink"+i)
			i++
		}
	}
	setInterval("lnkColor()", 1000)
}
if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.all)
window.onload=init

//::Auto-Select Country
function AutoSelectCountry(menu,infotype){
	objForm = document.forms[0];
	if(infotype == 1){
		if(menu.value != ""){
			objForm.b_country.value = 249;
		}
	}
	else{
		if(menu.value != ""){
			objForm.s_country.value = 249;
		}
	}
}

//::Auto-Select State
function AutoSelectState(menu,infotype){
	objForm = document.forms[0];
	if(infotype == 1){
		if(menu.value != "" && menu.value != 249){
			objForm.b_state.options[0].selected = true;
		}
	}
	else{
		if(menu.value != "" && menu.value != 249){
			objForm.s_state.options[0].selected = true;
		}
	}
}