// functions from mfab - start

function flip(name, type) {
//	document[name].src = "../images/"+name+type+".gif";
	document[name].src = "/evenue/linkID="+linkID+"/images/"+name+type+".gif";
}

function flipRelease(name, type) {
	name = "release"+name;
	document[name].src = "/evenue/linkID="+linkID+"/images/release_tickets"+type+".gif";
}

// functions from mfab - end

// Array for Country code and country name
var cnCodes = new Array(
								"AU","BE","BR","CA","DE","GB","IE","IL","JP","MX","NL",
								"RU","SG","ES","TT","UK","US","VE"
							);

var cnNames = new Array(
								"AUSTRALIA","BELGIUM","BRAZIL","CANADA","GERMANY","GREAT BRITAIN",
								"IRELAND","ISRAEL", "JAPAN",
								"MEXICO","NETHERLANDS","RUSSIAN FEDERATION","SINGAPORE","SPAIN",
								"TRINIDAD & TOBAGO","UNITED KINGDOM","UNITED STATES","VENEZUELA"
							);

//Default country code.
var defaultCnCode = "";

// Array for State code and state name
var stCodes = new Array(
								"AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA",
								"HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA",
								"MI","MN","MS","MO","MT","NE","NV","NH",
								"NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR",
								"RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY",
								"-",
								"AB", "BC", "LB", "MB", "NB", "NF", "NS", "NT", "ON",
								"PE", "QC", "SK", "YT"
							);

//Default state code.
var defaultStCode = "";

var stNames = new Array(
								"ALABAMA","ALASKA","ARIZONA","ARKANSAS","CALIFORNIA","COLORADO",
								"CONNECTICUT","DELAWARE", "DISTRICT OF COLUMBIA",
								"FLORIDA","GEORGIA","HAWAII","IDAHO","ILLINOIS",
								"INDIANA","IOWA","KANSAS","KENTUCKY","LOUISIANA",
								"MAINE","MARYLAND","MASSACHUSETTS","MICHIGAN","MINNESOTA",
								"MISSISSIPPI","MISSOURI","MONTANA","NEBRASKA","NEVADA",
								"NEW HAMPSHIRE","NEW JERSEY","NEW MEXICO","NEW YORK",
								"NORTH CAROLINA","NORTH DAKOTA","OHIO","OKLAHOMA",
								"OREGON","PENNSYLVANIA","PUERTO RICO","RHODE ISLAND",
								"SOUTH CAROLINA","SOUTH DAKOTA","TENNESSEE","TEXAS",
								"UTAH","VERMONT","VIRGINIA","WASHINGTON","WEST VIRGINIA",
								"WISCONSIN","WYOMING",
								"-------------",
								"ALBERTA", "BRITISH COLUMBIA", "LABRADOR", "MANITOBA",
								"BRUNSWICK", "NEWFOUNDLAND", "NOVA SCOTIA", "NORTHWEST TERRITORIES",
								"ONTARIO", "PRINCE EDWARD ISLAND", "QUEBEC", "SASKATCHEWAN",
								"YUKON TERRITORY"
							);

// Browser Check
	var isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
	var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
	var isDOM = (document.getElementById) ? true : false;
	var agt = navigator.userAgent.toLowerCase();
	var isMac = (agt.indexOf("mac")!=-1);

// Size of input boxes for different browsers
	var inputSizeS;
	var inputSizeM;
	var inputSizeL;
	if(isNav) {
		inputSizeS = 5;
		inputSizeM = 15;
		inputSizeL = 20;
		inputTimer = 3;
	} else {
		inputSizeS = 10;
		inputSizeM = 20;
		inputSizeL = 25;
		inputTimer = 3;
	}

// Preload images


// New Date Format
	function newDateFormat(time) {
		var ndow = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
		var nmoy = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		//Tue Jan 1 10:00:00 PST 2002
		if(time == "") {
			var formatedTime = "";
		} else {
	
			var dayow = ndow[time.getDay()];
			var month =nmoy[time.getMonth()];
			var date = time.getDate();
			var year = time.getFullYear();
	
			var formatedTime = dayow+", "+month+" "+date+", "+year;
	
		}
	
		return formatedTime;
	}
	
// New Time Format
	function newTimeFormat(time) {
		if(time == "") {
			var hm = "";
		} else {
			var m = time.getMinutes();
			var h24 = time.getHours();
			var h = h24 > 12 ? h24 - 12 : h24;
			if(m == 0 && h == 0)
				hm = "midnight";
			else if(m == 0 && h == 12)
				hm = "noon";
			else
				hm = h + ":" +  twoForm(m) + (h24 < 12 ? " am" : " pm");
		}
	
		return hm;
	}
	
// Centered Pop Up Box
	function popBox(href, name,w,h) {
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+',scrollbars=no,resizable=no';
		win = window.open(href, name, winprops);
		if (parseInt(navigator.appVersion) >= 4) {
			win.window.focus();
		}
	}
	
// Disables enter button in input boxes
	function disableEnter(fld) {
		var key = (window.event) ? event.keyCode : (key == 0);
		if (key == 13) {
			return false; 
		} 
		return true;
	}
	
