/*
 	Various Javascript Functions
	By: gary conley 
	Date: 08/17/2007
	
*/

/* This method removes all options from a HTML SELECT control */
function removeOptionsFromSelect( theSel ) {
	for(i=theSel.length-1; i>=0; i--)
   	 	theSel.options[0] = null;
}
/* This method adds an option and value to an HTML SELECT control */
function addOptionsToSelect( theSel, newText, newVal ) {
	var l = theSel.length;
	var newOpt = new Option(newText, newVal);
	theSel.options[l] = newOpt;
}
/* This method adds an option and value to an HTML SELECT control and Sets it Selected */
function addOptionsToSelectSelected( theSel, newText, newVal ) {
	var l = theSel.length;
	var newOpt = new Option(newText, newVal);
	theSel.options[l] = newOpt;
	theSel.options[l].selected = true;
	
}

/* This method returns the index of value of the HTML SELECT control based on the value passed in */
function setOptionIndexByValue( theSel, theValue ) {
	var valIndex=0;
	for (var x=0;x<theSel.options.length; x++) 
		if (theSel.options[x].value == theValue) {
			valIndex=x;
			theSel.options[x].selected=true;
			break;
			}
		   else
		    if (theSel.multiple)
			   theSel.options[x].selected=false;
	return valIndex;			
}

function setCookie(cookieName, value, expDays) {
	var exp = new Date();     //set new date object
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * expDays)); 
	if (expDays==0) 
	    document.cookie = cookieName + "=" + escape(value)
	   else 
		document.cookie = cookieName + "=" + escape(value) + "; path=/" + ((expDays == null) ? "" : "; expires=" + exp.toGMTString());
}

function getCookie (cookieName) {
    var dc = document.cookie;
    var cname = cookieName + "=";
    if (dc.length > 0) {
      begin = dc.indexOf(cname);
      if (begin != -1) {
        begin += cname.length;
        end = dc.indexOf("", begin);
        if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
        }
      }
    return null;
}

function getProperCase(inText) {
	var tempStr=inText.toLowerCase();
	var tempChar='';
	var outStr='';
	var wordArray=tempStr.split(' ');
	for (i=0;i<wordArray.length;i++) {
		tempChar=wordArray[i].substr(0,1);
		tempChar=tempChar.toUpperCase();		
		if (outStr == '')
			outStr = tempChar + wordArray[i].substr(1)
		   else	
			outStr = outStr + ' ' + tempChar+wordArray[i].substr(1);
	}
	return outStr;	
}	

function getLowerCase(inText) {
	return inText.toLowerCase();	
}	

function getUpperCase(inText) {
	return inText.toUpperCase();	
}	





