//*******************//
//validation.js
//*******************//
var screenWidth, screenHeight
var isMapVisible = false 
var dateNow		 = ""
var timenow		 = ""
var yearNow		 = new Date() 

var thisYear	 = yearNow.getYear()
var mm			 = yearNow.getMonth()
var dd			 = yearNow.getDate()
var inputErrorMsg="The following data or fields are incomplete or inaccurate: \n"

if (thisYear < 2000) {
	thisYear	= 1900 + thisYear
   //alert(thisYear)
}
var yyyy		= thisYear
var enddate		= new Date()
var payBtnText  = "Finish"


//-----------browser details------------------//

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}


//-----------end browser details------------------//




/**
 * Array.prototype.[method name] allows you to define/overwrite an objects method
 * needle is the item you are searching for
 * this is a special variable that refers to "this" instance of an Array.
 * returns true if needle is in the array, and false otherwise
 * test
 * words = new Array(3,4,87,5,98,5,105);
 * alert("Array: " + words + " Indices Found:  " + words.AllIndicesOf(5)); 
 */
Array.prototype.AllIndicesOf = function( needle ) {
	var inds="";
	for (i=0; i<this.length; i++ ) 
	{	
		if (this[i] == needle) {
			if (inds=="") {
				inds=i.toString();
			}
			else {
				inds += "," + i.toString();
			}
		}
	}
	return inds;
}



function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function searchArrayItem(arrN,str) 
{
	var i;
	if (isArray(arrN)) {
		for ( i=0; i<arrN.length; i++ ) {
			if (str == arrN[i].toString) {
				return true
			}	
		}
	}	
	return false
}

function jsDDSelectorArray(arrExcludes, selname, arrValues, arrFilters, filterValue, selectedVal, strEventHandler, cssClass, isEnabled) 
{
	var ddText="<select name=" + selname;
	var classTag = (cssClass.length==0)? "" : " class=" + cssClass ;
	var enabledTag = (isEnabled)? "" : " disabled " ;
	ddText = ddText + enabledTag + classTag + strEventHandler + ">";
	
	if (!isArray(arrValues)) {
		arrValues=arrValues.split(",");
	}
	if (!isArray(arrExcludes)) {
		arrExcludes=arrExcludes.split(",");
	}

	if (selectedVal=="") {
		ddText = ddText + "<option value=''>-- Select --<\/option>";
	}
	
	for (x=0; x < arrValues.length; x++) {
		if (arrFilters[x] == filterValue) {
			if (!searchArrayItem(arrExcludes,arrValues[x])) {
				ddText = ddText +  "<option " + ((arrValues[x] == selectedVal)? "selected" : '' ) + " value='" + arrValues[x] + "'>" + arrValues[x] + "<\/option>";
			}
		}
	}

	ddText = ddText +  "<\/select>";
	return(ddText);
}


function getChildArray(parentString)
{
	var p=parentString.toLowerCase();
	if (p=='hosting')
		return "Windows,Linux";
	if (p=='web development')
		return "Packaged,Tailored";
	if (p=='windows software')
		return "As Quoted"
	else
		return "Others"	
}

function reviseChildOptions(parentArray, selectedParentValue, chldElement)
{
	var f = eval("document.forms['form0']." + chldElement);
	f.options.length = 0;
	var x,	i = 0;
	var strOptions=""
	var childArray=getChildArray(selectedParentValue)
	if (!isArray(childArray)) {
		childArray=childArray.split(",");
	}
	for (x=0; x < childArray.length; x++) {
		f.options[x] = new Option(childArray[x],childArray[x])
	}
	if (x)
		eval(f.options[0].selected=true);
	eval(f.options.length=x);
}




function reviseChildOptionsOld(parentArray, selectedParentValue, chldElement, childArray)
{
	var f = eval("document.forms['form0']." + chldElement);
	f.options.length = 0;
	var x,	i = 0;
	var strOptions=""
	for (x=0; x < childArray.length; x++) {
		if (parentArray[x] == selectedParentValue) {
			if (strOptions.indexOf(childArray[x])==-1 ) {
				f.options[i] = new Option(childArray[x],childArray[x])
				strOptions +=childArray[x] + ", ";
				i++;
			}
		}
	}
	if (i)
		eval(f.options[0].selected=true);
	eval(f.options.length=i);
}


function noPriorInclusion(o, n, el){
	var f = eval("document.forms['form0']." + o);
	for (p=0; p<n; p++) {
		alert("previous " + p + " item " + f.options[p].toString())
		if (f.options[p]==el) {
			return false;
		}
	}
	return true;
}



//Adds new uniqueArr values to temp array
function uniqueArr(a) {
 temp = new Array();
 for(i=0;i<a.length;i++){
  if(!contains(temp, a[i])){
   temp.length+=1;
   temp[temp.length-1]=a[i];
  }
 }
 return temp;
}
 
//Will check for the Uniqueness
function contains(a, e) {
 for(j=0;j<a.length;j++)if(a[j]==e)return true;
 return false;
}


//Get ArrayIndex
function getArrIndex(a,e){
for(j=0;j<a.length;j++)if(a[j]==e)return j;
 return -1;
}


//scroller objects & functions

