function initBody() {

}

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) { //v3.0
	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);
	}
	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];
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showPage(lSID,lPID,lFTLV,sTab,lDID) {
	var sQueryString = "";
	var sFTPR = new String(document.variables.FTPR.value);
	var dtOR = new String(document.variables.OR.value);
	
	sQueryString = "S=" + lSID + "&P=" + lPID;
	if (lFTLV == null)
		sQueryString = sQueryString + "&FTLV=" + document.variables.FTLV.value;
	else
		sQueryString = sQueryString + "&FTLV=" + lFTLV;
	if (sTab == null)
		sQueryString = sQueryString + "&TAB=" + document.variables.TAB.value;
	else
		sQueryString = sQueryString + "&TAB=" + sTab;
	if (lDID == null)
		sQueryString = sQueryString + "&DID=" + document.variables.DID.value;
	else
		sQueryString = sQueryString + "&DID=" + lDID;
		
	sQueryString = sQueryString + "&MID=" + document.variables.MID.value + "&MAID=" + document.variables.MAID.value;
	sQueryString = sQueryString + "&CID=" + document.variables.CID.value + "&BSID=" + document.variables.BSID.value;
	sQueryString = sQueryString + "&MNUM=" + document.variables.MNUM.value;
	sQueryString = sQueryString + "&BM=" + document.variables.BM.value + "&v1=" + document.variables.v1.value;
	sQueryString = sQueryString + "&v2=" + document.variables.v2.value + "&v3=" + document.variables.v3.value;
	sQueryString = sQueryString + "&ESID=" + document.variables.ESID.value;
	sQueryString = sQueryString + "&FTPR="
	do
	{ 
		sFTPR = sFTPR.replace(' ','+');
	}
	while(sFTPR.search(' ') > -1);
	sQueryString = sQueryString + sFTPR;
	sQueryString = sQueryString + "&UT=" + document.variables.UT.value;
	while(dtOR.search(' ') > -1)
	{
		dtOR = dtOR.replace(' ','+');
	}
	sQueryString = sQueryString + "&OR=" + dtOR;
	sQueryString = sQueryString + "&Mode=" + document.variables.Mode.value;
	location.href = sWebRootPath + "Execute/main.asp?" + sQueryString;
}

function fromList(selObj) {
	   eval("showPage" + selObj.options[selObj.selectedIndex].value);
}

function fromLink(sLink,sTab) {
	var sQueryString = "";
	var sFTPR = new String(document.variables.FTPR.value);
	var dtOR = new String(document.variables.OR.value);
	
	sQueryString = "S=-1&P=-1&Link=" + sLink;
	if (sTab == null)
		sQueryString = sQueryString + "&TAB=" + document.variables.TAB.value;
	else
		sQueryString = sQueryString + "&TAB=" + sTab;
	sQueryString = sQueryString + "&MID=" + document.variables.MID.value + "&MAID=" + document.variables.MAID.value;
	sQueryString = sQueryString + "&CID=" + document.variables.CID.value + "&BSID=" + document.variables.BSID.value;
	sQueryString = sQueryString + "&MNUM=" + document.variables.MNUM.value + "&DID=" + document.variables.DID.value;
	sQueryString = sQueryString + "&BM=" + document.variables.BM.value + "&v1=" + document.variables.v1.value;
	sQueryString = sQueryString + "&v2=" + document.variables.v2.value + "&v3=" + document.variables.v3.value;	
	sQueryString = sQueryString + "&ESID=" + document.variables.ESID.value;
	sQueryString = sQueryString + "&FTPR="
	do
	{ 
		sFTPR = sFTPR.replace(' ','+');
	}
	while(sFTPR.search(' ') > -1);
	sQueryString = sQueryString + sFTPR;
	sQueryString = sQueryString + "&UT=" + document.variables.UT.value;
	while(dtOR.search(' ') > -1)
	{
		dtOR = dtOR.replace(' ','+');
	}
	sQueryString = sQueryString + "&OR=" + dtOR;
	sQueryString = sQueryString + "&Mode=" + document.variables.Mode.value;
	location.href = sWebRootPath + "Execute/main.asp?" + sQueryString;
}

function ConfirmDelete(sURL, sParams, sMessage)	{
	if (confirm(sMessage)) {
		window.open(sURL,"customize",sParams);
		}
	}
				
