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(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));
}

function isdefined(variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function Add_A_Favorite(the_title) 
{ 
if (window.external) 
	// if the browser is IE open the add favorite window
	{
	external.AddFavorite(location.href, the_title)
	// Add the document location and title to the AddFavorite window
	}
	else 
	// Display and alert box for any other browser.
	{
	alert("Sorry, your browser doesn't support this feature." + 
	"\nPlease use the bookmark feature of your browser to save the location of this page.");
	}
}

function setVisibility(id) {
	if (document.getElementById(id).style.display == 'none') 
		document.all[id].style.display = 'inline';
	else
		document.all[id].style.display = 'none';
}

function Refresh_Parent_Win() {
	if (!parent.opener.closed)
		parent.opener.location.reload();
	window.top.focus();
	window.top.close();		
}

function isZip(s) { 
	var ret = true
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 
     if (!reZip.test(s)) {          
          ret = false;
     }
 
	return ret;
}