function anObject(parentId, selfRef, width, height, id, xDir, yDir, title, href, html)
{
	this.parentId		= parentId;
	this.selRef			= selfRef;
	this.size			= selfRef.size;
    this.width			= parseInt(width);
    this.height			= parseInt(height);
	this.id				= id;
	this.xDir			= xDir; //note: 0=no movement; 1=left->right; 2=right->left;
	this.yDir			= yDir; //note: 0=no movement; 1=top->bottom; 2=bottom->top;  
	this.title			= title;
	this.href			= href;
	this.html			= html;
	this.nHops			= this.height*2; //iterations required
	this.xLeap			= Math.round(this.width/this.nHops)
	this.yLeap			= Math.round(this.height/this.nHops)
	switch (this.xDir) {
		case 0:
			this.xMin = 0;
			this.xMax = 0;
			break;
		case 1:
			this.xMin = 0
			this.xMax = width;
			break;
		case 2:
			this.xMin = width * -1;
			this.xMax = width;
			break;
	}
			
	switch (this.yDir) {
		case 0:
			this.yMin = 0;
			this.yMax = 0;
			break;
		case 1:
			this.yMin = 0
			this.yMax = height;
			break;
	 	case 2: 
			this.yMin = height * -1;
			this.yMax = height;
			break;
	}

	this.show	= '<div id=' + id + ' style="position:relative;' + ((width=='')? '': ' width:' + width + 'px; ') +  ((height=='')? '': ' height:' + height + 'px; ') + ' visibility:hidden;">' +
				   ((href=="")? title : '<a href="' + href + '"><img height=13 border=0 align=absmiddle src="/images/navigate.jpg" /> '+ title + '</a>') + '<br />' + html +'</div>';
		   
}







function scrollObject(oArr)
{
	setTimeout(function(){scroller(oArr)},10)
}




function scroller(oRef) 
{
	this.oRef			= oRef;
	this.size			= oRef.length;
	
	
	
	
	var myObj			= this;
	var o, oCanvas, oParent;
	var xLoc, yLoc;
	var canvasWidth, parentWidth, halfWidthDefference ;
	
	for (var x=0; x < this.size; x++) {
		this.currentElement	= x;
		o = this.oRef[this.currentElement];
		
		
		for (var y=0; y < o.nHops; y++) {
			this.iterationCount = y;
			if (this.iterationCount==0) 
			{
					
				//do not move these 2 lines above where they are
				
				oCanvas	= document.getElementById(o.id);
				oParent = document.getElementById(o.parentId);
				canvasWidth = parseInt(oCanvas.style.width);
				parentWidth = parseInt(oParent.style.width);
				parentHeight = parseInt(oParent.style.height);
				halfWidthDifference=(parentWidth - canvasWidth)/2;
				//oCanvas.style.zIndex= (this.currentElement + 1);
				
				
				
				//Start with the initial position
					
				if (o.xDir==2){oCanvas.style.left = o.xMax + "px";}
				else{oCanvas.style.left = o.xMin + "px";}
				if (o.yDir==2){oCanvas.style.top  = o.yMax + "px";}
				else{oCanvas.style.top  = o.yMin + "px";}
					
					
				if (o.width > parentWidth && o.xDir==2) {
					oCanvas.style.left = parentWidth;
					this.iterationCount = parentWidth;
					//o.xMax = parentWidth;
				}
						
						
				if (o.height > parentHeight && o.yDir==2) {
					oCanvas.style.top=parentHeight;
					this.iterationCount = parentHeight;
					//o.yMax=parentHeight;
				}
			}
		
		
			xLoc = parseInt(oCanvas.style.left);
			yLoc = parseInt(oCanvas.style.top);
			switch (o.xDir) {
				case 0:
					xLoc = 0;
					break;
				case 1:
					xLoc += o.xLeap;
					if (xLoc > o.xMax) {xLoc = o.xMax;}
					break;
				case 2:
					xLoc -= o.xLeap;
					if (xLoc < o.xMin) {xLoc = o.xMin;}
					break;
			}
			switch (o.yDir) {
				case 0:
					yLoc = 0;
					break;
				case 1:
					yLoc += o.yLeap;
					if (yLoc > o.yMax) {yLoc = o.yMax;}
					break;
				case 2:
					yLoc -= o.yLeap;
					if (yLoc < o.yMin) {yLoc = o.yMin;}
					break;
			}
				
				
				
			xLoc = halfWidthDifference + xLoc
			oCanvas.style.left = xLoc + "px";
			oCanvas.style.top  = yLoc + "px";
			oCanvas.style.visibility="visible";	
			
		}	
		//at end of iterations :: finished element iterations	
		if (this.iterationCount == o.nHops) {	
			oCanvas.style.visibility="hidden";
		}
	}
	//at end of element array :: finished elements array
	if (this.currentElement == this.size) {
		this.currentElement = 0;
		this.iterationCount = 0;
	}			

	/*
	alert("iCount: " + this.iterationCount + "\nElement...: " + (parseInt(this.currentElement) + 1) + "\nId...: " + o.id +  "\nLeft...: " + oCanvas.style.left +   "\nTop...: " + oCanvas.style.top +  "\nVisibility...: " + oCanvas.style.visibility +
		"\n [xMin: " + o.xMin + " xMax: " + o.xMax + " yMin: " + o.yMin + " yMax: " + o.yMax + " xLeap: " + o.xLeap + " yLeap: " + o.yLeap + "]" + 
			"\nxLoc: " + xLoc + "\nyLoc: " + yLoc );
	*/
					
	scrollObject(oRef)
}



