/*
VERSION 1.03

Last updated: Friday, September 14, 2001 12:56 PM
*/

function imageSwap (name, newsrc) {
	document.images[name].src=newsrc;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function confirmDate(dateStr) {
	var month = dateStr.substring(0, dateStr.indexOf("/"));
	var day   = dateStr.substring(dateStr.indexOf("/")+1, dateStr.lastIndexOf("/"));
	var year  = dateStr.substring(dateStr.lastIndexOf("/")+1, dateStr.length);
	if (!isNaN(month) && !isNaN(day) && !isNaN(year)) {
		if (year > 79 && year < 100)
			year = parseInt(year) + 1900;
		if (year > 0 && year < 79)
			year = parseInt(year) + 2000;
		if (month < 1 || month > 12 || day < 1 || day > 31 || year < 1800 || year > 2200)
			return false;
		else
		if (month == 2 && day > 29 && (year%400 == 0))
			return false;
		else
		if (month == 2 && day > 28 && (year%100 == 0) && (year%400 != 0))
			return false;
		else
		if (month == 2 && day > 29 && (year%4 == 0))
			return false;
		else
		if (month == 2 && day > 28 && (year%4 != 0))
			return false;
		else
		if (month == 9 && day > 30)
			return false;
		else
		if (month == 11 && day > 30)
			return false;
		else
		if (month == 4 && day > 30)
			return false;
		else
		if (month == 6 && day > 30)
			return false;
		else
			return true;
	}
	else
		return false;
}

function verifyEmail(str) {
	var reg = /^[0-9a-zA-Z_\.\-]+@[0-9a-zA-Z\-\._]+\.[0-9a-zA-Z]+$/;
	return reg.test(Trim(str));
}

// removes any erroneous whitespaces
function Trim(str) {
	var left = /^\s+/;
	var right = /\s+$/;
	return str.replace(right,"").replace(left,"");
}

function empty(str) {
	return (Trim(str)=="");
}

function isNotNull(s) {
	return (s+""!="undefined" && s+""!="null" && s+""!="");
}

function popup(url) {
	var height = screen.availHeight/2;
	var width = screen.availWidth/2;
	var options = "width="+width+",height="+height+",scrollbars=yes,resizable=yes,toolbar=no";
	popupwindow = window.open(url,'popupwindow',options);
	popupwindow.focus();
}

function showCal(frm) {
	var x = window.screenX;
	var y = window.screenY;
	var cx = (x+(window.outerWidth/2));
	var cy = (y+175);
	var inputName = frm.name
	var hWindow = window.open("gtd/datePicker.asp?inputName="+frm.name+"&shortdate="+frm.value, "datePicker", "width=250,height=240,screenX="+cx+",screenY="+cy);
}

function showMedia(link, width, height) {
	if (!isNotNull(width)) {
		width = 280;
	}
	if (!isNotNull(height)) {
		height = 320;
	}

	//added by John to fix the windows that also contain captions.
	if(width < 400) width = 400;
	if(height < 400) height = 400;
	
	var mp = new popupWindow(width,height);
	mp.setName('mediapopup');
	mp.setUrl(link);
	mp.show();
}

function showColor(frm, link, width, height) {
	if (!isNotNull(link)) {
		link = 'gtd/colorPicker.asp'
	}
	if (!isNotNull(width)) {
		width = 280;
	}
	if (!isNotNull(height)) {
		height = 320;
	}
	var colorpopup = new popupWindow(width,height);
	colorpopup.setName('colorpopup');
	var u = new url(link);
	u.setOption('inputName',frm.name);
	u.setOption('inputColor',frm.value);
	colorpopup.setUrl(u.getUrl());
	colorpopup.show();
}

function makeValidNumber(bvObj, dval) {
	var dimStr = bvObj.value;
	var ret = "";
	for (var i=0; i<dimStr.length; i++) {
		if (!isNaN(dimStr.charAt(i))&&dimStr.charAt(i)!=" ")
			ret += dimStr.charAt(i);
	}
	if (ret == "") {
		ret = dval;
	}
	return ret;
}

function checkNumber(fName, dval) {
	var dl = eval(fName);
	dl.value = makeValidNumber(dl, dval);
	return;
}

function verifyFloat(formfield) {
	var dl = eval(formfield);
	if (Trim(dl.value)=="") return false;
	return !isNaN(dl.value);
}

// returns true when value is element in array, false otherwise
function isPartOf(val, ar) {
	for (var i = 0;i<ar.length;i++) {
		if (val == ar[i]) {
			return true;
		}
	}
	return false;
}
