/*
	functions.js: by Joel Firestone (4/30/01)
	
	These functions comprise all of the DHTML/JavaScript functionality across 
	delmarvaonline.com. It verifies form submissions, handles image pre-loading 
	and rollover, window pop-ups, etc.
*/

// =============================================================================
// 		generic functions (rollOn(), rollOff(), etc.
// =============================================================================

function preLoad() {
	// set our array of image names that we're going to load
	var arrImages = new Array ("signup","account","access","business","support","company","home","areainfo");
	var arrImage = new Array(6);
	
	// loop through arrImages, setting a new image and preloading it
	for (i = 0; i < arrImages.length; i++) {
		strName = "http://www.delmarvaonline.com/images/nav." + arrImages[i] + ".on.gif";
		arrImage[i] = new Image();
		arrImage[i].src = strName;
	}
}

function rollOn(name) {
	// rollover our images, based on the passed image name
	var strImage = "http://www.delmarvaonline.com/images/nav." + name + ".on.gif";
	document.images[name].src = strImage;
}

function rollOff(name) {
	// rollover our images, based on the passed image name
	var strImage = "http://www.delmarvaonline.com/images/nav." + name + ".gif";
	document.images[name].src = strImage;
}

// =============================================================================
// 		specific function for each different section
// =============================================================================

function checkTechSearch() {
	// make sure somethging was entered in the search box before we continue
	if (document.mySearch.terms.value == "") {
		alert("Please supply some text to search on.");
		return false;
	} else {
		return true;
	}
}

function eventSearch() {
	// make sure something was entered in the search box before we continue
	if (document.mySearch.terms.value == "") {
		alert("Please supply a keyword\(s\) to search for.");
		return false;
	} else {
		return true;
	}
}

function townSearch() {
	// make sure something was selected before we continue
	if (document.myTown.findTown.value == "") {
		alert("Please choose a town.");
		return false;
	} else {
		return true;
	}
}

function launch(url, name, width, height) {
	// launch a new window with the specs and page passed
	var myWin = window.open(url, name, "width=" + width + ",height=" + height);
}

function ranCamera() {
	// display one of 6 random camera images, with a link to it
	arrImages = new Array("baybridge.jpg","camera1.jpg","camera2.jpg","ocbeachcam.jpg","ocCAM.jpg","salisCAM.jpg");
	arrLinks = new Array(6);
	arrNames = new Array(6);
	
	// create our links
	arrLinks[0] = "http://www.baybridgecamera.com/";
	arrLinks[1] = "http://www.lewesferrycam.com/";
	arrLinks[2] = "http://www.rehobothcam.com/";
	arrLinks[3] = "http://www.ocbeachcam.com/";
	arrLinks[4] = "http://www.wboc.com/cameras/oc.cfm";
	arrLinks[5] = "http://www.wboc.com/cameras/saliscam.cfm";
	
	// create our names
	arrNames[0] = "Chesapeake Bay Bridge";
	arrNames[1] = "Lewes Ferry";
	arrNames[2] = "Rehoboth Beach, DE";
	arrNames[3] = "Ocean City, MD";
	arrNames[4] = "Ocean City, MD";
	arrNames[5] = "Salisbury, MD";
	
	// generate a random number
	var intNum = Math.floor(Math.random() * 6);
	
	// create a new image
	strImage = new Image(80,66);
	strImage.src = "/cameras/images/" + arrImages[intNum];
	strName = "/cameras/images/" + arrImages[intNum];
	
	// write out our code
	document.write('<a href="' + arrLinks[intNum] + '"><img src="' + strName + '" alt="' + arrNames[intNum] + '" width="80" height="66" border="0"><br><b>' + arrNames[intNum] + '</b></a><br>');
	return true;
}

/*	homepics.js: by Nathan E. Jones (6/19/01)
Randomly rotates pictures on homepage.  Manage what pictures display below.
			
		imgs = new Array ("peep1.jpg", "peep2.jpg", "peep3.jpg", "peep5.jpg", "peep18.jpg", "peep19.jpg")
		  
		function insertAd() {
			adIX = Math.round(Math.random()*(imgs.length-1))
			document.write('<div ALIGN="CENTER">')
			document.write('<IMG SRC="/images/'+imgs[adIX]+'" BORDER="0" width="150" alt="Delmarva Online Family">')
			document.writeln('</div>')
		}		*/	

function swapMe(objString) {
	var imgObj = eval("document.images['img"+ objString + "']")
	var dispObj = eval("document.all."+ objString + "")
	
	if (imgObj.src.indexOf('home_max.gif') != -1) {
		dispObj.style.display='block';
		imgObj.src = '/images/home_x.gif';
	} else {
		dispObj.style.display='none';
		imgObj.src = '/images/home_max.gif';
	}
}