//end scroller functions


function newSelection(nIndexNo,newOpt){
	
	var dad=ddDaisyArr[nIndexNo]
	var son=ddDaisyArr[nIndexNo+1] //can't exceed upperbound because was checked before
	var dadVarName=eval("document.forms['form0']."+dad.selVarName)
	var sonVarName=eval("document.forms['form0']."+son.selVarName)
	//alert(son.selVarName)
	if (dadVarName.options[newOpt]==null) {
		sonVarName.options.length=0
		if (readOnly) {
			alert("X - No " + dad.selVarName + " exists for selection...\n\n - select another group\n ")
		}
		else 
		{
			alert("X - No " + dad.selVarName + " exists for selection...\n\nYour options:\n - select another group\n - create a new Category and then a Subcategory...")
			eval('document.forms["form0"].'+dad.selVarName+'_entry').value=0
			eval('document.forms["form0"].'+son.selVarName+'_entry').value=0
		}	
	}
	else {
		if (!readOnly) {
			eval('document.forms["form0"].'+son.selVarName+'_entry').value=1
		}
		var dadText
		dadText=dadVarName.options[newOpt].text
		dad.currentSelection=newOpt //firstly change the parent arrays selection index
		var len =eval(son.arrayName.length)
		var displayOptions = sonVarName.options 
		displayOptions.length=len //start with the full array length assume all items 
		var j = 0 // new options counter
		//this next three lines are new for all options
		displayOptions[j].value = 0
		displayOptions[j].text = "All"
		j++
		for (var i=0; i < len; i++) {
			if (dadText==son.arrayName[i].parentName) {
				displayOptions[j].value = son.arrayName[i].recId
				displayOptions[j].text = son.arrayName[i].recDesc
				j++
			}
		}
		if (j>1) {
			eval(sonVarName.options[0].selected=true)
		}
		else {
			if (!readOnly)
				eval('document.forms["form0"].'+son.selVarName+'_entry').value=0
		}
				
		eval(displayOptions.length = j)
		//alert(ddDaisyArr.length)
		if (ddDaisyArr.length > nIndexNo+2) 
			newSelection(nIndexNo+1,0)
	}
}

















enddate.setTime(enddate.getTime()+(60*60*24*1000*1460))
screenWidth		=	screen.availWidth
screenHeight	=	screen.availHeight
SetCookie("screenWidth", screen.availWidth, enddate)
SetCookie("screenHeight", screen.availHeight, enddate)

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf(";",offset);
	if (endstr == -1)
		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

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;
	}
	if (name=="Login") { 
		return "Visitor"; 
	} 
	else {
		return null;
	}
}


function SetCookie( name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() :"") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "")+
	((secure) ? "; secure" : "");
}

function DeleteCookie( name, path, domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "")+
		"; expires= Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function getQueryString(strQs)
{
	var readFrom, ret=""
	if (strQs!="") {
		var arrQueryStrings = new Array()
		var qryStr=unescape(location.search)
	
		arrQueryStrings=qryStr.split("&")
		for (var i=0;i<arrQueryStrings.length;i++) {
			if (arrQueryStrings[i].indexOf(strQs)!=-1) 	{
				readFrom=arrQueryStrings[i].indexOf("=")+1
				ret=arrQueryStrings[i].substr(readFrom)
				break
			}
		}
	}
	return(ret)		
}
if (top!=self){
  top.location=location
}
function PopupDomainStatus(checkdom) {
	tgturl="http://www.aunic.net/cgi-bin/namestatus.pl?domain-name=" + checkdom +"&html-form=no"
	//alert(tgturl)
	newWindow = window.open("","", "toolbar=yes, scrollbars=yes status=no, menubar=yes, resizable=yes, width=790, height=600");
	newWindow.location="domquery.asp?"+tgturl
	newWindow.focus();
}

function show(dv)
{
document.getElementById(dv).style.visibility='visible';
}

function hide(dv)
{
document.getElementById(dv).style.visibility='hidden';
}


function showHideDivs(d)
{
	
	for (i=0; i < smPortfolio.length; i++) {
		divId="s"+i
		document.getElementById(divId).style.visibility = (i==d) ? "visible" : "hidden"
	}
}

function showHide(dname)
{
	if (dname=='loginDiv')  {
		//document.getElementById('indiv').style.zIndex="-1"
		//document.getElementById('org').style.zIndex="-1"
		document.getElementById('accountDiv').style.visibility='hidden'
		document.getElementById('loginDiv').style.visibility='visible'
	}
	else {
		//document.getElementById('indiv').style.zIndex="1"
		//document.getElementById('org').style.zIndex="1"
		//document.getElementById('loginDiv').style.visibility='hidden'
		document.getElementById('accountDiv').style.visibility='visible'
	}	
}			

function showDiv(divName,startDiv,maxDivs)
{
	//alert(divName + ", " +startDiv+ ", " +maxDivs)
	hideAllDivs(startDiv,maxDivs);
	document.getElementById("d"+divName.toString()).style.visibility="visible";
}
		
function hideAllDivs(minDivNo,maxDivisions)	
{
	for (var i=minDivNo;i<=maxDivisions;i++) {
		document.getElementById("d"+i.toString()).style.visibility="hidden";
	}
}
function showDivById(divNo, divNamePrefix, nStart, nEnd)
{
	var str = new String(divNo)
	hideAllDivsById(divNamePrefix, nStart, nEnd);
	document.getElementById(divNamePrefix+str).style.visibility="visible";
}
		
