// JavaScript Document

	function isNull(val){return(val==null);}
	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 in_array(needle, haystack, argStrict) {
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
		// *     returns 1: true
	 
		var found = false, key, strict = !!argStrict;
	 
		for (key in haystack) {
			if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
				found = true;
				break;
			}
		}
	 
		return found;
	}


//Changes visibility of a form element from an onclick event
//ex:  showElement(this, "specialChars", this.src.indexOf("_dn.gif") != -1);
function showElement(obj, obj_To_Change, modifier) { 
	var chng_Obj = MM_findObj(obj_To_Change);
	if(eval(modifier)){ eval("chng_Obj.style.visibility = 'visible'"); eval("chng_Obj.style.display = 'block'"); }
	else{ eval("chng_Obj.style.visibility = 'hidden'"); eval("chng_Obj.style.display = 'none'"); }
}



function SetFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i=0; i<field.length; i++) {
      if ( (field.elements[i].type != "image") &&
           (field.elements[i].type != "hidden") &&
           (field.elements[i].type != "reset") &&
           (field.elements[i].type != "submit") ) {

        document.forms[0].elements[i].focus();

        if ( (field.elements[i].type == "text") ||
             (field.elements[i].type == "password") )
          document.forms[0].elements[i].select();

        break;
      }
    }
  }
}

//Disables the submit buttons on a form
//  ex: <form onSubmit="disableSubmit(this)">
function disableSubmit(theform) {
	if (document.all || document.getElementById) {
	  for (i = 0; i < theform.length; i++) {
		var tempobj = theform.elements[i];
		if (tempobj.type != null)  if (tempobj.type.toLowerCase() == "submit")	tempobj.disabled = true;
	  }
	}
}

function update_and_close(){
	//window.opener.location.href = window.opener.location.href;
	window.opener.location.reload(true);
	if (window.opener.progressWindow){ window.opener.progressWindow.close(); } 
	parent.window.close();	
}

function open_popup(url, window_name, width, height){	
  if(!window_name) window_name='popup';
  if(!width) width='300';
  if(!height) height='300';
  window.open(url,window_name,'width='+width+',height='+height+',resizable=1, scrollbars=1');
}


function nudgeFirefox(){ 
    /* sort out a height problem in firefox */ 
    document.getElementsByTagName('body')[0].style.width='99%'; 
    document.getElementsByTagName('body')[0].style.width='auto'; 
}

function set_input(e, v){
	var obj;
	obj = MM_findObj(e);
	obj.value = v;
}

function toggle_input(e){
	var obj;
	obj = MM_findObj(e);
	if(obj.checked) obj.checked = false;
	else obj.checked = true;
}

function _CF_hasValue(obj, obj_type){
    if (obj_type == "TEXT"){
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    }
    else if (obj_type == "EMAIL"){
       	if (obj.value.length == 0){ 
      		alert('Missing Email Field\r\n\nYou must fill this in.');
			return false;
		}else if ((obj.value.indexOf('@') < 0) || (obj.value.indexOf('.') < 0 )){
			alert("Email invalid");
			return false; 
		}else
	 	 	return true;	
	}
}


function _CF_onError(form_object, input_object, object_value, error_message){
	alert(error_message);
	input_object.focus(); input_object.select();
    return false;	
}


//Protect agenst frames
function unframe_page(){	
	if(window.top.location.href != window.location.href){ 
		window.top.location.href = window.location.href;
	}
}


function movie_DoFSCommand(command, args) { 
  if (command == "display_text") { 
    obj = MM_findObj(args);
	//alert(obj.style.display);
	obj.style.display = 'block';
  }
}

function hideMe(id){
  myobj = MM_findObj(id);
  myobj.style.display = 'none';
}


//Detect the Media Object for flash, WMV, etc...
function getMovieObject(movieName){
  if (window.document[movieName]){
      return window.document[movieName];
  }
  
  if (navigator.appName.indexOf("Microsoft Internet")==-1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
	  
  }else{ // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    return document.getElementById(movieName);
  }
}

//Open new window for directions with Google Maps
function getDirections(start, end){
	//replace spaces with +s on start 
	s = new String(start);
	start = s.replace(/ /,"+");

	//replace spaces with +s on end
	e = new String(end);
	end = e.replace(/ /,"+");
	
	window.open("http://maps.google.com/maps?f=d&hl=en&saddr="+ start +"&daddr="+ end +"&z=13&om=1", "googlemapsdirections");
}



  //Quickly update the css class of an object
	function change_class (ob, classtxt) {
		if (document.getElementById) {
		  document.getElementById(ob).className = classtxt;
		} else {
		  document.all[ob].className = classtxt;
		} 
	}
	
	

	function check_element (ob) {
		if (document.getElementById) {
		  document.getElementById(ob).checked = "checked";
		} else {
		  document.all[ob].checked = "checked";
		} 
	}	
	
	
	
  //Mark Parent as checked.  (Inputs get checked, and labels get clicked)	
	function trigger_parent (e, lvl, tags) {
		
		if(!lvl) lvl = 4;
		if(!tags) tags = /(label)|(input)/i;
		
		for(x=0;x<lvl;x++){
			//alert(e.tagName);
			if(e.tagName.match( tags )){
				if(	e.tagName.match( /label/i ) ){
					//Click a label tag
					triggerEvent(e, 'click');
				}else{
					//Check the imput tag
					e.checked = 'checked';
				}
				break;
			}
			e = e.parentNode;
		}
	}
	
  //Triggers any event - cross browser
	//target = Object
	//eventStr = any event without the 'on'
	function triggerEvent(target, eventStr){
		
		//var target=document.getElementById(e);
		
		if(document.dispatchEvent) { // W3C
			var oEvent = document.createEvent( "MouseEvents" );
			oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
			target.dispatchEvent( oEvent );
		}
		else if(document.fireEvent) { // IE
			target.fireEvent("on"+ eventStr);
		}	
	}
	
	
	
	function confirmDelete( url ) {
		if( confirm("Do you really want to delete selected item.") ){
			document.location.href = url;	
		}
	}	
	
	
	function MM_jumpmenu(targ,selObj,restore){ //v3.0 \n";
		if(selObj.options[selObj.selectedIndex].value != ''){
			eval(targ + ".location='"+selObj.options[selObj.selectedIndex].value+"'");
		}
		if (restore) selObj.selectedIndex=0; ;
	}	


	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

