var formWasSubmitted = false;

function submitForm(formName) {
	if (!formWasSubmitted) {
		formWasSubmitted = true;
		eval('document.' + formName + '.submit()');
	}
}

function disableSubmit(this_form) {
	this_form.submit.disabled = true;
	return true;
}
function confirmAction(msg) {
	if (confirm ("Are you sure you want to " + msg)) {
		return true;
	} else {
		return false;
	}
}
function FlashInstalled() {
	result = false;

	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	}
	else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
	{
		// IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
		eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)	result = true; xObj = null;	} catch (e)	{}');
	}
	return result;
}

function FlashWrite(url,width,height) {
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write('  codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=5,0,0,0" ');
	document.write('  WIDTH=' + width + ' HEIGHT=' + height + '>');
	document.write(' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high> <param name="wmode" value="transparent">'); 
	document.write(' <EMBED src="' + url + '" quality=high ');
	document.write(' wmode="transparent" swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);
	document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
	document.write(' </EMBED></OBJECT>');
}

var browser_type = navigator.appName;
var browser_version = navigator.appVersion;

isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
IE4plus = (document.all) ? true : false;

if (!isMac && IE4plus) {
	browserSupportsDHTML = true;
} else {
	browserSupportsDHTML = false;
}
function IsNumeric(fieldName) {
	textObj = document.getElementById(fieldName);
	text = textObj.value;

	var ValidChars = "-0123456789.";
	var IsNumber=true;
	var testChar;
	if (text.length < 1) {
		IsNumber = false;
	}

	for (i = 0; i < text.length && IsNumber == true; i++) {
		testChar = text.charAt(i);
		if (ValidChars.indexOf(testChar) == -1) {
			IsNumber = false;
		}
	}

	
	// test - not first
	var dash = text.indexOf('-', 1)
	if (dash > 0) {
		IsNumber = false
	}
	
	// test for multiple .
	var dec = text.indexOf('.', 1)
	if (dec > 0) {
		var dec2 = text.indexOf('.', dec+1)
		if (dec2 > 0) {
			IsNumber = false
		}
	}

	if (!IsNumber) {
		alert('Please make sure you enter real numbers');
		textObj.focus();
		return false;
	} else {
		return true;
	}
}


function displaySection(display, displayId) {
	var objDisplay = document.getElementById(displayId);
	
	if (display) {
            objDisplay.style.visibility = "visible"
			objDisplay.style.display=(document.all)? "block" : "table-row" //may need 2 methods for this- add_mod_suppliers
          //  objDisplay.style.display    = "block"
    } else {
            objDisplay.style.visibility = "hidden"
            objDisplay.style.display    = "none"
    }
}

function isDate (month, year, day_object, this_form) {
	var today = new Date();
	day = day_object[day_object.selectedIndex].value;
		
	month = month-1;
	if (today.getMonth() > month) 
		year = ((year==99999) ? today.getFullYear() + 1:year);
	else 
		year = ((year==99999) ? today.getFullYear():year);

	var test = new Date(year,month,day);
	
	if ((year  == test.getFullYear()) &&
		(month == test.getMonth()) &&
		(day   == test.getDate())) {
		makeDatesClose(this_form, year, day_object);
		return true;
	}
	else {
		//alert("Invalid date, click ok to correct the date");
		for (d=28; d < day ;d++) {
			var test = new Date(year,month,d);
			
			if ((year  == test.getFullYear()) &&
			(month == test.getMonth()) &&
			(d == test.getDate())) {
				day_object[d-1].selected = true;
			}
			else {
				break;
			}
		}
		makeDatesClose(this_form, year, day_object);
		return false;
	}
}


function makeDatesClose(this_form, this_year, day_object) {
	try {
		var date1_month = this_form.date1_month.value*1;
		var date2_month = this_form.date2_month.value*1;
		var date1_day = this_form.date1_day.value*1;
		var date2_day = this_form.date2_day.value*1;
		if (date1_month <= date2_month) {
			months_diff = date2_month - date1_month;
		} else {
			months_diff = date2_month - date1_month + 12;
		}
		
		// if dates are within 4 months, auto change other date field to date - 7
		if ((months_diff > 4)
			|| ((months_diff == 0) && (date1_day >= date2_day))) {
			changeDate2(this_year, day_object, this_form);
		}
		
		// if months are equal and day2 < day1
		if ((date1_month == date2_month)
			&& (this_form.date1_day.value*1 > this_form.date2_day.value*1)) {
			this_form.date2_day.value = this_form.date1_day.value*1;
		}
	}
	catch (e) {
		// do nothing
	}
}

function areaWindow(property) {
	bookWindow = window.open(property,  '_blank', 'height=500,width=400,scrollbars=yes');
	bookWindow.focus();
}

function newWindow(property) {
	bookWindow = window.open(property, '_blank', 'height=500,width=680,scrollbars=yes')
	bookWindow.focus()
}

function newTallWindow(property) {
	bookWindow = window.open(property, '_blank', 'height=700,width=680,scrollbars=yes')
	bookWindow.focus()
}
function al() {
	alert('ok');
}