function hideAllDivsById(divNamePrefix,minD,maxD)	
{
	var str
	for (var i=minD; i<=maxD;i++)  {
		str = new String(i)
		document.getElementById(divNamePrefix+str).style.visibility="hidden";
	}
}

function showMap()
{
	document.getElementById("locMap").style.visibility="visible";
	isMapVisible = true
	document.getElementById("vuMap").innerHTML ="Hide Map"
}
		
function hideMap()	
{
	document.getElementById("locMap").style.visibility="hidden";
	isMapVisible = false
	document.getElementById("vuMap").innerHTML = "Show Map"
}

function changeOpacity(id, op)
{
	var obj  = document.getElementById(id);
	//var brzr = obj.filters ? "ie" : typeof obj.style.MozOpacity=="string"? "mozilla" : ""
	//alert(browserName)
	
	
	
	if (browserName == "Microsoft Internet Explorer")
		obj.filters.alpha.opacity=parseInt(op);
	else {
	
		if (browserName == "Firefox")
			obj.style.MozOpacity=op/100;
		else
			obj.style.opacity = parseInt(op)/100;
		
	}
}


function showAsSelected(menuItem)
{
	document.getElementById(menuItem).style.color="#ffffff"
	document.getElementById(menuItem).style.background="#f08000"
}

function TimeMessage()
{
	var len = 4
	var today=new Date()
	var sec = today.getSeconds()
	var mins=today.getMinutes()
		mins=(mins<10)?"0"+mins:mins
	var hrs=today.getHours()
	var days=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
	var mths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	var mssg=(hrs<12)?"Good Morning":(hrs>16)?"Good Evening":"Good Afternoon"
	var dateRightNow=today.getDate()+' '+mths[today.getMonth()]+' '+thisYear
	var timeRightNow=hrs+":"+mins
	var ap=(hrs>11)?"pm ":"am "

	
	return(days[today.getDay()]+' '+dateRightNow+' '+timeRightNow+':'+ap+'<br /><b>'+mssg+'</b>')
}


function currentDate() {
	
	
	dd=yearNow.getDate()
	mm=yearNow.getMonth()+1
	return(thisYear+"/"+mm+"/"+dd);
	
}
dateNow=currentDate();
function isEmpty(s) {
	if (s==null || s=="") {
		return true
	}
	else {
		return false
	}
}

function isEmail(e) {
	if (e==null || e=="" || e.indexOf("@")== -1 || e.indexOf("@")==0 || e.indexOf("@")==e.length || e.indexOf(".")==-1 || e.indexOf(".")==0 || e.indexOf(".")==e.length) {
		return false;
	}
	else {
		return true;
	}
}

function isNumeric(e) {
	var theDecimal= false
	var inStr=e.toString()
	
	for (var i=0; i<inStr.length;i++) {
		var theChar=inStr.charAt(i)
		if (theChar <"0" || theChar>"9") {	
			return false
		}	
	}	
	return true;
}

function isDigit(e) {
	
	inStr=e.toString()
	if (inStr=="") {
		return false
	}	
	for (var i=0; i<inStr.length;i++) {
		var theChar=inStr.charAt(i)
		if (theChar <"0" || theChar>"9") {	
			return false
		}	
	}	
	return true;
}

function isYear(e) {
	if (!isDigit(e)) {
		return false
	}	
	else {
		inStr=e.toString()
		if (inStr.length !=4){
			return false
		}	
		return true	
	}
}
	
function isPassword(p) {
	if (p==null || p=="" || p.length < 6) {
		//alert("Password must have at least 6 characters or digits")
		return false
	}
	else {
		return true
	}
}
var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
function checkDaysInMonth(y,m,d) {
	leapyr= (y % 4 > 0)?false:true
	daysInMonth[1]=(leapyr)?29:28
	return (d > daysInMonth[m - 1])?false:true	
}		    
		
			
function isValid_DMY_Date(d) {
	//alert("date: " + d)
	if (d.length != 10) {
		return false
	}
	var dd=d.substring(0,2)
	var mm=d.substring(3,5)
	var yyyy=d.substring(6, d.length)
	
	
	if (isEmpty(d)) {
		//alert(d +" " +"Date is empty")
		return false
	}
	if (dd.length >2) {
		//alert("Day part of date must be two digits")
		return false
	}
	
	if (mm.length > 2 || mm < 1 || mm >12) {
		//alert("Month must be two digits and one of 01, 02... to 12")
		return false	
	}
	
	if (yyyy.length !=4) {
		//alert("Year must be 4 digits")
		return false
	}	
	
	if (!checkDaysInMonth(yyyy, mm, dd)) {
		//alert("Wrong date in month")
		return false
	}
	delim1=d.charAt(2)
	delim2=d.charAt(5)
	
	if (delim1 !="/" && delim1 !="-"){
		//alert("Invalid delimiters")	
		return false
	}
	if (delim1 != delim2 ) {
		//alert("Two delimiters are different")	
		return false	
	}	
	else
		return true
}

