//Copyright© 1998. ZYX Productions. All rights reserved.
//**Start Encode**
var touched=-1
var mesg="", confirmMesg=""

function getElm(elementID){
	if (document.getElementById){
	//alert('getElementById');
	return document.getElementById(elementID);
	}else if (document.all){
	//alert('all');
	return document.all(elementID);
	}else if (document.layers){
	//alert('layers');
	return document.layers(elementID);
	}else {
	alert('Cannot Access DHTML Elements.\n Please Check Your Browser.')
	}
}
function getElms(elementID){
	if (document.getElementsByName){
	return document.getElementsByName(elementID);
	}else if (document.elementID){
	return document.elementID;
	}else {
	alert('Cannot Access DHTML Elements.\n Please Check Your Browser.')
	}
}
function expandOrCollapse(pageID,eventObj){
	if (getElm(pageID).style.display=="none"){
	getElm(pageID).style.display="block";
	eventObj.src="images/minus.gif";
	}
	else{
	getElm(pageID).style.display="none";
	eventObj.src="images/plus.gif";
	}
}
//SubV: sets one input value and submits the whole corresponding form with all previously set values
//security is build in for user priviledge verification and denial of specific services
function SubV(IDname,IDvalue) {
		getElm(IDname).value = IDvalue;
//		getElm(IDname).parentElement.submit();
		getElm(IDname).form.submit();
}
//SetV: sets one input value of its corresponding form
function SetV(IDname,IDvalue) {
		getElm(IDname).value = IDvalue;
}
//SebF: submit form
function SubF(IDform){
getElm(IDform).submit();
}
//confirmDelete: pops confirmation box whenever "delete" is requested
function confirmDelete(IDname,IDvalue,IDtype)
{
	 var conf= confirm("Click OK will permanently delete\n" +"this " + IDtype + "!");
	 if (conf== true)
	 {
	  SubV(IDname,IDvalue);
	 }
	 else
	 {
	  return false;
	 }
}
//confirmDelete: pops confirmation box whenever "delete" is requested
function confirmDel(IDtype)
{
	 var conf= confirm("Click OK will permanently delete\n" +"this " + IDtype + "!");
	 if (conf== true)
	 {
	  return true;
	 }
	 else
	 {
	  return false;
	 }
}
//confirm action: pops confirmation box whenever a note worthy action is requested
function confirmAct(mesg)
{
	 var conf= confirm(mesg);
	 if (conf!= true)
	 {
	  return false;
	 }
}
//confirm action: pops confirmation box whenever a note worthy action is requested
function confirmAct(mesg)
{
	 var conf= confirm(mesg);
	 if (conf!= true)
	 {
	  return false;
	 }
}
//alert message
function alertMesg(mesg){
alert(mesg);
}
//display indicated item and hide previously selected item
function displayThis(touchID)
{
	if (touched!=-1){
	getElm(touched).style.display='none';
	touched=touchID;
	}
	else {
	touched=touchID;
	}
getElm(touchID).style.display='inline';
}

// Check if string s is empty or whitespace characters only.
function isWhitespace(s)
{   var i;
	var whitespace = " \t\n\r";
    // Is s empty?
    if (isEmpty(s)) return true;
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);
	if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
//man, more checks, this is on radio values
function radioValue(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue=s[i].value;
}
return selectedValue;
}
//this is on checkBox values
function checkBoxValue(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue+=s[i].value + ", ";
}
selectedValue=selectedValue.substr(0, selectedValue.length-2);
return selectedValue;
}
function checkBoxTitle(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue+=s[i].title + "\n";
}
//selectedValue=selectedValue.substr(0, selectedValue.length-2);
return selectedValue;
}
//return form check error mesg
function returnError(mesg,confirmMesg){
	if (mesg=="") {
		if (confirmMesg=="")
		return true;
		else{
		var conf= confirm(confirmMesg+"\n");
		if (conf==false) return false; 
		}
	return true;
	}
	else
	{
	alert(mesg);
	return false;
	}
}
//fileUploadFormCheck
function fileUploadFormCheck(){
var mesg="", confirmMesg=""
	if (isWhitespace(getElm("fileDescription").value)==true) mesg+="Description is empty\n";
	if (isWhitespace(getElm("fileName").value)==true) mesg+="File Name is empty\n";
return returnError(mesg,confirmMesg);
}