/****************************************************************
* PURPOSE: Checks to see if the string is a valid date.  A valid
*	date is defined as any of the following:
*		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
*		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
*****************************************************************/
function IsValidDate(oInpBox, sFieldName) {
	var str = new String(oInpBox.value);
	var i = 0;
	var j = 0;
	var count = str.length;
	var addOne = false;

	if (count == 0) {
		return true;
		// if the field is empty, just return true...
	}
				
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count) i++;
	if (i == count || i > 2) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}
	// if it is a two-digits month, set a flag
	if (i == 2) addOne = true;
	// check if the number corresponding to the Month is a valid month
	if (!isDateNumber(str.substring(0,i),1)) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}

	j = i+1;
	i = 0;
	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count) i++;
	if (i+j == count || i > 2) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}
	// check if the number corresponding to the day is a valid day
	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}

	j = i+3;
	i = 0;
	// by default, asume a one-digit month. If it was a two-digit month, add one to counter 
	if (addOne) j++;
	// Loop through the last digits until the end (corresponding to the year)
	while (i+j < count) i++;
	if (i != 2 && i != 4) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}
	// check if the number corresponding to the year is a valid year
	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg(oInpBox, sFieldName);
		return false;
	}

	return true;
}

/****************************************************************
* PURPOSE:  Returns true if the string is a valid date number.
*	A method is passed in (1 = month, 2 = day).  If the string is
*	nonnumeric, false is passed back.  If the day in the date string
*	is greater than 31, false is returned.  If the month is greater
* than 12, an error is returned.
*****************************************************************/
function isDateNumber(strNum,method) {
	var str = new String(strNum);
	var i = 0;
				
	// First check that the string passed is numeric and positive
	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;
				
	// Check for a valid month (method 1)
	if (method == 1) {
		if (parseInt(str) < 1 || parseInt(str) > 12) return false;
	}

	// Check for a valid day (method 2)
	if (method == 2) {
		if (parseInt(str) < 1 || parseInt(str) > 31) {
			return false;
		}
	}
				
	// Check that every singular character is a number
	for (i = 0; i < str.length; i++) {
		if (str.length == 4 && i == 0) {
			// prevents entering a four digit year starting with zero
			if (str.charAt(i) < '1' || str.charAt(i) > '9') return false;
		}
		else {
			if (str.charAt(i) < '0' || str.charAt(i) > '9') return false;
		}
	}
				
	// Passed validation: return true
	return true;
}

/****************************************************************
* PURPOSE: Displays an alert box with the passed in string...
*****************************************************************/
function PromptErrorMsg(oInpBox, sFieldName)
{
	alert("You have entered an invalid date for " + sFieldName + ".  Please make sure your date format is in M/D/Y format.");
	oInpBox.focus();
}


function formHandler(form,selectbox) {
	var windowprops = "height=500,width=500,location=no,"
	+ "scrollbars=yes,menubars=no,toolbars=no,resizable=yes";
	
	if (selectbox == 'WebSiteAdmin') {
		var URL = form.WebSiteAdmin.options[form.WebSiteAdmin.selectedIndex].value;
		if (URL == 'HideEditButtons') {
			setEditButtons('0');
			URL = '';
		}
		else if (URL == 'ShowEditButtons') {
			setEditButtons('1');
			URL = '';
		}
		else if (URL == 'SetOverrideDate') {
			setDateField(document.MemberToolbar.OR);
			top.newWin = window.open(sWebRootPath + 'Secure/Includes/calendar.html','cal','WIDTH=208,HEIGHT=230');
			URL = '';
		}
		else if (URL == 'DB') {
			top.newWin = window.open(sWebRootPath + 'display/default.asp?org=' + lMemberOrgID,'DB','location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes');
			URL = '';
		}
		form.WebSiteAdmin.selectedIndex = 0;
	}
	else if (selectbox == 'Messages') {
		var URL = form.Messages.options[form.Messages.selectedIndex].value;
		form.Messages.selectedIndex = 0;
	}
	else if (selectbox == 'RevenueGen') {
		var URL = form.RevenueGen.options[form.RevenueGen.selectedIndex].value;
		form.RevenueGen.selectedIndex = 0;
	}
	else if (selectbox == 'DocsPics') {
		var URL = form.DocsPics.options[form.DocsPics.selectedIndex].value;
		form.DocsPics.selectedIndex = 0;
	}
	else if (selectbox == 'Reports') {
		var URL = form.Reports.options[form.Reports.selectedIndex].value;
		form.Reports.selectedIndex = 0;
	}
	else if (selectbox == 'Help') {
		var URL = form.Help.options[form.Help.selectedIndex].value;
		form.Help.selectedIndex = 0;
	}
	if (URL != '') {
		window.open(URL,'customize',windowprops);
	}
}

function loadVideoWindow(sURL,sName,sFeatures) {

	var win = window.open(sURL,sName,sFeatures);
	win.focus();

}
