var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

/*function deal_with_error(msg, url, line) {
    alert('Message: ' + msg + '\n' + 'In file: ' + url + '\n' + 'At line: ' + line);
    return true;
}

self.onerror = deal_with_error;*/

// checks for null values upon form submit
function CheckNull(object, message) {
	if (object.value == '') {
		alert(message);
		return false;			
	}
	else
		return true;
}	
/*
//autosaves a form -- for use in Wizards ONLY
function AutoSave(ActionName, FormName) { // ActionName: Array containing actions we want to check; FormName: name of the form on the action pages
	var Old_Url = new String(window.top.Frame_Main.location) // source page where the form resides
	var j = ActionName.length; // number of Actions we're checking; eg. Franchisee_Form, Franchisee_Details_Form, etc.
	for (i=1; i<=j; i++) { // loop through all the actions and find the one in the main frame
		if (Old_Url.indexOf(ActionName[i-1]) != -1) {			
			var FName = FormName[i-1];
			Send_Form = eval("window.top.Frame_Main." + FName);
			Send_Form.submit();
			//Send_Form.onSubmit = alert("s")
			//Send_Form.onSubmit = CheckNull(window.top.Frame_Main.document.myForm.Franchisee_Region_ID, 'Please select a Region'); //alert('Submitted');
		}
    }
}
*/
//autosaves a form -- for use in Wizards ONLY
function AutoSave(Exclusions) { // ActionName: Array containing actions we want to check; FormName: name of the form on the action pages
	var Old_Url = new String(window.top.Frame_Main.location) // source page where the form resides
	var j = Exclusions.length; // number of Actions we're checking; eg. Franchisee_Form, Franchisee_Details_Form, etc.
	for (i=1; i<=j; i++) { // loop through all the actions and find the one in the main frame
		if (Old_Url.indexOf(Exclusions[i-1]) != -1) {
			alert("Exclude this.");
		}
		else {
			//alert("send please");
			window.top.Frame_Main.myForm.submit();
		}
    }
}

//Creates a pop-UP window
function popUP(myID, h, w, WinName, menubar,resizable,scrollbars,toolbar) {	
	if (NS4) 
		newWindow = window.open(myID,WinName,"menubar="+menubar+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",width=" + w + ",height="+ h+ ",screenX=0,screenY=0");
	else
		newWindow = window.open(myID,WinName,"menubar="+menubar+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",width=" + w + ",height="+ h + ",top=0,left=0");
	newWindow.focus();
}	

//Creates a pop-UP window with the ability to assign the position
function popUP2(myID, h, w, WinName, menubar,resizable,scrollbars,toolbar,top,left) {	
	if (NS4) 
		newWindow = window.open(myID,WinName,"menubar="+menubar+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",width=" + w + ",height="+ h+ ",screenX=0,screenY=0");
	else
		newWindow = window.open(myID,WinName,"menubar="+menubar+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",width=" + w + ",height="+ h + ",top=" + top + ",left=" + left);
	newWindow.focus();
}	

// pops up a confirm dialog box 
function confirmAction(message) {
	return confirm(message);
}	

//print article
function print_art(){
	alert("Once printing has completed, close this window using your browser's close button. NOTE: if the 'Print Dialog' box does not automatically open, click your browser's print button.");
	window.print();
}
//print calendar
function print_cal(){
	alert("For best print results, from the 'Print Dialog' box select 'Landscape'. Once completed, close this window using your browser's close button. NOTE: if the 'Print Dialog' box does not automatically open, click your browser's print button.");
	window.print();
}

function CheckAll(what) {
	var form_name = eval(what)
	for (var i=0, j=form_name.elements.length; i<j; i++) 
		if (form_name.elements[i].type == 'checkbox')
			form_name.elements[i].checked = 1
}		

function ClearAll(what) {
	var form_name = eval(what)
	for (var i=0, j=form_name.elements.length; i<j; i++) 
		if (form_name.elements[i].type == 'checkbox')
			form_name.elements[i].checked = 0
}	

function Max_Length(what, maxlength, message){
	var Check_Length = new String(what)
		if (Check_Length.length > maxlength){
			alert(message)
			return false
		}	
	return true;	
}

function Strip_Path(StripString) {
	var myString = new String (eval(StripString))
	//strip the directory path from the string
	var t = myString.lastIndexOf("/");
	myString = (myString.substring(t + 1, myString.length));
	//strip the file extention and paramters of the string
	var t = myString.indexOf(".");
	return (myString.substring(0, t));
}

function LTrim(str){
	if(str==null){
		return null;
	}
	for(var i=0;str.charAt(i)==" ";i++);
		return str.substring(i,str.length);
}

function RTrim(str){
	if(str==null){
		return null;
	}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
		return str.substring(0,i+1);
}

function Trim(str){
	return LTrim(RTrim(str));
}

