// Opens Window PopUp
function winPopUp(winURL,name,winWidth,winHeight) {
	var w = window.open(winURL, 'name', "width="+winWidth+", height="+winHeight+", toolbars=no, scrollbars=yes");
	w.focus();
}

// Generic Jump Menu
function JumpMenu(targ,selObj){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}

// Clears default text in form field on focus
function clearFld(pFld) {
	getObject(pFld).value = "";
	return false;
}

// Accepts an object reference or a string, returns an object reference
function getObject(pRef) {
	var obj;

	if (typeof(pRef) == "object") {
		obj = pRef;
	} else if (typeof(pRef) == "string") {
		obj = document.getElementById(pRef);
		if (!obj) {
			throw new ObjectNotFoundException(pRef);
		}
	} else {
		throw new InvalidObjectRefException(pRef);
	}
	
	return obj;
}

// Trims White Spaces in the passed values
function trimText(obj) {
	var str = "";
	for (var i=0; i < obj.length; i++) {
		var letter = obj.charAt(i).toLowerCase();
		if (letter == " ")
			continue;
		str = str + letter;
	}
	return str;
}

// Validates Passed Email Address
function isValidEmail(email){
	if (/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/.test(email)) {
		return (true);
	}
	else {
		return (false);
	}
} 

/*--------------------------------------------------------
 *  Function:  timestamp
 *  
 *  Description:
 *  Accepts a date and style, writes localized timestamp
 *  	in specified style to the reader's browser
 *  
 *  Parameters:
 *  date	string	unixtime timestamp
 *  style	string	predefined style of output
 *							
 *  Return:
 *  none	
 *
 * Usage:
 * <script type="text/javascript">timestamp(1279479600000,'longDateTime')</script>
 *-------------------------------------------------------*/
 
function timestamp(pDate,style) {

	var date = new Date(pDate);
	var now = new Date();

	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var monthday = date.getDate();
	var weekday = date.getDay();
	var hour = date.getHours();
	var minute = pad(date.getMinutes());

	var strShortMonth = "";	
	var strLongMonth = "";
	switch (month) {
		case 1:
			strShortMonth = "Jan";
			strLongMonth = "January";
			break;
		case 2:
			strShortMonth = "Feb";
			strLongMonth = "February";
			break;
		case 3:
			strShortMonth = "Mar";
			strLongMonth = "March";
			break;
		case 4:
			strShortMonth = "Apr";
			strLongMonth = "April";
			break;
		case 5:
			strShortMonth = "May";
			strLongMonth = "May";
			break;
		case 6:
			strShortMonth = "Jun";
			strLongMonth = "June";
			break;
		case 7:
			strShortMonth = "Jul";
			strLongMonth = "July";
			break;
		case 8:
			strShortMonth = "Aug";
			strLongMonth = "August";
			break;
		case 9:
			strShortMonth = "Sep";
			strLongMonth = "September";
			break;
		case 10:
			strShortMonth = "Oct";
			strLongMonth = "October";
			break;
		case 11:
			strShortMonth = "Nov";
			strLongMonth = "November";
			break;
		case 12:
			strShortMonth = "Dec";
			strLongMonth = "December";
			break;
	}
	
	var strWeekday = "";
	switch (weekday) {
		case 0:
			strWeekday = "Sunday";break;
		case 1:
			strWeekday = "Monday";break;
		case 2:
			strWeekday = "Tuesday";break;
		case 3:
			strWeekday = "Wednesday";break;
		case 4:
			strWeekday = "Thursday";break;
		case 5:
			strWeekday = "Friday";break;
		case 6:
			strWeekday = "Saturday";break;
	}
	
	var meridian = "am";
	if (hour >= 12) {
		hour = hour - 12;
		meridian = "pm";
	}
	if (hour == 0) {
		hour = 12;
	}
	
	var time = hour+":"+minute+" "+meridian;
	var shortDate = strShortMonth + " " + monthday;
	var longDate = shortDate + ", " + year;
	
	var timestamp = "";
	switch (style) {
		case "longDate" :
			document.write(longDate);
			break;
		case "shortDate" :
			document.write(shortDate);
			break;
		case "time" :
			document.write(time);
			break;
		case "longDateTime" :
			document.write(longDate + " " + time);
			break;
		case "shortDateTime" :
			document.write(shortDate + ", " + time);
			break;
		case "homepage" :
			if (date.getDate() == now.getDate()) {
				document.write(time);
			} else {
				document.write(shortDate);
			}
			break;
		case "dateTime" :
			if (date.getYear() == now.getYear()) {
				document.write(shortDate + ", " + time);
			} else {
				document.write(longDate + " " + time);
			}
			break;
		default :
			//document.write(time_ago_in_words(pDate));
			if (date.getYear() == now.getYear()) {
				document.write(shortDate);
			} else {
				document.write(longDate);
			}
	}
	
}

