<!--

var iw_String = {
	/**
	*This function removes leading and trailing whitespace from a string
	*@author found on net
	*@param str this is the string that will be stripped of it's leading and trailing whitespace
	*/
	trim: function (str){
		if(str != null){
			try{
				str = str.replace(/^\s*|\s*$/g,"");
			}catch(err){
				str = str;
			}
		}else{
			str = "";
		}
		return str;
	},
	replace: function(str, find, rep){
		var myStr = str.toString()
		return myStr.replace(/find/g, rep); 
	}
}

function iwValidateNumber(field, defval, fieldname){
    var tval = String(field.value);
    tval = tval.replace(/,/g,"");
    tval = tval.replace("$","");
    tval = tval.replace("%","");
    var newrem = Number(tval);
    if(isNaN(newrem)){
        alert("You must enter a valid number in the " + fieldname + " field.");
        field.value = field.defaultValue;
        field.blur();
        field.select();
        field.focus();
        return false;
    } else {
        field.value = tval;
    }
    return true;
}

/**
* This method validates date or datetime input fields
* TODO - Pass in a boolean if the field is required?
*/
function val_date(input,defVal){
	var date = input.value;
	if(date == '' || date.length==0){ //check here for boolean required
		return false;
	}
	var checkTime=false;

	if(date.length>12){
		checkTime=true;
		date=date.toUpperCase();
		var time = date.slice(date.indexOf(" ")+1);
		date = date.substr(0,date.indexOf(" "));
	}
	
	date = date.split("/");
	
	var year = date[2];
	if(year != null && year.length > 0){
		if(year.length == 2){
			if(eval(year) > 50){
				year = "19" + year;
			}else{
				year = "20" + year;
			}
		}
	}
	
	var month = date[0]-1;
	var day = date[1];
	var theDate = new Date(year,month,day);

	//set the hours/minutes/seconds/milliseconds
	theDate.setSeconds(0);
	theDate.setMilliseconds(0);		
	if(checkTime){ //set the hours of theDate based on input
		var m = time.substr(time.indexOf(" ")+1); //grab am or pm 
		time = time.substr(0,time.indexOf(" ")).split(":"); //grab array with hours, minutes
		var hour = (time[0]=='12') ? new Number(0) : new Number(time[0]); //make a number out of hours, if it's 12, set it to 0
		hour = (m=='PM') ? hour + 12 : hour; //if it's a PM time, add 12 to hours
		var minute = new Number(time[1]);//store minutes
		theDate.setHours(hour);
		theDate.setMinutes(minute);
	}else{
		theDate.setHours(0);
		theDate.setMinutes(0);
	}
	
	/* check for errors in date */
	var goodDate = true;
	if(theDate.getFullYear() != year){
		goodDate=false;
	}
	if(theDate.getMonth() != month){
		goodDate=false;
	}
	if(theDate.getDate() != day){
		goodDate=false;
	}
	/* additional checking for time */
	if(checkTime){
		if(theDate.getMinutes() != minute){
			goodDate=false;
		}
		if(theDate.getHours() != hour){
			goodDate=false;
		}
	}
	
	if(!goodDate){
		alert('You must enter a valid date in the '+input.name+' field.');
		input.value=defVal;
		input.focus();
		return false;
	}else{
		var month = theDate.getMonth()+1;
		if(eval(month) < 10){
			month = "0" + eval(month);
		}
		var day = theDate.getDate();
		if(eval(day) < 10){
			day = "0" + eval(day);
		}
	
		input.value = month + "/" +day + "/" + theDate.getFullYear();
	}
	return theDate;
}
	