/*credit card checking routines -checkdigit, checksum, Luhn Algorithm
/*credit card validation procedures

function checkLuhn(cc) {
    var i, nDigits, parity, sum = 0
    cc = cc.toString()
    nDigits = cc.length
	parity = nDigits % 2
	for (i=0; i<nDigits; i++) {
		var digit = parseInt(cc.charAt(i))
		if ((i % 2) == parity)
			digit = digit * 2
        if (digit > 9)
            digit = digit - 9 
        sum = sum + digit
     }
     return ((sum % 10) == 0)
 }
 
 function isValidCCE(ccname,num)
 {
	var nLen,pfx
	
	if(isEmpty(ccname) || isEmpty(num) || !isNumeric(num))
		return (false)
	nLen = num.length
	
	switch(ccname) {
		case "American Express": {
			if(nLen == 15) {
				pfx = parseInt(num.substr(0,2))
				if (pfx == 34 || pfx == 37) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Visa Card": {
			if(nLen == 16 || nLen==13)  {
				pfx = parseInt(num.substr(0,1))
				if (pfx == 4) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Master Card": {
			if(nLen == 16)  {
				pfx = parseInt(num.substr(0,1))
				if (pfx > 50 && pfx < 56) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Diners Club": {
			if(nLen == 14) { 
				pfx = parseInt(num.substr(0,3))
				if (pfx > 299 && pfx < 306) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		
		case "JCB": {
			if(nLen == 16) {
				pfx = parseInt(num.substr(0,1))
				if (pfx==3) {
					if (checkLuhn(num))
						return (true)
				}
			}
			else {
				if(nLen == 15)  {
					pfx = parseInt(num.substr(0,4))
					if (pfx==2131 || pfx==1800) {
						if (checkLuhn(num))
							return (true)
					}
				}
			}
			break;
		}
	}
	return (false)
}

function checkCreditCardEntry()
{
	var f = document.form0
	//alert("CardNo.: " + f.BkCType.value + f.BkCNo.value)
	if (!isValidCCE(f.BkCType.value, f.BkCNo.value))
		alert("Credit card number entry is not valid.\n Please check and retry.\n")
}
// end credit card validation routines
*/

/* proofing online visitor is not a form submit bot */
var botProofString
var grafxFontArr=new Array(36)
grafxFontArr[0]="0.gif"
grafxFontArr[1]="1.gif"
grafxFontArr[2]="2.gif"
grafxFontArr[3]="3.gif"
grafxFontArr[4]="4.gif"
grafxFontArr[5]="5.gif"
grafxFontArr[6]="6.gif"
grafxFontArr[7]="7.gif"
grafxFontArr[8]="8.gif"
grafxFontArr[9]="9.gif"
grafxFontArr[10]="a.gif"
grafxFontArr[11]="b.gif"
grafxFontArr[12]="c.gif"
grafxFontArr[13]="d.gif"
grafxFontArr[14]="e.gif"
grafxFontArr[15]="f.gif"
grafxFontArr[16]="g.gif"
grafxFontArr[17]="h.gif"
grafxFontArr[18]="i.gif"
grafxFontArr[19]="j.gif"
grafxFontArr[20]="k.gif"
grafxFontArr[21]="l.gif"
grafxFontArr[22]="m.gif"
grafxFontArr[23]="n.gif"
grafxFontArr[24]="o.gif"
grafxFontArr[25]="p.gif"
grafxFontArr[26]="q.gif"
grafxFontArr[27]="r.gif"
grafxFontArr[28]="s.gif"
grafxFontArr[29]="t.gif"
grafxFontArr[30]="u.gif"
grafxFontArr[31]="v.gif"
grafxFontArr[32]="w.gif"
grafxFontArr[33]="x.gif"
grafxFontArr[34]="y.gif"
grafxFontArr[35]="z.gif"

function proofUserEntry(frm,entry)
{
	if (entry != botProofString) {
		frm.ovs.value=""
		alert("Verification string entered does not match the one displayed.")
		//location.reload()
	}
	else {
		//document.getElementById("actualForm").style.visibility="visible"
		//isHuman(frm)
		//frm.vfd.value=botProofString +'<%=checkASPValue4This%>'
		frm.vfd.value=frm.ovs.value + frm.ftype.value
	}
}

function printGrafxNumber(nmb)
{
	var asciiCode,ndx,grafxHtml=""
	for (x=0;x<6;x++) {
		asciiCode=nmb.charCodeAt(x)
		if (asciiCode > 96) 
			ndx=asciiCode-87 // take 96 and add 10
		else
			ndx=asciiCode-48
		grafxHtml=grafxHtml+'<img src="/ssl/images/grafx/'+grafxFontArr[ndx]+'" width="30" height="30" alt="">'
	}
	document.write(grafxHtml)	
}

function genrateAlphaNumericRandomString()
{
	var chr,ndx,ANRString=""
	for (x=0;x<6;x++) {
		ndx=Math.round(Math.random()* 35)
		chr=grafxFontArr[ndx].charAt(0)
		ANRString=ANRString+chr
	}
	botProofString=ANRString
}
function isHuman(f)
{
	f.vfd.value=botProofString +'<%=checkASPValue4This%>'
}

/* eop: proofing online visitor is not a form submit bot */

function getRadioButtonSelectedValue(n)
{
	for (var i=0; i<n.length; i++){
		if (n[i].checked)
			return(n[i].value)
	}
	return ""
			
}