//PDF requrement fileUploadFormCheck
function pdfFileCheck(s){
var mesg="", confirmMesg=""
	if (/(\.pdf)+$/.test(s.value)!=true) mesg="PDF files only\n";

	if (mesg!="") {
	return returnError(mesg,"");
	s.focus();
	s.select();
	return false;
	}
}

//jpg,gif requrement fileUploadFormCheck
function imageFileCheck(s){
var mesg="", confirmMesg=""
	if (/((\.jpg)|(\.jpeg)|(\.bmp)|(\.gif)|(\.JPEG)|(\.BMP)|(\.GIF)|(\.JPG))+$/.test(s.value)!=true) mesg="JPG, GIF or BMP files only\n";

	if (mesg!="") {
	return returnError(mesg,"");
	s.focus();
	s.select();
	return false;
	}
}

// Check form value
function formValueCheck(s,checkMethod,methodOption){ //s is input object
var mesg=""
	switch (checkMethod){
	   case "number":
	   		if (isFinite(s.value)==false) mesg="Numbers only\n";
				break;
	   case "noNegative":
		 		if (s.value < 0) mesg="Value cannot be negative\n";
				break;
	   case "alpha":
		 		if (/[^A-Za-z\s]+/.test(s.value)==true) mesg="Alphabets only\n";
				break;
	   case "string":
		 		if (isWhitespace(s.value)==true) mesg="Value cannot be empty\n";
				break;
	   case "email":
		 		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(s.value)) && !(isWhitespace(s.value))) mesg="Not a valid email\n";
				break;
	   case "phone":
		 		switch (methodOption){
				case "allNum":
					if (!(/^\d{10}$/.test(s.value)) && !(isWhitespace(s.value))) {mesg="Phone number must be 10 digits in the following formats:\nxxxxxxxxxx";};
					break;
				case "dash":
					if (!(/^\d{3}-\d{3}-\d{4}$/.test(s.value)) && !(isWhitespace(s.value))) {mesg="Phone number must be in the following format:\nxxx-xxx-xxxx";};
					break;
				case "max":
					var re; 
					re = new RegExp("\\d{"+s.maxLength+"}","ig");
					if (re.test(s.value)==false && !(isWhitespace(s.value))) {mesg="This requires " +s.maxLength +" numbers"};
				default:
					break;
				}
				break;
	   default: 
	   		break;
	}
	
	if (mesg!="") {
	returnError(mesg,"");
	s.focus();
	s.select();
	return false;
	}
}

