 
 var isNN = (navigator.appName.indexOf("Netscape") != -1);
 var isIE = (navigator.appName.indexOf("Microsoft") != -1);
 
 // if not a number, toss an alert and reset the field to 0
 function validateInt(field,orig)
 {
   if(isNaN(field.value))
   {
     alert("That is not a valid quantity.")
     field.value = orig;
     return false;
   }
 }
 
 // if blank, toss an alert
 function validateNotBlank(field,desc){
   if(field.value == "")
   {
     alert("The " + desc + " can not be blank.");
     return false;
   }
 }
 
 function showHideDiv(obj)
 {
   var s;
   if(isIE)
   {
     s = document.all[obj].style.display;
     if(s == 'block')
     {
       s = 'none';
     }else{
       s = 'block';
     }
     document.all[obj].style.display = s;
   }else{
   	obj = document.getElementById(obj);
     s = obj.style.display;
     if(s == 'block')
     {
       s = 'none';
     }else{
       s = 'block';
     }
     obj.setAttribute('style','display:'+s);
   }
 }

 function changeStyle(obj,attr,val)
 {
   var s;
   if(isIE)
   {
    	document.all[obj].style[attr] = val;
   }else{
   	obj = document.getElementById(obj);
     	obj.setAttribute('style',attr+':'+val);
   }
 }

 
 function showHide(obj,style)
 {
   var s;
   if(isIE)
   {
     s = document.all[obj].style.display;
     document.all[obj].style.display = style;
   }else{
     obj = document.getElementById(obj);
     s = obj.style.display;
     obj.setAttribute('style','display:'+style);
   }
 }
 
 
 function checkUncheck(field,check)
 {
   if(field.length)
   {
     for (i = 0; i < field.length; i++)
     {
       field[i].checked = check;
     }
   }else{
     field.checked = check;
   }
 }
 
 function addOption(theSel, theText, theValue)
 {
   var newOpt = new Option(theText, theValue);
   var selLength = theSel.length;
   theSel.options[selLength] = newOpt;
 }
 
 function deleteOption(theSel, theIndex)
 { 
   var selLength = theSel.length;
   if(selLength>0)
   {
     theSel.options[theIndex] = null;
   }
 }
 
 function moveOptions(theSelFrom, theSelTo)
 {
   
   var selLength = theSelFrom.length;
   var selectedText = new Array();
   var selectedValues = new Array();
   var selectedCount = 0;
   
   var i;
   
   // Find the selected Options in reverse order
   // and delete them from the 'from' Select.
   for(i=selLength-1; i>=0; i--)
   {
     if(theSelFrom.options[i].selected)
     {
       selectedText[selectedCount] = theSelFrom.options[i].text;
       selectedValues[selectedCount] = theSelFrom.options[i].value;
       deleteOption(theSelFrom, i);
       selectedCount++;
     }
   }
   
   for(i=selectedCount-1; i>=0; i--)
   {
     addOption(theSelTo, selectedText[i], selectedValues[i]);
   }
   
 }
 
 function selectAll(theSelFrom)
 {
   var selLength = theSelFrom.length;
   for(i=selLength-1; i>=0; i--)
   {
   	theSelFrom.options[i].selected = true;
   }
 }
 
 function confirmDelete(url) {
 	var answer = confirm("Are you sure you want to delete this? This could cause associated data to be deleted or become disassociated.")
 	if (answer){
 		window.location = url;
 	}
 }

 function confirmCancel(url) {
 	var answer = confirm("Are you sure you want to cancel this? You will not be able to reactivate it later. Consider Pushing if you'd like to come back to it later.")
 	if (answer){
 		window.location = url;
 	}
 } 

 function confirmRollbackl(url) {
 	var answer = confirm("Are you sure you want to roll this request back 1 stage?")
 	if (answer){
 		window.location = url;
 	}
 } 


 function confirmCancelCampaign(url) {
 	var answer = confirm("Are you sure you want to cancel this campaign and all requests?")
 	if (answer){
 		window.location = url;
 	}
 } 
  
 function openCalendar(formName,formField){
 	url = '/success/secure/get_calendar/'+formName+'/'+formField;
 	openWindow(url,'calendar','width=225,height=200');
 	
 }
 
 function openWindow(theURL,winName,features) { //v2.0
   window.open(theURL,winName,features);
 }
 
 
 // set the main window name for any opener events
window.name = "main";


function changeText(fillMe,newContent) {
    var newStuff = document.getElementById(newContent).innerHTML;
    document.getElementById(fillMe).innerHTML = newStuff;
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