function RemoveBad(field){
	var InStr = String(field.value);
	InStr = InStr.replace(/\</g,"");
    InStr = InStr.replace(/\>/g,"");
    InStr = InStr.replace(/\"/g,"");
    InStr = InStr.replace(/\'/g,"");
    InStr = InStr.replace(/\%/g,"");
    InStr = InStr.replace(/\;/g,"");
    InStr = InStr.replace(/\(/g,"");
    InStr = InStr.replace(/\)/g,"");
    InStr = InStr.replace(/\&/g,"");
    InStr = InStr.replace(/\+/g,"");
    field.value = InStr;
    return InStr;
}



//main search functions
  //sortfield and sortdirections for main searches
  //defined in each page used
	function ScrollTo(arg) {
	    document.fmain.resultsPage.value = arg;
	    document.fmain.submit();
	}
	
	function SortOn(arg){
	    if(arg == SortField){
	        if(SortDirection == "ASC"){
	            document.fmain.SortDirection.value = "DESC";
	        } else {
	            document.fmain.SortDirection.value = "ASC";
	        }
	    } else {
	        document.fmain.SortDirection.value = "ASC";
	        document.fmain.SortField.value = arg;
	    }
	    document.fmain.submit();
	}
//end main search functions	


//this function takes an input (text/password/etc) 
//and clears its value
function clearField(field){field.value='';}

/**
*This function takes in an object, and will find it's Y coordinate
* this is used for jumping to the anchor in the onload event
*/
function findPosY(obj){
	if(obj){
		var curtop = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
}

/**
*This method takes in an X and Y coordinate and will scroll the page to these locations
*/
function anchorScroll(x,y){
	self.scrollTo(x,y);
}

//this function will select/deselect
//multiple checkboxes with the same name
var checkflag = "false";
function checkMultiple(field) {
	if(field!=null){
		numFields = field.length;
		if(!numFields){
			numFields = 1;
		}
		if (checkflag == "false") {
			for (i = 0; i < numFields; i++) {
				if(numFields>1){
					field[i].checked = true;
				}else{
					field.checked=true;
				}
			}
			checkflag = "true";
		}else{
			for (i = 0; i < numFields; i++) {
				if(numFields>1){
					field[i].checked = false;
				}else{
					field.checked=false;
				}
			}
			checkflag = "false";
		}
	}
}
/**
* This function takes in a checkbox input element, and a list of field names 
* to enable or disable, depending on the checkbox.checked property
* If boolean onChecked is true - then the form elements will toggle when the box is checked
* Else if onChecked is false - the form elements will toggle when the box is unchecked
* If boolean clearElements is true, when the form elements are disabled, their values will be cleared
*/
function toggleFormElements(checkbox,onChecked,clearElements){
	if((checkbox.checked==true && onChecked==true) || checkbox.checked==false && onChecked==false){
		for(i=3;i<arguments.length;i++){
			$(arguments[i]).disabled='';
			$(arguments[i]).className = "";
		}
		if($(arguments[3])){
			if($(arguments[3]).tagName == 'SELECT'){
				Field.focus($(arguments[3]));
			}else{
				Field.activate($(arguments[3]));
			}			
		}
	}else{
		for(i=3;i<arguments.length;i++){
			$(arguments[i]).disabled='true';
			$(arguments[i]).className = "disabled"
			if(clearElements){
				if($(arguments[i]).tagName == 'SELECT'){
					$(arguments[i]).selectedIndex = 0;
					//$(arguments[i]).selectedIndex = -1;
				}else{
					$(arguments[i]).value='';
				}
			}
		}
	}
}

function confirmDelete(name, extra){
	if(name==null || name.length==0){
		name = 'Object';
	}
	var textConfirm = 'Are you sure you want to delete this '+name+'?';
	if(extra!=null && extra.length>0){
		textConfirm += '\n\n'+extra+'.';
	}
	if(confirm(''+textConfirm)){
		return true;
	}else{
		return false;
	}
}




/**
* This method pops up a new window with no toolbar, etc.
* It also sets the new window to 'dependent', meaning when the parent window is closed
* the popup will also be closed.
* @param url	The url/location of the new window
* @param width	The width of the new window
* @param height	The height of the new window
*
*/

function popup_menu(url,w,h, menu){
	var curDate = new Date();
	var winName = curDate.getHours() + curDate.getMinutes() + curDate.getSeconds() + curDate.getMilliseconds();
	var newWind = window.open(url,winName,'toolbar=0,dependent=1,directories=0,scrollbars=1,location=0,status=0,menubar=' + menu +',resizable=1,width='+w+',height='+h+'');
	if(newWind.opener==null){
		newWind.opener=window;
	}
}
function popup(url,w,h){
		var curDate = new Date();
	var winName = curDate.getHours() + curDate.getMinutes() + curDate.getSeconds() + curDate.getMilliseconds();
	var newWind = window.open(url,winName,'toolbar=0,dependent=1,directories=0,scrollbars=1,location=0,status=0,menubar=0,resizable=1,width='+w+',height='+h+'');
	if(newWind.opener==null){
		newWind.opener=window;
	}
}


function popup_color(FormName, IDField, NameField){
	var theURL = 'popup_color.jsp?FormName='+FormName+'&IDF='+IDField+'&NameF='+NameField;
	popup(theURL,210,210);
}
function popup_audit(ParentTableID, ParentID){
	var theURL = 'popup_audit.jsp?ParentTableID='+ParentTableID+'&ParentID='+ParentID;
	popup(theURL,750,500);
}


//this function will check whether an element is hidden, and change
//its display to the opposite 
//pass in the ID of one div/table/etc to hide or show
//also, pass in an optional form element to focus on display
//optional - defaultHidden: if the element is set to display:none in the style sheet
function swap(box1, focus1, boolNoBlock){
	var box1 = document.getElementById(box1);
	if(box1 && box1.style.display==''){ //If this is the first time swapping this object, grab its style from the style sheet
		if (box1.currentStyle){//IF INTERNET EXPLORER
			var currDisp = eval('box1.currentStyle.' + 'display');
		}
		else if (document.defaultView.getComputedStyle){//IF MOZILLA
			var currDisp = document.defaultView.getComputedStyle(box1,null).getPropertyValue('display');
		}
		//Might check here to over-ride style in style sheet with inline style?
		box1.style.display=currDisp; //set the box's display to stylesheet value
	}
	
	if (boolNoBlock) {
		var disp = "";
	} else {
		var disp = "block";
	}
	if (box1)
		box1.style.display=(box1.style.display=="none")?disp:"none"; //if none, go to block or inline & vice versa
	if(focus1 && box1){
		if(box1.style.display==disp){Field.activate($(focus1));}
	}
}

/**
* This function will show the first element and hide the next two
* useful in hiding/display inactive,active, or both (projects/opportunities/activities)
*/
//do not use!!!!!!  only in frag_child_opp and frag_child_proj
function showAndHide(show,hide1,hide2){
	$(show).style.display='block';
	$(hide1).style.display='none';
	$(hide2).style.display='none';
	
	$(show+'_link').style.fontWeight='bold';
	$(hide1+'_link').style.fontWeight='normal';
	$(hide2+'_link').style.fontWeight='normal';
}

//-->