function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var subMnus="";
									
function showMenu(idx,li){
	var subleftoffset=((document.body.offsetWidth-933)/2)+8;
	if(document.body.offsetWidth<933)
		subleftoffset=18;
	var sublefts=new Array(5);
	sublefts[0]=subleftoffset+66;
	sublefts[1]=sublefts[0]+90;
	sublefts[2]=sublefts[1]+89;
	sublefts[3]=sublefts[2]+94;
	sublefts[4]=sublefts[3]+102;
	try{
		hideAllMenu();
		var dv=document.getElementById("sub"+idx);
		dv.style.left=sublefts[li];
		dv.style.top=146;
		dv.style.visibility="visible";
	}
	catch(e){}
}

function hideAllMenu(){
	try{
		var ar=subMnus.split(',');
		for(i=0;i<ar.length;i++){
			var dv=document.getElementById("sub"+ar[i]);
			dv.style.visibility="hidden";
		}
	}
	catch(e){}
}

function popWin(whichOne){
	var myWin;
	myWin=window.open(whichOne,'thisWin','width=400,height=400');
}

function validEmail(email){
	var emailexp = /.*\@.*\..*/;
	return emailexp.test(email)
}

function isDefined(ckVar){
  	var DEFINED_V=true;
  	


      	function handleError() {
      	DEFINED_V=false;
      	return true;
      	}
      	var oldOnError=window.onerror;
      	window.onerror=handleError;
      	try { 
      		eval(ckVar);
      	}catch (e) 
      	{ DEFINED_V=false;
      	}
      	window.onerror=oldOnError;
      	return DEFINED_V;
}

function validDate(aDate) {
	var dateexp = /^(\d{1,2}\/\d{1,2}\/\d{4})$/;
    if (!dateexp.test(aDate)) { return false; } 	
	var	temp = new String(aDate), m = 0, d = 0;
	
	for (i=0; i < temp.length; i++){ 
		var str = temp.charAt(i); 
		if (str == "/") { if (m == 0) { m = i; } else { d = i; break; }}			
	}
	
	var month = parseInt(temp.substring(0, m), 10);
	var day = parseInt(temp.substring(m + 1, d), 10); 
	var year = parseInt(temp.substring(d + 1, temp.length), 10);								
					
	switch (month) {
		case 1:	case 3:	case 5:	case 7:	case 8:	case 10: case 12:					
			if ((day < 1) || (day > 31)) {  return false;	} break;
		case 2:		
			if ((year % 400 == 0) || (year % 4 == 0)) {	if ((day < 1) || (day > 29)) {  return false;	} break}
			if ((day < 1) || (day > 28)) {  return false; } break;
		case 4:	case 6:	case 9: case 11:
			if ((day < 1) || (day > 30)) {	 return false; } break;
		default: return false;			
	}		
	return true;		
}

var calendar;
function ShowCalendar(formname,boxname,boxdate){
	calendar=window.open('show_calendar.cfm?boxname='+boxname+'&boxdate='+boxdate+'&formname='+formname,
	'calendar','scrollbars=0,width=230,height=190, top=40,left=40');
} 

function getSelectedOp(theSelect){
	for(i=0;i<theSelect.options.length;i++){
		if(theSelect.options[i].selected)
			return theSelect.options[i].value;
	}
	
	return -1;
}

function validateMyInfo(theForm){
	if(theForm.newPassword.value!=""&&theForm.newPassword.value!=theForm.confirmPassword.value){
		alert("The new password and confirmation do not match. Please try again.");
		theForm.newPassword.focus();
		return false;
	}
	if(theForm.bidderFName.value==""){
		alert("Please enter a first name.");
		theForm.bidderFName.focus();
		return false;
	}
	if(theForm.bidderLName.value==""){
		alert("Please enter a last name.");
		theForm.bidderLName.focus();
		return false;
	}
	if(theForm.bidderCName.value==""){
		alert("Please enter a company name.");
		theForm.bidderCName.focus();
		return false;
	}
	if(theForm.bidderACode.value==""||isNaN(theForm.bidderACode.value)){
		alert("Please enter an area code. (numbers only)");
		theForm.bidderACode.focus();
		return false;
	}
	if(theForm.bidderPhone.value==""||isNaN(theForm.bidderPhone.value)){
		alert("Please enter a phone number. (numbers only)");
		theForm.bidderPhone.focus();
		return false;
	}
	if(theForm.bidderEmail.value==""){
		alert("Please enter an email address.");
		theForm.bidderEmail.focus();
		return false;
	}
	if(!validEmail(theForm.bidderEmail.value)){
		alert("The email address you entered is not valid (i.e. abc@server.com). Please try again.");
		theForm.bidderEmail.focus();
		return false;
	}
	if(theForm.bidderAddress1.value==""){
		alert("Please enter a street address.");
		theForm.bidderAddress1.focus();
		return false;
	}
	if(theForm.bidderCity.value==""){
		alert("Please enter a city.");
		theForm.bidderCity.focus();
		return false;
	}
	if(theForm.bidderPostal.value==""){
		alert("Please enter a postal/zip code.");
		theForm.bidderPostal.focus();
		return false;
	}
	return true;
}