function getCBSelectedValue(n)
{
	var cbItems = ""
	
	for (var i=0; i<n.length; i++){
			if (cbItems=="")
				cbItems = n[i].value
			else
				cbItems += ", " + n[i].value
	}
	document.forms["0"].selected_modules.value=cbItems
	return cbItems
}
function PopUpWin(url_n_actions, height, width)
{
	windowOpener(url_n_actions, 'visible', height, width, 10, 10,'','',0,0,0,0,1)
}


function getServerResponse(urlaction,file2read,field2read,return2form,return2field,paraname,paravalue,paratype)
{
	if (paravalue !="")
		windowOpener("include/return2server.asp?action="+ urlaction + "&file2read=" + file2read + "&field2read=" + field2read + "&return2form=" + return2form + "&return2field=" + return2field + "&paraname=" + paraname + "&paravalue=" + paravalue + "&paratype=" + paratype, 'hidden', 1, 1, 10, 10,'','',0,0,0,0,1)
}

function AddItemTotals(f)
{
	if (f.Hours2Book=="")
		f.Hours2Book.value=0
		
	f.HireCost.value=parseFloat(f.Hours2Book.value) * parseFloat(f.HireCostPerHr.value)
	f.HireCharge.value=parseFloat(f.Hours2Book.value)* parseFloat(f.HireChargePerHr.value)
	f.TotalCost.value=parseFloat(f.HireCost.value)+parseFloat(f.FloatCost.value)+parseFloat(f.ReturnFloatCost.value)+parseFloat(f.EscortCost.value)+parseFloat(f.NightCost.value)+parseFloat(f.OTCost.value)
	f.TotalPrice.value=parseFloat(f.HireCharge.value)+parseFloat(f.Floatage.value)+parseFloat(f.ReturnFloatage.value)+parseFloat(f.EscortCharge.value)+parseFloat(f.NightCharge.value)+parseFloat(f.OTCharge.value)
}

function windowOpener(URL, wName, pheight, pwidth, pscrollbars, ptop, pleft, plocation, pdirectories, pstatus, pmenubar, ptoolbar, presizable) {
	sParams = "height=" + pheight + ",width=" + pwidth + ",top=" + ptop + ",left=" + pleft + ",location=" + plocation + ",directories=" + pdirectories + ",status=" + pstatus + ",menubar=" + pmenubar + ",toolbar=" + ptoolbar + ",resizable=" + presizable + ",scrollbars=" + pscrollbars;
	newWindow = window.open(URL, wName, sParams);
	newWindow.focus();
}
function getContextHelp(topic,topicHeading)
{
	helpContextWin=window.open("contexthelp.asp?topic=" + topic + "&content=" + topicHeading , "" , "toolbar=false, status=false, scrollbars, menubar=false, resizable, width=500, height=350")
	helpContextWin.focus()
}
function StateSelector(id, stateFieldName, stateNameFieldName, nextField2Focus) {
	sParams = "height=500,width=300,top=30,left=30,scrollbars=yes";
	sUrl = "/ssl/include/getState.asp?id=" + id + "&statefieldname="+ stateFieldName + "&statenamefieldname=" + stateNameFieldName + "&nextField2Focus=" + nextField2Focus;
	newWindow = window.open(sUrl, "States", sParams);
	if (!newWindow) {
		alert("Your browser has blocked a popup window this program needs to show states/provinces/regions of the selected country. Please allow popup blocker, at least for this site or just for now, in order for this page to be displayed. Then click the state/province/region box on the form to retry.");
	}
	else {
		newWindow.focus();
	}	
	//windowOpener(sUrl, "States", 500, 340, "yes", 30, 30, "no", "no", "no", "no", "no", "no");
	
}
function BlurState(nextField) {
	//alert("This is a read-only data - for the selected country. To change select a new country.");
	var f="document.form0."+nextField
	//document.form0.entxt.focus();
	eval(f).focus()
}

function checkCardInput()
{
	var m, f=document.forms['ccpay0']
	m=""  
	r=radioButtonSelected(f.EPS_CARDTYPE)
	if (r=="")
		m+=". a cardtype must be selected\n"
	if (isEmpty(f.EPS_CARDNUMBER.value) || (f.EPS_CARDNUMBER.value).length<12 || (f.EPS_CARDNUMBER.value).length>18)
		m+=". cardnumber input is not valid\n" 
	if (isEmpty(f.EPS_NAMEONCARD.value))
		m+=". name on card is empty or invalid\n"
	if (m != "")
		alert("The following fields are incorrect or empty:\n\n"+ m)
	else {
		f.submit()	
	}	
}

function checkRequestSelected()
{
	var f=document.forms["form0"]
	for (var i=0; i < f.inewrequest.length; i++) {
		if (f.inewrequest[i].checked) {
			break
		}
	}
	if (i == 0) {
		alert("This data is required if you selected 'relates to a previous ticket'")    
		f.inewrequest[i].focus()
	}	
}

function radioButtonSelected(f) //f=field
{
	var r="none"
	f=eval(f)
	for (var i=0; i < f.length; i++) {
		if (f[i].checked) {
			r=f[i].value
			break
		}
	}
	return r
}




function isDDSelected(fldName)
{
	
	fldName	=	eval(fldName)
	return (fldName[fldName.selectedIndex].value != "")?true:false
}

function DDItemSelected(fldName)
{
	fldName	  =  eval(fldName)
	return fldName[fldName.selectedIndex].value
}