// General check for required fields of all inputs enclosed in a form
function generalFormCheck(s){ // s is a form object, the trick is in the alt
var formInputs=s.elements, mesg="", postFocus=""
for (i=0; i<formInputs.length; i++){
	if (isEmpty(formInputs[i].alt)==false && isWhitespace(formInputs[i].value)==true){
	mesg+=formInputs[i].alt +" is required\n";
		if (postFocus=="") postFocus=formInputs[i];
	}
}
	if (mesg!="") {
	postFocus.focus();
	return returnError(mesg,"");
	return false;
	}
}
// Advanced form check for required fields of selected inputs enclosed in a form
function advancedFormCheck(s,t){ // s is a form object, the trick is in the t; t is variable for the special parameter
var formInputs=s.elements, mesg="" //, postFocus=""
for (i=0; i<formInputs.length; i++){
	if (formInputs[i].attributes.getNamedItem(t) && isWhitespace(formInputs[i].value)==true){
	mesg+=formInputs[i].attributes.getNamedItem(t).value +" is required\n";
	}
}
	if (mesg!="") {
	return returnError(mesg,"");
	return false;
	}
}
//General check for matching values such as password and email entries, require alt attribute in input field
function checkMatch(s,t){
var mesg="", postFocus=""
if (getElm(s).value!=getElm(t).value){
mesg+=getElm(s).alt + " and " + getElm(t).alt + " must be the same.\n"
	if (postFocus=="") postFocus=getElm(s);
}
	if (mesg!="") {
	postFocus.focus();
	return returnError(mesg,"");
	return false;
	}
}
function calendarPopup(valueID){
//var CPheight,CPwidth 
//if(calendarPop){
//calendarPop.close();
//}
calendarPop=window.open('calendar_pop.asp?formValue='+valueID,'calendarPop','toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,titlebar=no,width=120,height=138');
//calendarPop.moveTo(event.screenX-event.offsetX-120, event.screenY-event.offsetY+event.srcElement.offsetHeight);
//calendarPop.moveTo(100, 100);
calendarPop.focus();

/*

calendarPop=window.open("calendar_pop.asp?formValue="+valueID,"calendarPop","toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no,width=120,height=138,screenX=0,left=(event.screenX-event.offsetX-120),screenY=0,top=(event.screenY-event.offsetY+event.srcElement.offsetHeight)");
calendarPop.moveTo(event.screenX-event.offsetX-120, event.screenY-event.offsetY+event.srcElement.offsetHeight);
calendarPop.focus();

calendarPop=window.open('calendar_pop.asp?formValue='+valueID,'calendarPop','toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=no,alwaysRaised,dependent,width=120,height=138,directories=no,screenX=0,screenY=0,left=event.screenX-event.offsetX-120,top=event.screenY-event.offsetY+event.srcElement.offsetHeight');
calendarPop.moveTo(event.screenX-event.offsetX-120, event.screenY-event.offsetY+event.srcElement.offsetHeight);
calendarPop.focus();

*/
//event.srcElement.height can be used in place of event.srcElement.offsetHeight but only works for image objects where it has a height
}
// popup for image display
var oPopup = window.createPopup();
function imagePop(imagePath,popWidth,popHeight,popX,popY)
{
    imageSizeControl="";
	if (popWidth<200){
	popWidth=200;
	}
	if (popWidth>400){
	popWidth=400;
	imageSizeControl="width=400";
	}
	if (popHeight>400){
	popHeight=400;
	imageSizeControl="height=400";
	}

	var oPopBody = oPopup.document.body;
    oPopBody.style.backgroundColor = "lightyellow";
    oPopBody.style.border = "solid black 1px";
    oPopBody.innerHTML = "<center style='font-size: 12px; font-weight: normal; font-family: Arial;'>Click outside <B>popup</B> to close.</center><table align=center><tr align=center><td><img src='" + imagePath + "' " + imageSizeControl + "></td></tr></table>";

	if (popX!=null && popY!=null) {
	oPopup.show(popX, popY-(popHeight+40), popWidth+40, popHeight+40, document.body);
	}
	else {
    //oPopup.show(200, 100, popWidth+40, popHeight+40, document.body);
    oPopup.show(event.clientX-event.offsetX-(popWidth+40), event.clientY-event.offsetY-(popHeight+40), popWidth+40, popHeight+40, document.body);
	}
}

//shipping Selection update
function shippingUpdate(shippingCost,grandTotal){
getElm('shippingCostText').innerText="$" + shippingCost + "   ";
getElm('shippingCostDisplay').innerText="$" + shippingCost + "   ";
getElm('shippingCost').value=shippingCost;
getElm('total').value=grandTotal;
getElm('grandTotalDisplay').innerText="$" + grandTotal + "   ";
getElm('submitButton').style.visibility="visible";
}
function formFiller(pageName,windowName,winWidth,winHeight){
windowName=window.open(pageName,windowName,'toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no,width='+winWidth+',height='+winHeight+',screenX=0,left='+(screen.width-winWidth)/2+',screenY=0,top='+(screen.availHeight-winHeight)/2+'');
windowName.focus();
}
function winOpener(pageName,windowName,winWidth,winHeight){
windowName=window.open(pageName,windowName,'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable,alwaysRaised,dependent,titlebar=no,width='+winWidth+',height='+winHeight+',screenX=0,left='+(screen.width-winWidth)/2+',screenY=0,top='+(screen.availHeight-winHeight)/2+'');
windowName.focus();
}

function logout(){
var timeoutMesg="Idle time has been more than 20 minutes, your account will be logged out for security.";
alert(timeoutMesg);
location.href="login.asp?do=logout";
}

//s=score or par
function scoreThatCard(s){
var scTot=0, scOut=0, scIn=0;
	for (i=1; i<=9; i++){
		if (isFinite(getElm(s+i).value)==true){
		scOut+=Number(getElm(s+i).value);
		}
	}
	for (i=10; i<=18; i++){
		if (isFinite(getElm(s+i).value)==true){
		scIn+=Number(getElm(s+i).value);
		}
	}
	
	getElm(s+'Out').value=scOut;
	getElm(s+'In').value=scIn;
	getElm(s+'Total').value=scOut+scIn;
}
/*
<SCRIPT language="jscript" RUNAT="Server">
var cityStr;
cityStr=decodeURI(request.querystring("city"));
</SCRIPT>
*/
// Your code goes here.