function checkEvent() {
	// set our array of illegal characters
	arrBadChars = new Array("~","`","!","@","#","$","%","^","&","=","?","/","\\");
	strTitle = document.myEvent.evtTitle.value;

	// make sure a category has been selected
	if (document.myEvent.catID.options[0].selected == true || document.myEvent.catID.selectedIndex == -1) {
		alert("Please choose a category for this event.");
		return false;
	}
	// make sure our required fields have been filled in
	if (document.myEvent.evtTitle.value == "" || document.myEvent.evtDescription.value == "" || document.myEvent.evtTime.value == "") {
		alert("Please supply at least a title, description, and time for this event.");
		return false;
	}
	// make sure a state has been selected
	if (document.myEvent.stateID.value == "") {
		alert("Please choose at least one state to add this event.");
		return false;
	}
	// make sure an event type has been selected
	if (document.myEvent.evtType.options[0].selected == true) {
		alert("Please select what type of event this is.");
		return false;
	}
	// based on our choices, define what is required from here
	if (document.myEvent.evtType.options[1].selected == true || document.myEvent.evtType.options[5].selected == true) {
		if (document.myEvent.evtDay.value == "") {
			alert("Please select the date for this event.");
			return false;
		}
	}
	if (document.myEvent.evtType.options[3].selected == true) {
		// reset the start and end days
		if (document.myEvent.evtWeekDay.options[0].selected == true) {
			alert("Please select the day this weekly event takes place.");
			return false;
		}
	}
	if (document.myEvent.evtType.options[4].selected == true) {
		// reset the start and end days
		if (document.myEvent.evtMonth.options[0].selected == true) {
			alert("Please select the day of the month this event takes place.");
			return false;
		}
	}
	if (document.myEvent.evtType.options[6].selected == true) {
		if (document.myEvent.evtDay.value == "" || document.myEvent.evtEndDay.value == "") {
			alert("Please select a start and end day this extended event takes place.");
			return false;
		}
	}
	
	// loop through and make sure no illegal characters appear in the title
	for (i = 0; i < arrBadChars.length; i++) {
		if (strTitle.indexOf(arrBadChars[i]) != "-1") {
			alert("The title contains an illegal character \(" + arrBadChars[i] + "\).\n" +
				  "Please remove this and try again.");
			return false;
		}
	}
	
	// all good
	return true;
}

function swapDays() {
	// set our date values
	strDate = new Date();
	strDay = strDate.getDate();
	strMonth = strDate.getMonth() + 1;
	strYear = strDate.getYear();
	strFullDate = strMonth + "/" + strDay + "/" + strYear;
	
	// set a variable based on the chosen item from evtType
	intIndex = document.myEvent.evtType.selectedIndex;
	
	// based on our chosen index, swap out fields and set their focus()
	if (intIndex == 0) {
		alert("Please choose the type of event this is.");
		document.myEvent.evtDay.value = "";
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.options[0].selected = true;
	}
	if (intIndex == 1) {
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.options[0].selected = true;
		document.myEvent.evtDay.value = strFullDate;
		document.myEvent.evtDay.focus();
		document.myEvent.evtDay.select();
	}
	if (intIndex == 2) {
		document.myEvent.evtDay.value = "";
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.options[0].selected = true;
		document.myEvent.evtTime.focus();
		document.myEvent.evtTime.select();
	}
	if (intIndex == 3) {
		document.myEvent.evtDay.value = "";
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtMonth.options[0].selected = true;
		document.myEvent.evtWeekDay.focus();
	}
	if (intIndex == 4) {
		document.myEvent.evtDay.value = "";
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.focus();
	}
	if (intIndex == 5) {
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.options[0].selected = true;
		document.myEvent.evtDay.value = strFullDate;
		document.myEvent.evtDay.focus();
		document.myEvent.evtDay.select();
	}
	if (intIndex == 6) {
		document.myEvent.evtEndDay.value = "";
		document.myEvent.evtWeekDay.options[0].selected = true;
		document.myEvent.evtMonth.options[0].selected = true;
		document.myEvent.evtDay.value = strFullDate;
		document.myEvent.evtEndDay.value = strFullDate;
		document.myEvent.evtDay.focus();
		document.myEvent.evtDay.select();
	}
}

function valWebMail() {
	// make sure no @ signs appear in the username
	strUsername = document.LOGINFORM.USERNAME.value;
	
	if (strUsername.indexOf("@") != -1) {
		alert("Please enter just your username, and not your entire email address.\n\n" +
			  "For example: If your email is johndoe@dmv.com, simply enter johndoe.");
		return false;
	}
	return true;
}

function setFocus()
{
    document.implogin.imapuser.focus();
}

function submit_login2() {
if (login_form.login_username.value.indexOf('@') == -1) {
        alert("Please enter your full email address, for example, person@isp.com");
        login_form.login_username.focus();
        return false;
    }

    if(login_form.secretkey.value.length == 0) {
        alert("Please enter your password, being careful to use the proper case.");
        login_form.secretkey.focus();
        return false;
    }

    return true;
}

function submit_login() {
	var imapuser = document.implogin.imapuser.value;
	var pass = document.implogin.pass.value;
	var server = document.implogin.server[document.implogin.server.selectedIndex].value;
	
	if (document.implogin.server[document.implogin.server.selectedIndex].value.substr(0, 1) == "_") {
        return false;
    }
    if (imapuser == "") {
        alert("Please provide your username and password");
        document.implogin.imapuser.focus();
        return false;
    } else if (document.implogin.pass.value == "") {
        alert("Please provide your username and password");
        document.implogin.pass.focus();
        return false;
    }
	//if (imapuser.indexOf("@") != -1) {
		//alert("Please only enter your username, and not your entire email address.");
		//return false;
	//}
	if (server == "") {
		alert("Please choose the domain you dialup through.");
		return false;
	}
	return true;
}
//-->

function enter_key_trap(e)
{
    var keyPressed;

    if (document.layers) {
        keyPressed = String.fromCharCode(e.which);
    } else if (document.all) {
        keyPressed = String.fromCharCode(window.event.keyCode);
    } else if (document.getElementById) {
        keyPressed = String.fromCharCode(e.keyCode);
    }

    if ((keyPressed == "\r" || keyPressed == "\n") && (Submit_login())) {
        document.implogin.submit();
    }
}
//-->