function validateApp2(theForm){
	if(theForm.appFName.value==""){
		alert("Please enter a first name.");
		theForm.appFName.focus();
		return false;
	}
	if(theForm.appLName.value==""){
		alert("Please enter a last name.");
		theForm.appLName.focus();
		return false;
	}
	if(theForm.appCName.value==""){
		alert("Please enter a company name.");
		theForm.appCName.focus();
		return false;
	}
	if(theForm.appACode.value==""||isNaN(theForm.appACode.value)){
		alert("Please enter an area code. (numbers only)");
		theForm.appACode.focus();
		return false;
	}
	if(theForm.appPhone.value==""||isNaN(theForm.appPhone.value)){
		alert("Please enter a phone number. (numbers only)");
		theForm.appPhone.focus();
		return false;
	}
	if(theForm.appEmail.value==""){
		alert("Please enter an email address.");
		theForm.appEmail.focus();
		return false;
	}
	if(!validEmail(theForm.appEmail.value)){
		alert("The email address you entered is not valid (i.e. abc@server.com). Please try again.");
		theForm.appEmail.focus();
		return false;
	}
	if(theForm.appAddress1.value==""){
		alert("Please enter a street address.");
		theForm.appAddress1.focus();
		return false;
	}
	if(theForm.appCity.value==""){
		alert("Please enter a city.");
		theForm.appCity.focus();
		return false;
	}
	if(theForm.appPostal.value==""){
		alert("Please enter a postal/zip code.");
		theForm.appPostal.focus();
		return false;
	}
	
	/*if(theForm.appUserType.options[theForm.appUserType.selectedIndex].value=="Active Bidder"){
		if(theForm.appInstitution.value==""){
			alert("You must enter your bank institution name.");
			theForm.appInstitution.focus();
			return false;
		}
		if(theForm.appInstNum.value==""){
			alert("You must enter your bank institution number.");
			theForm.appInstNum.focus();
			return false;
		}
		if(theForm.appTransit.value==""){
			alert("You must enter your bank transit number.");
			theForm.appTransit.focus();
			return false;
		}
		if(theForm.appAccount.value==""){
			alert("You must enter your bank account number.");
			theForm.appAccount.focus();
			return false;
		}
		if(theForm.appBContact.value==""){
			alert("You must enter your bank contact.");
			theForm.appBContact.focus();
			return false;
		}
		if(theForm.appAvgSpending.value==""){
			alert("You must estimate your average weekly spending.");
			theForm.appAvgSpending.focus();
			return false;
		}
		if(theForm.appMaxSpending.value==""){
			alert("You must estimate your maximum weekly spending.");
			theForm.appMaxSpending.focus();
			return false;
		}
	}*/
	if(isNaN(theForm.appAvgSpending.value)){
		alert("Your average weekly spending must be a valid number.");
		theForm.appAvgSpending.focus();
		return false;
	}
	if(isNaN(theForm.appMaxSpending.value)){
		alert("Your maximum weekly spending must be a number.");
		theForm.appMaxSpending.focus();
		return false;
	}
	return true;
}

function validateActivation(theForm){
	if(theForm.id.value==""){
		alert("Please enter a username.");
		theForm.id.focus();
		return false;
	}
	if(theForm.bidderPassword.value==""){
		alert("Please enter your issued password.");
		theForm.bidderPassword.focus();
		return false;
	}
	if(theForm.newPassword.value==""||theForm.newPassword.value!=theForm.confirmPassword.value){
		alert("Please enter and confirm a new password.");
		theForm.newPassword.focus();
		return false;
	}
	
	return true;
}