function SetDDLSelectedIndex(fldName,newValue)
{
	// sets a new selectedIndex where value=newValue
	fldName	 =	eval(fldName)
	for (x=0;x<fldName.options.length;x++) {
		if (fldName.options[x].value==newValue) {
			fldName.options[x].selected=true
			break
		}
	}
}			
function radioOptionNoSelected(f) //f=field
{
	f=eval(f)
	for (var i=0; i < f.length; i++) {
		if (f[i].checked) {
			break
		}
	}
	return i
}

function uncheckRadioOption(f) //f=field
{
	f=eval(f)
	//alert(f)
	for (var i=0; i < f.length; i++) {
		f[i].checked=false
	}
}


function relocateDivision(divName,lx,ly)
{
	document.getElementById(divName).style.left=lx;
	document.getElementById(divName).style.top=ly;
}


function submitContactForm()
{
	var f = document.forms['roi'] 
	var msg = ""
	
	if (isEmpty(f.FirstName.value)) {
		msg += "\n. First Name empty"
	}
	
	if (isEmpty(f.LastName.value)) {
		msg += "\n. Last Name empty"
	}

	if (!isEmail(f.Email.value)) {
		msg += "\n. Incorrect or empty email address"
	}
	if (isEmpty(getRadioButtonSelectedValue(f.jobDescription))) {
		msg += "\n.  How can Sitemarvel help - box empty"
	}
	if (!isValid_DMY_Date(f.targetDate.value)) {
		msg += "\n. Tentative completion date empty or inaccurate"
	}

	if (isEmpty(f.Message.value)) {
		msg += "\n. No message or question entered"
	}
	if (f.ovs.value != botProofString) {
		f.ovs.value=""
		msg += "\n. Verification string does not match with the one displayed."
	}
	if (msg != "") {
		alert("Incorrect or invalid input in the following fields:\n" + msg)	
	}
	else {
		f.button2.disabled=false
		f.submit();
	}
}



function checkButtonState()
{
	var f = document.forms['roi'] 
	var msg = 0
	
	if (isEmpty(f.FirstName.value)) {
		msg += 1
	}
	
	if (isEmpty(f.LastName.value)) {
		msg += 1
	}

	if (!isEmail(f.Email.value)) {
		msg += 1
	}
	if (isEmpty(getRadioButtonSelectedValue(f.jobDescription))) {
		msg += 1
	}
	if (!isValid_DMY_Date(f.targetDate.value)) {
		msg += 1
	}

	if (isEmpty(f.Message.value)) {
		msg += 1
	}
	if (f.ovs.value != botProofString) {
		f.ovs.value=""
		msg += 1
	}
	if (msg == 0) {
		f.button2.disabled=false;
	}	
}


function checkIfExists(arr,val)
{
	var i 
	//alert(eval(arr)[40])
	for (i=0; i<eval(arr).length; i++) {
		if (eval(arr)[i]==val) {
			alert("That username is taken\n- please try a different username!");
			return true;
		}
	}
	//alert("ok!");
	return false;	
}
function validatePaymentEntry(checkOnly,mode) 
{
	var f,m, ccTypeSelected, payMethod,cxMonth,cxYear
	f=document.forms["form0"]
	m=""
	var isPpProcessing = ((f.isPpProcessing.value).toLowerCase()=="true")?true:false
	payMethod		=	DDItemSelected(f.MethodOfPayment);
	ccTypeSelected	=	DDItemSelected(f.CCType);
	cxMonth			=	DDItemSelected(f.CCxMonth);
	cxYear			=	DDItemSelected(f.CCxYear);
	
	
	if (isEmpty(payMethod)) {m+="\nMethod of payment";};
	//if (isEmpty(f.CustomerRef.value)) {m+="\nCustomer order No."};
	
	
	//alert(ccTypeSelected);
	if (!isPpProcessing  && payMethod=='Credit Card') {
		if (isEmpty(ccTypeSelected)) {m+="\nCard type"};
		if (isEmpty(f.CCNo.value))		{m+="\nCard No."};
		if (isEmpty(f.CCCV.value))		{m+="\nCredit card check value"};
		if (isEmpty(f.CCName.value))	{m+="\nName on card"};
		if (isEmpty(cxMonth))			{m+="\nCard expiry month"};
		if (isEmpty(cxYear))			{m+="\nCard expiry year"};
	}
	if (m != "")
		alert("The following fields are incorrect or empty:\n\n" + m)
	else {
		if (!checkOnly){
			//f.action="/ssl/order.asp?action=process-payments";
			f.submit();
		}
		else
			alert("S U C C E S S \n\nEverything checks fine!")
			
	}	

}

function validateItemDetails(checkOnly,mode) 
{
	var f, m, r, phone, mob
	f=document.forms["form0"]
	m=""
	
	
	if (mode==0)
		mode="new"
		
		
	if (isEmpty(f.ItemName.value))
		m+=". item name (short description)\n"
		
	if (isEmpty(f.ItemDescription.value))
		m+=". item description\n"	
		
	
	
	if (!isDDSelected(f.ItemCategory))
		m+=". item category \n"
		
	if (!isDDSelected(f.ItemSubcategory))
		m+=". item sub-category \n"
		
	if (isEmpty(f.ItemPrice.value))
		m+=". item price\n"
		
	if (isEmpty(f.ItemPPButtonId.value))
		m+=". ItemPPButtonId\n"
		
	
	
	if (m != "")
		alert("The following fields are incorrect or empty:\n\n"+ m)
	else {
		if (!checkOnly)
			f.submit()
		else
			alert("S U C C E S S \n\nEverything checks fine!")
			
	}	
}