// Changes first letter of all strings in an input field to Uppercase
	function changeCase(field) {
		var fstring;
		var tmpChar;
		var preString;
		var postString;
		var flength;
		fstring = field.value.toLowerCase();
		flength = fstring.length;
		if (flength > 0) {
			for (s = 0; s < flength; s++) {
				if (s == 0)  {
					tmpChar = fstring.substring(0,1).toUpperCase();
					postString = fstring.substring(1,flength);
					fstring = tmpChar + postString;
				} else {
					tmpChar = fstring.substring(s, s+1);
					if (tmpChar == " " && s < (flength-1)) {
						tmpChar = fstring.substring(s+1, s+2).toUpperCase();
						preString = fstring.substring(0, s+1);
						postString = fstring.substring(s+2,flength);
						fstring = preString + tmpChar + postString;
					}
				}
			}
		}
		field.value = fstring;
	}
	
	// Validates email address with the following rules:
	// 1. One or more characters before the "@"
	// 2. An optional "[", because user@[255.255.255.0] is a valid e-mail
	// 3. A sequence of letters, numbers, and periods, which are all valid domain or IP address characters
	// 4. A period followed by a 2-3 letter suffix
	// 5. An optional "]"

	function emailValidate(email) {

		var str = email.value; // email string
  
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,6})(\]?)$/; // valid

		if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
			return true;
		}

	//	window.status = "Please enter a valid Internet e-mail address";
		alert("Please enter a valid Internet e-mail address.");

		email.focus();
		email.select();

		return false;
	}

// Validates password is not empty and between 4 and 12 characters
	function passwordValidate(password) {
	
		if(password.value == "") {
			window.status = "Please enter a password";
			password.focus();
			return false;
		}
		if(IPFlag == "1")
		{
			if(password.value.length < 6 || password.value.length > 15) {
				window.status = "Your Password must be between 6 and 15 characters in length.";
				password.focus();
				return false;
			}
		}
		else
		{
			if(password.value.length < 4 || password.value.length > 12) {
				window.status = "Your Password must be between 4 and 12 characters in length.";
				password.focus();
				return false;
			}
		}
	}
// Validates that a 7 or 10 digit phone number has been entered
	function phoneValidate(phone) {
		re  = /[^0-9]/g;
		val = phone.value.replace(re, ""); // take out ' ', '()', '/', '-'
		if((!val.match(/^[2-9]\d{9}$/)) && (!val.match(/^[2-9]\d{6}$/))) {
			alert("Please enter a valid 7 or 10 digit phone number");
			phone.focus();
			phone.select();
			return false;
		}
		if(val.length == 10)
		 phone.value = "(" + val.substr(0, 3) + ") " + val.substr(3, 3) + "-" + val.substr(6, 4) ;
		else
		 phone.value = val.substr(0, 3) + "-" + val.substr(3, 4);		 
		return true ;
	}

// Opens search box on SE
	function launch(path) {
	  remote = open(path + "/datePicker.html", "child",
	         "resizable,dependent=yes,width=300,height=225,left=300,screenX=300,top=200,screenY=200") ;
	}

// Works with launch function	
	function callBack(child, groupCode, timeDateFrom, timeDateTo) {
		document.dateForm.timeDateFrom.value = timeDateFrom ;
		document.dateForm.timeDateTo.value = timeDateTo ;
		document.dateForm.groupCode.value = groupCode ;
		child.close() ;
		document.dateForm.submit() ;
	}

//constants for US/Canada client.
var US_CLIENT = 1;
var CA_CLIENT = 0;

//Returns the lable for state/province depending on the customer is US/Canada
function getStateLable()
{
	if(US_CLIENT)
		return "State/Province";
	if(CA_CLIENT)
		return "Province/State";

	return "State/Province";
}

//Returns the lable for zip/postal code depending on the customer is US/Canada
function getZipCodeLable()
{
	if(US_CLIENT)
		return "Zip/Postal Code";
	if(CA_CLIENT)
		return "Postal/Zip Code";

	return "Zip/Postal Code";
}

/* Additional functions by Tim */

// function to print the header on each page
// if your headers are images, the image parameter is the filename and the text parameter is the alt text
// if your headers are text, the image parameter is ignored and the text parameter is the text printed

// there are generally two header types, images and text...
// set to images if your headers are images
// set to text if your headers are text
	var headType = "text";

	function printHead(image, text) {
		if(headType == "image") {
			document.write(
				'<table cellpadding="0" cellspacing="0" border="0" width="100%">',
				'	<tr>',
				'		<td width="34"><img src="', imageWWWPath, '/head-l.gif" width="34" height="19"  border="0"></td>',
				'		<td width="100%"><img src="', imageWWWPath, '/head-',image,'.gif" height="19" alt="',text,'" border="0"></td>',
				'	</tr>',
				'</table>'
			);
		} else if(headType == "text") {
			document.write(
				'<table width="100%" cellpadding="0" cellspacing="0" border="0">',
				'	<tr>',
				'		<td class="head">&nbsp;',text,'</td>',
				'	</tr>',
				'</table>'
			);
		}
		return true;
	}

function timeOnlyFormat(time) {
	if(time == "") {
			var hm = "n/a";
		} else {
			var m = time.getMinutes();
			var h24 = time.getHours();
			var h = h24 > 12 ? h24 - 12 : h24;

			if(m == 0 && h == 0) {
				hm = zerotimetext;
			} else if(m == 0 && h == 12) {
				hm = "noon";
			} else {
				hm = h + ":" +  twoForm(m) + (h24 < 12 ? " am" : " pm");
			}
		}

		return hm;
	}

// custom code function for dollar formatting

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


// get variables from query string
	function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		} 
		return "";
	}

