//===== relative URL handling code for js files ================
sWZBaseFolder = "www.smartappoint.com";                          
sWZ = window.location.href;                                     
iWZ = sWZ.indexOf(sWZBaseFolder) + sWZBaseFolder.length + 1;    
sWZBase = sWZ.substring(0,iWZ);                                 
//===== Copyright © 2001 Spidersoft. All rights reserved. ======

/////////////////////////////////////////////////////////////////////////////////////////
// Common routines
/////////////////////////////////////////////////////////////////////////////////////////

// Triggers a server event by appending the specified eventId to the form's query string
// and then submitting the form
function navOnClick(strEventId) {
	if (validateForm(strEventId) == true) {
		document.forms[0].action = document.forms[0].action + "?eventId=" + strEventId;
		document.forms[0].submit();
	}
}

// Returns a flag indicating if the ENTER key has been pressed
function isEnterKeyPressed() {
	if (window.event.keyCode == 13)
		return true;

	return false;
}

// Clicks on the specified form field
function clickField(strFieldName) {
	document.forms[0].elements[strFieldName].click();
}

// Clicks on the specified radio button
function clickRadioButton(strFieldName, intIndex) {
	document.forms[0].elements[strFieldName].item(intIndex).click();
}

// Sets the contents of the specified form field to the specified value
function setFieldValue(strFieldName, strFieldValue) {
	document.forms[0].elements[strFieldName].value = strFieldValue;
}

// Returns the contents of the specified form field
function getFieldValue(strFieldName) {
	return document.forms[0].item(strFieldName).value;
}

// Returns a flag indicating if the specified dropdown list item is selected
function isDropdownSelected(strFieldName, intIndex) {
	return document.forms[0].elements[strFieldName].options(intIndex).selected;
}

// Returns a flag indicating if the specified radio button is selected
function isRadioButtonSelected(strFieldName, intIndex) {
	return document.forms[0].elements[strFieldName].item(intIndex).checked;
}

// Returns a flag indicating if the specified checkbox is selected
function isCheckboxSelected(strFieldName) {
	return document.forms[0].elements[strFieldName].checked;
}

// Returns the length of data in the specified form field
function fieldLength(strFieldName) {
	var strFieldValue;
	
	strFieldValue = document.forms(0).item(strFieldName);
	
	if (strFieldValue == null)
		return 0;
		
	return strFieldValue.value.length;
}

// Returns a flag indicating if the contents of the specified form field are numeric
function isNumeric(strFieldName) {
	var intFieldValue;
	var intLength;

	intFieldValue = getFieldValue(strFieldName);
	
	if ( isNaN(Math.abs(intFieldValue)) ) {
		if (isNumeric.arguments.length == 1)
			return false;
	}

	return true;
}

// Returns a flag indicating if the contents of the specified phone# field are valid
function isPhoneNoOK(strFieldName) {
	var strFieldValue;
	var strValidCharacters;
	var intLength;
	var intField;

	strFieldValue = getFieldValue(strFieldName);
	strValidCharacters = "0123456789()-+ ";

	for (var i=0; i < strFieldValue.length; i++) {
		intField = strFieldValue.substring(i, i+1);
		if (strValidCharacters.indexOf(intField) == -1) {
			return false;
		}
	}

	return true;
}

// Checks if the contents of specified form field are alphabetic
function isAlphabetic(strFieldName){
	var re, strFieldValue, intLength, valid;
	
	strFieldValue = document.forms(0).item(strFieldName).value;
	
	re = new RegExp("[^a-z\-\' ]","gi");
	
	if(strFieldValue.match(re) == null)
		return true;

	return false;
}

// Returns a flag indicating if the contents of the specified form field are a valid date
function isValidDate(strDayFieldName, strMonthFieldName, strYearFieldName) {
	
	var intDayFieldValue;
	var intMonthFieldValue;
	var intYearFieldValue;

	// Numeric field Checking
	if (!isNumeric(strDayFieldName) )
		return false;

	if (!isNumeric(strMonthFieldName) )
		return false;

	if (!isNumeric(strYearFieldName) )
		return false;

	intDayFieldValue = parseInt(getFieldValue(strDayFieldName), 10);
	intMonthFieldValue = parseInt(getFieldValue(strMonthFieldName), 10);
	intYearFieldValue = parseInt(getFieldValue(strYearFieldName), 10);

	// Day field validation
	if (intDayFieldValue < 1 || intDayFieldValue > 31)
		return false;

	// Month field validation
	if (intMonthFieldValue < 1 || intMonthFieldValue > 12)
		return false;

	// Year field validation
	if (intYearFieldValue == "0000")
		return false;
	
	return true;
}

// Returns a flag indicating if the contents of the specified form field are a valid time
function isValidTime(strHourFieldName, strMinuteFieldName) {
	var intHourFieldValue;
	var intMinuteFieldValue;

	// Numeric field checking
	if (!isNumeric(strHourFieldName) )
		return false;

	if (!isNumeric(strMinuteFieldName) )
		return false;

	intHourFieldValue = parseInt(getFieldValue(strHourFieldName), 10);
	intMinuteFieldValue = parseInt(getFieldValue(strMinuteFieldName), 10);


	// Hour field validation
	if (intHourFieldValue < 0 || intHourFieldValue > 23)
		return false;

	// Minute field validation
	if (intMinuteFieldValue < 0 || intMinuteFieldValue > 59)
		return false;

	return true;
}

// Checks if the specified form field is a valid email address - must contain @ symbol
function isEmailAddress(strFieldName){
	var strFieldValue;

	strFieldValue = document.forms(0).item(strFieldName).value;
	
	if ( (strFieldValue.indexOf("@") != -1) && (strFieldValue.indexOf(".") != -1) ) 
		return true;

	return false;
}

// Sets the cursor position back to form field if error
function gotoField(strFieldName) {
	document.forms(0).item(strFieldName).focus();
	document.forms(0).item(strFieldName).select();
}

// Sets the class of the specified form field to 'enabled field' style
function enableField(strFieldName) {
	with (document.forms[0].elements[strFieldName]) {
		disabled = false;
		className = "enabledField";
	}
}

// Sets the class of the specified form field to 'disabled field' style
function disableField(strFieldName) {
	with (document.forms[0].elements[strFieldName]) {
		disabled = true;
		value = "";
		className = "disabledField";
	}
}

// Displays an error message and returns FALSE to the caller
function errorMsg(strMsg) {
	alert(strMsg);
	
	return false;
}

// Displays a yes/no prompt and returns the selected outcome (TRUE/FALSE) to the caller
function warningMsg(strMsg) {
	return confirm(strMsg);
}

// Displays an information message and returns TRUE to the caller
function infoMsg(strMsg) {
	alert(strMsg);
	
	return true;
}

// Returns the current ActivityId for the screen
function getThisActivityId() {
	var strActivityId = getFieldValue("_activityId");

	return strActivityId;
}

// Get Cookie Value function
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape (document.cookie.substring(offset, endstr));
}

// Get Cookie function
function GetCookie(name) {
	var arg = name+"=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
   }
   return null;
}