function validateContactDetails(checkOnly,mode) 
{
	var f, m, r, phone, mob
	if (mode==0)
		mode="new"
		
		
	f=document.forms["form0"]
	phone=f.phocc.value + f.phoac.value + f.phono.value
	mob=f.mobcc.value + f.mobac.value + f.mobno.value
	
	m="" 
	
	
	if (isEmpty(f.firstname.value))
		m+=". first name\n"
		
	if (isEmpty(f.lastname.value))
		m+=". last name\n"
	if (r==1 && isEmpty(f.businessname.value))
		m+=". business name required for selected customer type \n"
		
	if (isEmpty(f.address1.value))
		m+=". address line 1\n"
		
	if (isEmpty(f.city.value))
		m+=". city\n"
		
	if (isEmpty(f.postcode.value))
		m+=". postcode\n"
		
	if (isEmpty(f.email.value))
		m+=". email\n"
	
	if (isEmpty(f.username.value))
		m+=". username\n"
		
	if (isEmpty(f.loginpassword.value) || f.loginpassword.value!=f.confirmpassword.value)
		m+=". password not entered or does not match\n"
				
		
	if (isEmpty(phone) && isEmpty(mob))
		m+=". at lease one of phone or mobile must be entered"

	
	if (m != "")
		alert("The following fields are incorrect or empty:\n\n"+ m)
	else {
		f.mobile.value=f.mobcc.value+"-"+f.mobac.value+"-"+f.mobno.value
		f.phone.value=f.phocc.value+"-"+f.phoac.value+"-"+f.phono.value
		f.fax.value=f.faxcc.value+"-"+f.faxac.value+"-"+f.faxno.value
		
		if (!checkOnly)
			f.submit()
		else
			alert("S U C C E S S \n\nEverything checks fine!")
			
	}	
}




function loginValidate(u1,p1) {
	var u = eval("document.forms['logon']." + u1).value;
	var p = eval("document.forms['logon']." + p1).value;
	if (p=="" || u.value=="") {
		alert("Username and password both must be entered")
	}
	else {
		document.forms['logon'].submit()
	}		
}


function NoEntry(hopto)
{
	alert("No editing allowed in this field")
	hopto.focus()
}

function checkLuhn(cc) {
    var i, nDigits, parity, sum = 0
    cc = cc.toString()
    nDigits = cc.length
	parity = nDigits % 2
	for (i=0; i<nDigits; i++) {
		var digit = parseInt(cc.charAt(i))
		if ((i % 2) == parity)
			digit = digit * 2
        if (digit > 9)
            digit = digit - 9 
        sum = sum + digit
     }
     return ((sum % 10) == 0)
 }
 
 function isValidCCE(ccname,num)
 {
	var nLen,pfx
	
	if(isEmpty(ccname) || isEmpty(num) || !isNumeric(num))
		return (false)
	nLen = num.length
	
	switch(ccname) {
		case "American Express": {
			if(nLen == 15) {
				pfx = parseInt(num.substr(0,2))
				if (pfx == 34 || pfx == 37) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Visa": {
			if(nLen == 16 || nLen==13)  {
				pfx = parseInt(num.substr(0,1))
				if (pfx == 4) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Mastercard": {
			if(nLen == 16)  {
				pfx = parseInt(num.substr(0,1))
				if (pfx > 50 && pfx < 56) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		case "Diners Club": {
			if(nLen == 14) { 
				pfx = parseInt(num.substr(0,3))
				if (pfx > 299 && pfx < 306) {
					if (checkLuhn(num))
						return (true)
				}
			}
			break;
		}
		
		case "JCB": {
			if(nLen == 16) {
				pfx = parseInt(num.substr(0,1))
				if (pfx==3) {
					if (checkLuhn(num))
						return (true)
				}
			}
			else {
				if(nLen == 15)  {
					pfx = parseInt(num.substr(0,4))
					if (pfx==2131 || pfx==1800) {
						if (checkLuhn(num))
							return (true)
					}
				}
			}
			break;
		}
	}
	return (false)
}

function checkCreditCardEntry()
{
	var f = document.form0
	//alert("CardNo.: " + f.CCType.value + f.CCNo.value)
	if (!isValidCCE(f.CCType.value, f.CCNo.value))
		alert("Credit card number entry is not valid.\n Please check and retry.\n")
}
function ToggleActivate(tblName)
{
	var f=document.forms["form0"]
	
	
	switch(tblName) {
		case "tblCustomers":{
			f.isActive.value^=1
			break;	
			}
		case "tblItems":{
			f.ItemIsActive.value^=1
			break;	
			}
		case "tblTenderPrices":{
			f.TenderIsActive.value^=1
			break;	
			}
		case "tblComments":{
			f.CommentIsActive.value^=1
			break;	
			}
		case "tblStaff":{
			f.IsActive.value^=1
			break;	
			}
	}
	f.submit()
}

function toggleShowHide(el, lnk)
{
	var o=document.getElementById(el);
	var l=document.getElementById(lnk);
	if (o.style.visibility=="visible") {
		l.innerHTML="Show";
		o.style.visibility="hidden";
	}	
	else{
		l.innerHTML="Hide";
		o.style.visibility="visible";
	}	
}
