
// Global
var myRemote;
var navURL;
var myNavPopup;
var mainEditor;

iens6=document.all||document.getElementById
ns4=document.layers

<!--GLOBAL VARIABLES-->
var thename
var theobj
var thetext
var winHeight
var winPositionFromTop
var winWidth
var startH=2
var openTimer
var scrollSpeed=30
var CURSOR_POS = 0;
var ON_DIV_MENU_ITEM = false;
<!--END GLOBAL VARIABLES-->

var description=new Array()


  
function launch(newURL, newName, newFeatures, orgName) {
remote = open(newURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;

  remote.opener.name = orgName;
  return remote;
}

function openWindow(loc) {
  var winl = (screen.width-750)/2;
  var wint = (screen.height-640)/2;

  myRemote = launch(loc,"FreeSurveys1","height=640,width=750,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top="+wint + ",left=" + winl,"Help");
  window.myRemote.focus();  
}

function openPreview(loc) {
  var winl = (screen.width-800)/2;
  var wint = (screen.height-640)/2;

  myRemote = launch(loc,"FreeSurveys1","height=640,width=800,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top="+wint + ",left=" + winl,"Help");
  window.myRemote.focus();  
}

function openLargeWindow(loc) {
  var winl = (screen.width-1040)/2;
  var wint = (screen.height-640)/2;

  myRemote = launch(loc,"FreeSurveys1","height=640,width=1024,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top="+wint + ",left=" + winl,"Help");
  window.myRemote.focus();  
}

function openWindowWithMenu(loc) {
  var winl = (screen.width-750)/2;
  var wint = (screen.height-640)/2;
  myRemote = launch(loc,"WindowWithMenu","height=640,width=800,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=1,resizable=1,scrollbars=1,status=0,toolbar=1,top="+wint+",left="+winl,"Help");
  window.myRemote.focus();  
}


function openSlideShow(loc) {
  myRemote = launch(loc,"SlideShow1","height=640,width=800,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0","Help");
  window.myRemote.focus();  
}

function miniPopup(loc) {
  var winl = (screen.width-450)/2;
  var wint = (screen.height-300)/2;

  myRemote = launch(loc,"FreeSurveys2","height=300,width=450,channelmode=0,dependent=0,directories=0,fullscreen=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top=" + wint + ",left=" + winl,"Help");
  window.myRemote.focus();  
}


function gotoLoc (loc) {
  var winl = (screen.width-640)/2;
  var wint = (screen.height-750)/2;

  myRemote = launch(loc,"FreeSurveys","height=640,width=750,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top=" + wint + ",left=" + winl,"Help");
  window.myRemote.focus();
}

function helpWindow(loc) {
  var winl = (screen.width-640)/2;
  var wint = (screen.height-700)/2;

  myRemote = launch(loc,"FreeSurveys3","height=640,width=700,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,top=" + wint + ",left=" + winl,"Help");
  window.myRemote.focus();
}


function addQuestion(form , base) {
   base += "?location=";
   base += form.location.options[form.location.selectedIndex].value;
   base += "&questionCategory=";
   base += form.questionCategory.options[form.questionCategory.selectedIndex].value;

   gotoLoc(base);
}


function refreshForm(form) {
    opener.document.forms[form].submit();
    window.close();
}

function refreshBuilder() {
    opener.document.DummyForm.submit();
    window.close();
}



function refreshLocation(loc) {
  if (opener && opener.document) {
    opener.document.location=loc;
    window.close();
  } else {
    document.location=loc;
  }
}

function refreshLocationWithAlert(loc, msg) {
  opener.document.location=loc;
  alert(msg);
  window.close();
}


function openWindowConditionalAlert(loc, condition, falseMessage) {
  if(condition == "true" ) {
    openWindow(loc);        
  } else {
    alert(falseMessage);
  }
}

function openPreviewConditionalAlert(loc, condition, falseMessage) {
  if(condition == "true" ) {
    openPreview(loc);        
  } else {
    alert(falseMessage);
  }
}


function closeWindow() {
  if (isInternetExplorer()) {
    window.opener='x';
  }
  window.close();
}

function refreshAdmin() {
  refreshLocation('showUpdate.do');
}

function refreshList() {
  refreshLocation('listSurveys.do');
}

function deleteWindow (loc) {
    if (confirm("Are You Sure ?")) {
        document.location = loc;
    }
}

function confirmDelete(loc, message) {
    if (confirm(message)) {
        document.location = loc;        
    }
}

function DropDownMenu(entered) {
  with (entered) {
  ref=options[selectedIndex].value;
  document.location=ref;
  }
}


function DropDownMenuWithPrefix(prefix, entered) {
  ref=entered.options[entered.selectedIndex].value;
  prefix += ref;
  document.location=prefix;
}

function DropDownMenuWithPrefixPopup(prefix, entered) {
  if (entered.selectedIndex > 0) {
    ref = entered.options[entered.selectedIndex].value;
    prefix += ref;
    gotoLoc(prefix);
  }
}


function SetChecked(val) {
  dml=document.form[0];
  len = dml.elements.length;
  var i=0;
  for( i=0 ; i<len ; i++) {
    if (dml.elements[i].name=='questionID') {
      dml.elements[i].checked=val;
    }
  }
}


function lookupAndClose(elementName, value) {
    opener.document.forms[0].elements[elementName].value = value;
    window.close();
}

function lookupDivAndClose(elementName, value, divId) {
    opener.document.forms[0].elements[elementName].value = value;
    var divElement = opener.document.getElementById(divId);
    divElement.innerHTML = value;
    window.close();
}

function transferValueFromPopUp(openerFormName, openerFormElementName, value, loc) {
        
        loc += "&overrideStylesheet=";
        loc += value;

        top.frames["main"].document.location = loc;
        top.opener.document.forms[openerFormName].elements[openerFormElementName].value = value;
}

function gotoTopFrame(loc) {
  if (top != self) {
    // We are in a frame
    top.location = loc;
  } else {
    document.location = loc;
  }
}


function printFrame() {
    parent.frames[1].focus();
    parent.frames[1].print(); 
}

function loadFrame(url) {
    parent.frames[1].document.location = url;
}

function loadTop(url) {
    parent.document.location = url;
}


function goBack() {
  window.history.go(-1);
}

function setCookie(name, value) {
  var expFromNow = 60*24*60*60*1000;  // Expires in 60 Days
  var exp = new Date(); 
  exp.setTime(exp.getTime() + expFromNow);
  document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}


function getCookie(Name) 
{
        var search = Name + "="   
        if (document.cookie.length > 0) 
        { 
                offset = document.cookie.indexOf(search);
                if (offset != -1) //DOES COOKIE EXIST
                { 
                        offset += search.length;
                        end = document.cookie.indexOf(";", offset);
                        if (end == -1);
                                end = document.cookie.length;
                        end = offset + 1; //SINCE THE VALUE IS 0, IT HAS A LENGTH OF 1
                        return unescape(document.cookie.substring(offset, end));
                }    
        }
}

function checkForNotNull(field, message){
	txt = field.value;	
	if(txt == null || txt.length < 1){
		alert(message);
		return false;
	}
	else{
		return true;		
	}

}


function logSiteRef() {
  var siteRef;          
  var loc = document.location.href;
  index = loc.indexOf("siteRef=");
  if ( index >= 0) {
    siteRef=loc.substring(index+8);
    setCookie("siteRef", siteRef);        
  }
}

function closeFrame() {
  top.document.location=top.frames['main'].location;
}

function processAlerts(str){
	alert(str);
}


function modifyText(id, text) {
        if(document.getElementById && text != '') {
          obj = document.getElementById(id);
          if (obj) {
            obj.innerHTML = text;
          }
        }
}

function modifyTextNoCheck(id, text) {
        if(document.getElementById) {
          obj = document.getElementById(id);
          if (obj) { 
           obj.innerHTML = text;
          }
        }
}

function microPollOptionModifyDivColor (id, selectBox, customColorField) {
        for (i=1; i > 0; i++) {
                var idStr = id+"_"+i;
                if(document.getElementById(idStr)) {
                        modifyDivColor(idStr, selectBox, customColorField);
                } else {
                        break;
                }
        }
}

function modifyDivColor(id, selectBox, customColorField) {
        if (document.getElementById) {
           obj = document.getElementById(id);
           if (selectBox.selectedIndex >= 0) {
             var selectedValue = selectBox.options[selectBox.selectedIndex].value;
             if (selectedValue == "-1") {
                selectedValue = customColorField.value;
             }

             obj.style.color = selectedValue;
           }
        }
}

function modifyDivBackgroundColor(id, selectBox, customColorField) {
        if (document.getElementById) {
           obj = document.getElementById(id);
           if (selectBox.selectedIndex >= 0) {
             var selectedValue = selectBox.options[selectBox.selectedIndex].value;
             if (selectedValue == "-1") {
                selectedValue = customColorField.value;
             }

             //obj.style.color = selectedValue;
               obj.style.backgroundColor = selectedValue;
           }
        }
}

function modifyDivBorderColor(id, selectBox, customColorField) {
        if (document.getElementById) {
           obj = document.getElementById(id);
           if (selectBox.selectedIndex >= 0) {
             var selectedValue = selectBox.options[selectBox.selectedIndex].value;
             if (selectedValue == "-1") {
                selectedValue = customColorField.value;
             }

             obj.style.borderColor = selectedValue;
           }
        }
}

function modifyTableBorderColor(id, selectBox, customColorField) {
        if (document.getElementById) {
           obj = document.getElementById(id);
           if (selectBox.selectedIndex >= 0) {
             var selectedValue = selectBox.options[selectBox.selectedIndex].value;
             if (selectedValue == "-1") {
                selectedValue = customColorField.value;
             }

             obj.style.borderColor = selectedValue;
           }
        }
}

function changeTextClass(id, stylesheetClass) {
        if(document.getElementById) {        
          obj = document.getElementById(id);
          obj.className=stylesheetClass;
        }        
}

function changeDualTextClass(id1, id2, stylesheetClass1, stylesheetClass2) {
        changeTextClass(id1, stylesheetClass1);
        changeTextClass(id2, stylesheetClass2);
}



function printLocation(loc) {
  myRemote = launch(loc,"FreeSurveys1","height=700,width=600,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0","Help");
  window.myRemote.focus();  
  if (window.print) {
    window.print();
  }

}

function deliverWebPage(appURL) {
  var url = appURL + "?url=" + document.location;
  miniPopup(url);
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function getSel() {
	if (document.getSelection) txt = document.getSelection();
	else if (document.selection) txt = document.selection.createRange().text;
	else return;
        
        return txt;
}


function checkSelection(typeVal) {
  mySelection = getSel();
  if (mySelection) {
        document.forms[0].decorationType.value = typeVal;
        document.forms[0].decorationValue.value = mySelection;
        document.forms[0].submit();
  } else {
        alert ("Please Select Text and then Click on the Icon");
  }
}

function changeMode(form, value) {
  form.singleDisplayMode.value = value;
  form.changeQuestionType.value = "true";
  form.submit();
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  }
 }
}


function applyText(val, control) {
  control.value = val;
}


function warnForInactivity(expiryTimeInMinutes) {
  alert ("Your Session Will Expire in " + expiryTimeInMinutes + " minutes due to Inactivity. Please Respond to the Survey!");
}


function openURLWithAlert(alertMessage, url) {
  alert(alertMessage);
  document.location = url;
}


function submitAction(form, name, value) {
  form.elements[name].value = value;
  form.submit();
}

function showCollapse(id) {
    var div = document.getElementById(id);
    var image = document.getElementById(id + "_sign");
    if (div.style.display == 'none') {
        div.style.display='block';
        image.src='/images/minus.gif';
    } else {
        hideDiv(id);
        image.src='/images/plus.gif';
    }   
}

function showCollapseFade(linkNode, id) {
    showCollapse(id);
}

function showCollapseBlock(id) {
        if(document.getElementById) {
          obj = document.getElementById(id);
          if (obj.style.display == 'block') {
            obj.style.display='none';
	       
          } else {
            obj.style.display='block';        
          }
        }
}


function showCollapseConditional(val, comparison, id) {      
      if(document.getElementById) {
          obj = document.getElementById(id);
          if (val == comparison) {
            obj.style.display='inline';        
          } else {
            obj.style.display='none';
          }
      }
}

function showMultiDiv(maxOptionIndex, selectElement, divPrefix) {
      if(document.getElementById) {
          // First Hide all the DIVS
          for (i = 0; i < maxOptionIndex; ++i) {
            elementId = divPrefix + i;
            obj = document.getElementById(elementId);
            if (obj && obj != null) {
                obj.style.display='none';
            }
          }
          elementId = divPrefix + selectElement.value;      
          obj = document.getElementById(elementId);
          if (obj && obj != null) {
            obj.style.display='inline';  
          }
      }
}

function showMultiDivIndex(maxOptionIndex, selectElement, divPrefix) {
      if(document.getElementById) {
          // First Hide all the DIVS
          for (i = 0; i < maxOptionIndex; ++i) {
            elementId = divPrefix + i;
            obj = document.getElementById(elementId);
            if (obj && obj != null) {
                obj.style.display='none';
            }
          }
          elementId = divPrefix + selectElement.selectedIndex;
          obj = document.getElementById(elementId);
          if (obj && obj != null) {
            obj.style.display='inline';  
          }
      }
}

function showCollapseConditional1(val, questionDiv, ansDiv, ansStr, questionStr) {

 	if(document.getElementById) {
		qObj = document.getElementById(questionDiv);
		aObj = document.getElementById(ansDiv);
	  	if(val != -1) {
			document.getElementById(questionDiv).innerHTML = questionStr;
			document.getElementById(ansDiv).innerHTML = ansStr;
			qObj.style.display='inline';	          	
			aObj.style.display='inline';	          	
	  	}else{
			qObj.style.display='none';
			aObj.style.display='none';
	  	}
      	}
}

function showCollapseConditionalCheckbox(checkboxElement, id) {    
      if(document.getElementById) {
          obj = document.getElementById(id);
          if (checkboxElement.checked) {
            obj.style.display='';        
          } else {
            obj.style.display='none';
          }
      }
}

function rolloverDiv(tableRow, inout, divid) {
  if (document.getElementById) {
        var obj = document.getElementById(divid);
        if (obj) {
          if (inout) {
            obj.style.display='block';
          } else {
            obj.style.display='none';
          }
        }
  }
  if (tableRow) {
        if (inout) {
          tableRow.style.background='#ffffcc';
        } else {
          tableRow.style.background='#ffffff';
        }
  }
}

function rolloverHighlightId(elementId, inout, hColor) {
  return rolloverHighlight(document.getElementById(elementId), inout, hColor);
}

function rolloverHighlight(element, inout, hColor) {
  if (element) {
        if (inout) {
                element.style.background=hColor;
        } else {
                element.style.background="";
        }
  }
}

function rolloverHighlight1(element) {
        element.className='highlight';
        if (!element.onmouseout) {
                element.onmouseout=function() {element.className='nohighlight';};
        }
}

function assignClass(divid, styleClass) {
  if (document.getElementById) {
        var currTableRow = document.getElementById(divid);
        currTableRow.className=styleClass;
  }
}


function fillSelectList(selectInput, targetSelectBox, myArray) {
  var target = selectInput.form.elements[targetSelectBox];
        
  while(target.options.length) {
        target.options[0] = null;
  }

  var arr = myArray[selectInput.selectedIndex];

  for(i = 0; i < arr.length; ++i) {
        target.options[i] = arr[i];
  }

}

function showHelp(selectInput, sourceDivId) {
        if (selectInput.selectedIndex >= 0) {
                var index = selectInput.selectedIndex;
                docLocation = "/help/" + selectInput.options[index].value + "-ajax.html";
                ajaxInlinePopup(sourceDivId, docLocation);
        }
}

function enableTextbox(textBox, checkBoxState){	
	if(checkBoxState==true){
		textBox.disabled=false;
	}       
	else{   
		textBox.disabled=true;
	}       
}

function insertRowDisplayTag(textBox, checkBoxState){

	var str = textBox.value;

	
	if(checkBoxState==true && str.indexOf("<display=row>") < 0){
		textBox.value = str+ "\r\n\r\n\r\n" +
				"<display=row>";
        }
        else if(str.indexOf("<display=row>") >= 0 && checkBoxState==false){
        	sindex = str.indexOf("<display=row>");
		str = str.substring(0,sindex) + 
			str.substring(sindex+"<display=row>".length +1, str.length);
		textBox.value = str;
        }

}


function populateConversionSurveys(url){
	document.location = url
}

function openSmallWindow (loc) {
  myRemote = launch(loc,"FreeSurveys","height=100,width=250,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0","Help");
  window.myRemote.focus();
}


function navPopup(id, title, itemTitle, itemURL, itemPopup) {
   var mye,mye2,menu;
   var open=0;
   // Set the navURL;
   navURL = itemURL;
   myNavPopup = itemPopup;

   var startx=0,starty=0;
   if (!id || id == "") {
        id = 0;
   }

   if ((mye = document.getElementById(id)) == null) return;


   for(var p = mye; p && p.tagName!='BODY'; p = p.offsetParent){
      startx += p.offsetLeft;
      starty += p.offsetTop;
   }

   if ((mye2 = document.getElementById("navcontrol_title")) == null) return;
   mye2.innerHTML = title;

   if ((menu = document.getElementById("navcontrol")) == null) return;
   menu.style.left = (startx-3)+"px";
   menu.style.top  = (starty-3)+"px";

   
   for (i = 0; i < itemTitle.length; ++i) {
        mye = document.getElementById("navcontrol_" + i);
        if (mye == null) {
          return;
        }
        mye.innerHTML = itemTitle[i];

        mye2 = document.getElementById("navcontrol_" + i + "_row");
        if (mye2 == null) {
          return;
        }
        mye2.style.display = "";
   }


   menu.style.display="";
   return;
}

function navClick(optionNumber) {
  if (navURL != null && optionNumber < navURL.length) {
    if (myNavPopup != null && optionNumber < myNavPopup.length) {
        if (myNavPopup[optionNumber]) {
                navClose();
                gotoLoc(navURL[optionNumber]);
                return;
        }
    }
    document.location = navURL[optionNumber];
  }
}


function navClose() {
  var mye2;
  if ((mye2 = document.getElementById("navcontrol")) == null) return;
  mye2.style.display="none";
}

function clearExistingData(mForm) {

  for (i=0; i < mForm.action.length; i++) {
    if (mForm.action[i].checked) {
       if(i == 1){
         delConfirm(mForm);
       } else {
         mForm.submit();
       }
     }
  }

}

function delConfirm(mForm){

        retVal = confirm("Once data is deleted there is no way to recover it.\r\n"+
                        "Are you sure you want to delete the data?");
        if(retVal == true){
                mForm.submit();
        }

}

function runningTotal(ary, outputDiv, validationTotal, isvalidated){
    var formObj = document.forms['run'];
    if(formObj == null){
	formObj = document.forms[2];
    }
    
    if (formObj.elements == null ){
	return;
    }
    
    var total=0;
    var filledBoxes=0;

    for (i=0; i<ary.length; i++){
	if (formObj.elements[ary[i]]) {
	    val = formObj.elements[ary[i]].value;
	    if(!isNaN(val) && val.length>0){
		total += parseInt(val);
		filledBoxes++;
	    }
	}
    }
    if (filledBoxes == ary.length-1 && isvalidated){	
	for (i=0;  i < ary.length; i++){
	    if (formObj.elements[ary[i]]) {
		val = formObj.elements[ary[i]].value;
		if(isNaN(val) || val.length ==0){
		    formObj.elements[ary[i]].value = (validationTotal-total) +"";
		    total = validationTotal;
		    break;
		}
	    }
	}
    }
    document.getElementById(outputDiv).innerHTML = "" + total;
}

function intValidation(val){

	for(i =0; i < val.length; i++){
		if(isNaN(val.charAt(i)+"")){			
			return false;
		}
	}
	return true;

}

function cSumIntValidation(textBox){

	if(!intValidation(textBox.value)){
		alert("Please enter a numeric value as Constant Sum Value");
		textBox.focus();
	}

}

function ajaxSubmitFormObjectAction(divID, url, htmlForm, evaluateJS, elementName, val) {
  htmlForm.elements[elementName].value = val;
  ajaxSubmitFormObjectFinal(divID, url, htmlForm, evaluateJS);
}

function ajaxSubmitForm(divID, url, formName) {
  var htmlForm = document.forms[formName];
  return ajaxSubmitFormObject(divID, url, htmlForm);
}
function ajaxSubmitFormObject(divID, url, htmlForm) {
  return ajaxSubmitFormObjectFinal(divID, url, htmlForm, false);
        
}

function addTableRow(tableID, data) {
        
   var tableRef = document.getElementById(tableID);
   var newRow   = tableRef.insertRow(tableRef.rows.length);

   eval(data);

   for (i=0; i < tableRow.length; i++) {        
        var newCell  = newRow.insertCell(i);
        var newText  = document.createTextNode(tableRow[i]);
        newCell.appendChild(newText);
   }       
           
}

//Sorry, cant make this function generic
function updateQuickPollAnswers (tableID, data) {
        synchronizeTextAreaToTable(tableID, data, 
          "<input type=\"radio\" name=\"u_quickPoll\" value=\"{row_number}\">",
          "{row_value}");
}

function synchronizeTextAreaToTable(tableID, data, c1HTML, c2HTML) {
        var answerTable = document.getElementById(tableID);        
        var ary = new Array();
        ary = data.split("\n");
        var aryLen = 0;
        
        for (i=0; i < (answerTable.rows.length); i++) {
                answerTable.deleteRow(i);
        }

        for (i=0; i < ary.length; i++) {
                if (ary[i].length > 0) {
                        var newRow = answerTable.insertRow(i);
                        col1 = newRow.insertCell(0);
                        col2 = newRow.insertCell(1);
                        col2.style.fontSize = "8pt";
                                                
                        var rowIndex = i;
                        var rowNumber = (i+1);
                        var rowValue = ary[i];


                        column1HTML = c1HTML.replace(/\{row_number\}/g, rowNumber);
                        column2HTML = c2HTML.replace(/\{row_number\}/g, rowNumber);

                        column1HTML = column1HTML.replace(/\{row_value\}/g, rowValue);
                        column2HTML = column2HTML.replace(/\{row_value\}/g, rowValue);

                        column1HTML = column1HTML.replace(/\{row_index\}/g, rowIndex);
                        column2HTML = column2HTML.replace(/\{row_index\}/g, rowIndex);
                                
        
                        col1.innerHTML = column1HTML;
                        col2.innerHTML = column2HTML;
                        aryLen++;
                }
        }       

        for (i = answerTable.rows.length -1; i >= aryLen; i--) {
                answerTable.deleteRow(i);
        }

}


function synchronizeTextAreaToTable2(tableID, data, c1HTML, c2HTML) {
        var answerTable = document.getElementById(tableID);        
        var ary = new Array();
        ary = data.split("\n");
        var aryLen = 0;
        
        for (i=0; i < ary.length; i++) {
                if (ary[i].length > 0) {
                        aryLen++;

                        var rowIndex = i;
                        var rowNumber = (i+1);
                        var rowValue = ary[i];

                        if (i < answerTable.rows.length) {
                                // Updating
                                var row = answerTable.rows[i];
                                var c1 = row.cells[0];
                                var c2 = row.cells[1];

                                column1HTML = c1HTML.replace(/\{row_number\}/g, rowNumber);
                                column2HTML = c2HTML.replace(/\{row_number\}/g, rowNumber);
        
                                column1HTML = column1HTML.replace(/\{row_value\}/g, rowValue);
                                column2HTML = column2HTML.replace(/\{row_value\}/g, rowValue);

                                column1HTML = column1HTML.replace(/\{row_index\}/g, rowIndex);
                                column2HTML = column2HTML.replace(/\{row_index\}/g, rowIndex);


                                c1.innerHTML = column1HTML;

                                // Do NOT update c2.HTML

                        } else {
                                var newRow = answerTable.insertRow(i);
                                col1 = newRow.insertCell(0);
                                col2 = newRow.insertCell(1);
                                col2.style.fontSize = "8pt";
                                                
                                column1HTML = c1HTML.replace(/\{row_number\}/g, rowNumber);
                                column2HTML = c2HTML.replace(/\{row_number\}/g, rowNumber);
        
                                column1HTML = column1HTML.replace(/\{row_value\}/g, rowValue);
                                column2HTML = column2HTML.replace(/\{row_value\}/g, rowValue);

                                column1HTML = column1HTML.replace(/\{row_index\}/g, rowIndex);
                                column2HTML = column2HTML.replace(/\{row_index\}/g, rowIndex);
                                        
        
                                col1.innerHTML = column1HTML;
                                col2.innerHTML = column2HTML;
                        }
                }
        }       

        for (i = answerTable.rows.length -1; i >= aryLen; i--) {
                answerTable.deleteRow(i);
        }

}

//Sorry, cant make this function generic
function cyopDummyResults (tableID, data) {

        var answerTable = document.getElementById(tableID);
        var ary = new Array();
        ary = data.split("\n");
        var aryLen = 0;
        var tableRowCode = "<TR><TD style=\"font-size:8pt;\"> {option_text} </TD></TR>" +
                           "<TR><TD>" +
                           "<TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" +
                           "<TR><TD bgcolor=\"#606060\" width=\"{percent_value}%\" height=\"10\"></TD>" +
                           "<TD width=\"{remander_percent_value}%\" height=\"10\" style=\"border:0; font-size: 8px; font-family:Tahoma;\">" +
                           "&nbsp;{percent_value}% "+
                           "</TD></TR>" +
                           "</TABLE>" +
                           "</TD></TR>";
 
           
        
        for (i=0; i < (answerTable.rows.length); i++) {
                answerTable.deleteRow(i);
        }

        var newRow = answerTable.insertRow(0);
        col1 = newRow.insertCell(0);
        var colData =  "<TABLE STYLE=\"font-family: Tahoma; font-size: 8.5pt;\" width=\"180\">";

        for (i=0; i < ary.length; i++) {
                if (ary[i].length > 0) {
                        var percentValue = Math.floor(Math.random()*70);        
                        var str = tableRowCode.replace(/\{option_text\}/g , ary[i]);
                        str = str.replace(/\{percent_value\}/g, percentValue.toString());
                        str = str.replace(/\{remander_percent_value\}/g, (100 - percentValue).toString());
                        colData += str;
                }
        }
        colData += "<TR><TD align=\"right\" class=\"special\" style=\"font-size:7pt;\"></TD></TR>";
        colData += "</TABLE>";
        col1.innerHTML = colData;        
        for (i = answerTable.rows.length -1; i > 0; i--) {
                answerTable.deleteRow(i);
        }

}


function updateMicroPollAnswersDropDown (tableID, data, styleClass) {

        var answerTable = document.getElementById(tableID);
        var ary = new Array();
        ary = data.split("\n");
        var aryLen = 0;
        var selectMenu = "<select name=\"mpDropDown\" class=\"" + styleClass  + "\">\n";
        var opt = "<option value=\"dummy\">${opt_text}</option>";

        for (i=0; i < (answerTable.rows.length); i++) {
                answerTable.deleteRow(i);
        }

        for (i=0; i < ary.length; i++) {
                if (ary[i].length > 0) {
                        tmp = opt.replace("${opt_text}", ary[i]);
                        selectMenu += "\n" + tmp + "\n";
                        aryLen++;
                }
        }

        selectMenu += "</select>";
        //alert(selectMenu);
        var newRow = answerTable.insertRow(0);
        col1 = newRow.insertCell(0);
        col2 = newRow.insertCell(1);
        col2.style.fontSize = "8pt";

        col1.innerHTML = " ";
        col2.innerHTML = "<div class=\""+styleClass+"\">" + selectMenu + "</div>";


        for (i = answerTable.rows.length -1; i > 0; i--) {
                answerTable.deleteRow(i);
        }

        
}

function updateMicroPollAnswers (tableID, data, styleClass, inputType) {
        
        //alert(inputType);
        if (inputType == 2) {
                updateMicroPollAnswersDropDown (tableID, data, styleClass);
                return;
        }
        var inputTypeStr = (inputType == 0 ? "radio" : "checkbox");
        //alert(inputTypeStr);
        var answerTable = document.getElementById(tableID);
        var ary = new Array();
        ary = data.split("\n");
        var aryLen = 0;

        for (i=0; i < (answerTable.rows.length); i++) {
                answerTable.deleteRow(i);
        }

        for (i=0; i < ary.length; i++) {
                if (ary[i].length > 0) {
                        var newRow = answerTable.insertRow(i);
                        col1 = newRow.insertCell(0);
                        col2 = newRow.insertCell(1);
                        col2.style.fontSize = "8pt";

                        col1.innerHTML = "<input type=\"" + inputTypeStr  + "\" name=\"u_quickPoll\" value=\""+(i+1)+"\">";
                        col2.innerHTML = "<div class=\""+styleClass+"\" id=\"mp_option_view_" + (i+1) + "\">" + ary[i] + "</div>";
                        aryLen++;
                }
        }
        for (i = answerTable.rows.length -1; i >= aryLen; i--) {
                answerTable.deleteRow(i);
        }

}

function ajaxLinkConfirm(divID, url, text) {
  if (confirm(text)) {
        ajaxLink(divID, url);
  }
}

function ajaxLinkPrompt(divID, url, text) {
  var f = prompt(text);
  if (f) {
        ajaxLink(divID, url + f);
  }
}

function ajaxLinkTab(tabIndexClass, divID, url, spinnerDiv) {
  var tabbedMenu = document.getElementById('TabbedMenu');
  if (tabbedMenu) {
    tabbedMenu.className = tabIndexClass;
    ajaxLink(divID, url, spinnerDiv);
  } else {
    alert('TabbedMenu Div Not Found');
  }
}

function ajaxLinkForControl(controlID, url) {
    ajaxLinkForControl1(document.getElementById(controlID), url, true);
}

function preAjax() {
        var statusMessageDiv = document.getElementById("promptMessage");
        if (statusMessageDiv) {
            statusMessageDiv.innerHTML = 'Processing...';
        }
}

function ajaxCall0(url, params) {
        preAjax();
        ajaxEngine.registerRequest('AjaxCall', url);
        ajaxEngine.registerAjaxElement('promptMessage');
        ajaxEngine.sendRequest('AjaxCall', 'ajax=true', params);  
}
function ajaxCall(url, params, div) {
        preAjax();
        if (document.getElementById(div)) {
                ajaxEngine.registerRequest('AjaxCall', url);
                ajaxEngine.registerAjaxElement(div);
                ajaxEngine.registerAjaxElement('promptMessage');
                ajaxEngine.sendRequest('AjaxCall', 'ajax=true', params);  
        }
}

function ajaxCall2(url, param1, param2, div) {
        preAjax();
        if (document.getElementById(div)) {
                ajaxEngine.registerRequest('AjaxCall', url);
                ajaxEngine.registerAjaxElement(div);
                ajaxEngine.sendRequest('AjaxCall', 'ajax=true', param1, param2);  
        }
}


function  refreshBuilderGoToSection(loc,secID){
	goToSection(loc,secID);
}

function goToSection(loc,secID){
        loc = loc + "?xrnd=" + Math.random() + "#" + secID;
        window.opener.location = loc;
}


function showSelectedQuestionContentInDiv(mnu,dispDiv){

        var qIDDiv = 1;
        mnuOptions = mnu.options;

        for(var i=1; i< mnuOptions.length; i++){
                if(mnuOptions[i].selected){
                        qIDDiv = (mnuOptions[i].value);
                }
        }

        if(qIDDiv==1){
                qIDDiv = mnuOptions[0].value;
        }
        divObj = document.getElementById(dispDiv);
        document.getElementById(dispDiv).innerHTML = document.getElementById(qIDDiv+"").innerHTML
        divObj.style.display='inline';

}

function isSelected(menu, value) {
        for(i=0; i < menu.length; i++) {
          if ((menu[i].selected || menu[i].checked) && menu[i].value == value) {
            return true;
          }
        }
        return false;
}


function openPreviewMultiLingual(){

        var loc = "{"+document.location+"}";

        if(loc.indexOf("surveyconsole") > 0) {
                loc = "http://www.surveyconsole.com/userimages/1630/Multi_Lingual_Surveys.html";
        } else {
                loc = "http://www.questionpro.com/akira/TakeSurvey?id=231362&responseCheck=false";
        }

        openPreview(loc);
        

}

function checkSelection (mnu, invalidVal, submitFrm) {

        var val = mnu[mnu.selectedIndex].value;

        if (val == invalidVal) {
                alert("Please select a valid option");
        } else {
                submitFrm.submit();
        }


}

function setObj(text,theswitch,inwidth,inheight) {
        thetext=text
        if(iens6){
                thename = "viewer"
                theobj=document.getElementById? document.getElementById(thename):document.all.thename
                winHeight=100
                        if(iens6&&document.all) {
                                winPositionFromTop=document.body.clientHeight
                                winWidth=(document.body.clientWidth-document.body.leftMargin)
                        }
                        if(iens6&&!document.all) {
                                winPositionFromTop=window.innerHeight
                                winWidth=(window.innerWidth-(document.body.offsetLeft+30))
                        }
                        if(theswitch=="override") {
                                winWidth=inwidth
                                winHeight=inheight
                        }
                theobj.style.width=winWidth
                theobj.style.height=startH
                        if(iens6&&document.all) {
                                theobj.style.top=document.body.scrollTop+winPositionFromTop
                                theobj.innerHTML = ""
                                theobj.insertAdjacentHTML("BeforeEnd","<table cellspacing=0 width="+winWidth+" height="+winHeight+" border=1><tr><td width=100% valign=top class=popupText>"+thetext+"</td></tr></table>")
                        }
                        if(iens6&&!document.all) {
                                theobj.style.top=window.pageYOffset+winPositionFromTop
                                theobj.innerHTML = ""
                                theobj.innerHTML="<table cellspacing=0 width="+winWidth+" height="+winHeight+" border=1><tr><td width=100% valign=top class=popupText>"+thetext+"</td></tr></table>"
                        }
        }
        if(ns4){
                thename = "nsviewer"
                theobj = eval("document."+thename)
                winPositionFromTop=window.innerHeight
                winWidth=window.innerWidth
                winHeight=100
                        if(theswitch=="override") {
                                winWidth=inwidth
                                winHeight=inheight
                        }
                theobj.moveTo(0,eval(window.pageYOffset+winPositionFromTop))
                theobj.width=winWidth
                theobj.clip.width=winWidth
                theobj.document.write("<table cellspacing=0 width="+winWidth+" height="+winHeight+" border=1><tr><td width=100% valign=top class=popupText>"+thetext+"</td></tr></table>")
                theobj.document.close()
        }
        viewIt()
}

function viewIt() {
        if(startH<=winHeight) {
                if(iens6) {
                        theobj.style.visibility="visible"
                                if(iens6&&document.all) {
                                        theobj.style.top=(document.body.scrollTop+winPositionFromTop)-startH
                                }
                                if(iens6&&!document.all) {
                                        theobj.style.top=(window.pageYOffset+winPositionFromTop)-startH
                                }
                        theobj.style.height=startH
                        startH+=2
                        openTimer=setTimeout("viewIt()",scrollSpeed)
                }
                if(ns4) {
                        theobj.visibility = "visible"
                        theobj.moveTo(0,(eval(window.pageYOffset+winPositionFromTop)-startH))
                        theobj.height=startH
                        theobj.clip.height=(startH)
                        startH+=2
                        openTimer=setTimeout("viewIt()",scrollSpeed)
                }
        }else{
                clearTimeout(openTimer)
        }
}

function stopIt() {
        if(iens6) {
                theobj.innerHTML = ""
                theobj.style.visibility="hidden"
                startH=2
        }
        if(ns4) {
                theobj.document.write("")
                theobj.document.close()
                theobj.visibility="hidden"
                theobj.width=0
                theobj.height=0
                theobj.clip.width=0
                theobj.clip.height=0
                startH=2
        }
}

function openMicroPoll (loc) {       
        win = open(loc,"pollWin", "width=500,height=350");        
}

function popupForm(formObject, baseURL) {
  // Submits a Form on a new Popup Window
  baseURL += "?";
        
  for (i = 0; i < formObject.elements.length; ++i) {
    baseURL += (formObject.elements[i].name + "=" + escape(formObject.elements[i].value) + "&");
  }
  gotoLoc(baseURL);
}

function checkSpamCompliance (actn, submitForm, popupURL) {

     if (submitForm.spamCompliance.checked) {
          if (actn == "upload" ) {
              submitForm.submit();
          } else  {
              miniPopup(popupURL);
          }
     } else {
         alert("Please read and check the SPAM Compliance Policy check-box");
     }

}

function checkboxSubmit(checkboxControl,  message) {
  if (checkboxControl.checked) {
        checkboxControl.form.submit();
  } else {
        alert(message);
  }
}

function modifyMicroPollProgressBarColor (sudoID, selectBox, customColorField, threeD) {
         
        var selectedValue = selectBox.options[selectBox.selectedIndex].value;
        if (selectedValue == "-1") {
                selectedValue = customColorField.value;
        }

        for (i=1; i > 0; i++) {
                var id = sudoID+"_"+i;
                if (document.getElementById(id)) {
                        if (threeD) {
                              selectedValue = selectedValue.toLowerCase().replace(/#/g, "");
                              modifyTableCellBackgroundImage(id, "/images/micropoll/chart/chart_"+selectedValue+".gif", 0,0);
                        } else {
                              modifyTableCellBackgroundColor(id, selectedValue, 0,0);
                        }
                } else {
                        break;
                }
        }
}

function modifyTableCellBackgroundColor (id, customColor, rowIndex, colIndex) {

        if (document.getElementById(id)) {
           obj = document.getElementById(id).rows[rowIndex].cells;
           tableCell = obj[colIndex];
           tableCell.style.backgroundImage="";
           tableCell.style.backgroundColor = customColor;
           //bgColor = customColor;
        }
}

function modifyTableCellBackgroundImage (id, imgSrc , rowIndex, colIndex) {
        //alert(imgSrc);
        if (document.getElementById(id)) {
           obj = document.getElementById(id).rows[rowIndex].cells;
           tableCell = obj[colIndex];
           tableCell.style.backgroundColor="";
           tableCell.style.backgroundImage="url('" + imgSrc + "')";
           tableCell.style.backgroundRepeat="repeat-x";
           tableCell.style.backgroundPosition="center center";
           //bgColor = customColor;
        }
}

function copyText (txtBox) {
        txtBox.focus();
        txtRange = txtBox.createTextRange();
        txtRange.execCommand("SelectAll");
        txtRange.execCommand("Copy");
}

function closeDiv(id) {
  container = document.getElementById(id);
  if (container) {
        container.style.display='none';
  }
}

function closeInlinePopup (id) {
    showSeeThroughElements();
    closeDiv(id);
}

function showSeeThroughElements () {
    changeSeeThroughElementsDisplay("");
}

function hideSeeThroughElements () {
    changeSeeThroughElementsDisplay("none");
}

function changeSeeThroughElementsDisplay (display) {
    //add more elements that need to be hidden / shown here
    changeDisplayForElements("select", display);
    changeDisplayForElements("object", display);
}

function changeDisplayForElementsBYVIRAJ_SO_SLOW(type, display) {
    for(var i=0;i<document.all.length;i++){
        var ele = document.all[i];
        try {
          if (ele.type.indexOf(type) >= 0) {
              ele.style.display=display;
          }
        } catch (e) {
            //eat it
        }
    }
}

function changeDisplayForElements(type, display) {
    var elements = document.getElementsByTagName(type);

    for(var i=0; i < elements.length; i++) {
        var ele = elements[i];
        try {
          ele.style.display=display;
        } catch (e) {
            //eat it
        }
    }
}

function frameWithAjaxImageSubmit (imageDiv, frmSrc, frmID) {
        document.getElementById(imageDiv).style.display="inline";
        document.getElementById(imageDiv).innerHTML = "<img src=\"/images/ajax.gif\"><br>Getting Images...";
        var frm = document.getElementById(frmID);
        frm.src = frmSrc;
}

function isValidURL (url) {
        var regExp= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
        if (regExp.test(url)) {
                return true;
        }
        else {
                window.alert("Invalid URL");
                return false; 
        }
}

function ajaxLinkInParentWindow (divID, actionSrc) {
        this.parent.ajaxLink1(this.parent.document.getElementById(divID),actionSrc);
}

function hideDiv (divID) {
        obj = document.getElementById(divID);
        if (obj) {
          obj.style.display="none";
        }
}

function showDiv (divID) {        
        obj = document.getElementById(divID);
        if (obj) {
          obj.style.display="block";
        }
}


function hideParentDiv (divID) {
        this.parent.document.getElementById(divID).style.display="none";
}

function formatStr (txtBoxNameOrID, v, formIndex) {
    e = getObject1(txtBoxNameOrID, formIndex); 
    var str = getSelected(e);
    if (str.indexOf("\r") > 0 || str.indexOf("\n") > 0) {
        alert("Please select one line at a time.");
        return;    
    }
    if (str) setSelection(e, '<' + v + '>' + str + '</' + v + '>');
    return false;
}



function getSelected (e) {
    if (document.selection) {
        e.focus();
        var range = document.selection.createRange();
        return range.text;
    } else {
        var length = e.textLength;
        var start = e.selectionStart;
        var end = e.selectionEnd;
        if (end == 1 || end == 2 && length != undefined) end = length;
        return e.value.substring(start, end);
    }
}

function setSelection (e, v) {
    if (document.selection) {
        e.focus();
        var range = document.selection.createRange();
        range.text = v;
    } else {
        var length = e.textLength;
        var start = e.selectionStart;
        var end = e.selectionEnd;
        if (end == 1 || end == 2 && length != undefined) end = length;
        e.value = e.value.substring(0, start) + v + e.value.substr(end, length);
        e.selectionStart = start + v.length;
        e.selectionEnd = start + v.length;
    }
    e.focus();
}

function insertLink (txtBoxNameOrID, isMail, formIndex) {
    e = getObject1(txtBoxNameOrID, formIndex);
    var str = getSelected(e);
    var link = '';
    if (!isMail) {
        if (str.match(/^https?:/)) {
            link = str;
        } else if (str.match(/^(\w+\.)+\w{2,5}\/?/)) {
            link = 'http://' + str;
        } else if (str.match(/ /)) {
            link = 'http://';
        } else {
            link = 'http://' + str;
        }
    } else {
        if (str.match(/@/)) {
            link = str;
        }
    }
    var my_link = prompt((isMail ? "Enter email address:" : "Enter URL:"), "");
    if (my_link != null) {
         if (str == '') str = my_link;
         if (isMail) my_link = 'mailto:' + my_link;
        setSelection(e, '<a href="' + my_link + '" target="_blank">' + str + '</a>');
    }
    return false;
}

function getObject (elementNameOrID) {
        return getObject1(elementNameOrID, -1);
}
function getObject1 (elementNameOrID, formIndex) {
        
        if (formIndex < 0 && document.getElementById(elementNameOrID)) {
                return document.getElementById(elementNameOrID);
        } else if (formIndex >= 0 && 
                   document.forms[formIndex] &&
                   document.forms[formIndex].elements[elementNameOrID]) {
                return document.forms[formIndex].elements[elementNameOrID];
        }

        for (i=0; (document.forms && i < document.forms.length); i++) {
                if (document.forms[i].elements[elementNameOrID]) {
                      return  document.forms[i].elements[elementNameOrID];
                }
        }

}

function ajaxInlinePopup1 (popupWidth, popupHeight, appURL) {  
        var container = document.getElementById("contentEnclosingDivID");

        container.style.left = 220 + document.body.scrollLeft;
        container.style.top = 100 + document.body.scrollTop;

        var rightShadowDiv = document.getElementById("rightShadowDivID"); 
        var bottomShadowDiv = document.getElementById("bottomShadowDivID");
        var contentTable = document.getElementById("contentTableID");
        
        if (popupWidth > 0) {
                contentTable.style.width = popupWidth;
        }        
        if (popupHeight > 0) {
                contentTable.style.height = popupHeight;
        }                
        var shadowOffset = 10;        
        var ieAdjustment = 0;
        if (navigator.appName.indexOf("Microsoft Internet Explorer") >= 0) {
                 ieAdjustment = -7;
        }

        rightShadowDiv.style.left = parseInt(container.style.left) + parseInt(contentTable.style.width);
        bottomShadowDiv.style.left = parseInt(container.style.left) + shadowOffset;

        rightShadowDiv.style.top = parseInt(container.style.top) + shadowOffset ;
        rightShadowDiv.style.height = parseInt(contentTable.style.height) - shadowOffset + ieAdjustment;
        
        bottomShadowDiv.style.top = parseInt(container.style.top) +
                              parseInt(contentTable.style.height) + ieAdjustment;
        bottomShadowDiv.style.width = parseInt(contentTable.style.width);
        
        container.style.display="inline";
        bottomShadowDiv.style.display="inline";
        rightShadowDiv.style.display="inline";
        
        ajaxLink("contentDivID", appURL);
         
}

function closeLiteInlinePopup() {
        document.getElementById("contentEnclosingDivID").style.display="none";
        document.getElementById("rightShadowDivID").style.display="none";
        document.getElementById("bottomShadowDivID").style.display="none";
}

function insertImageCode (inputField, imageURL) {        
        var imageCode = "<img src=\""+imageURL+"\">";
        inputField.value = inputField.value + "\r\n" + imageCode;
}

function writeDiv (div, txt) {
        div.innerHTML = txt;        
}

//ReOrder methods
function moveSelectionUp (mnu) {
        mnuOptions = mnu.options;
        if(mnuOptions[0].selected){
            return;
        }

        for(var i=0; i < mnuOptions.length; i++){
                if(mnuOptions[i].selected && i > 0) {
                        mnuOptions[i].selected = false;
                        tmpVal = mnuOptions[i].value;
                        tmpTxt = mnuOptions[i].text;
                        mnuOptions[i].value = mnuOptions[i-1].value;
                        mnuOptions[i].text = mnuOptions[i-1].text;
                        mnuOptions[i-1].value = tmpVal;
                        mnuOptions[i-1].text = tmpTxt;
                        mnuOptions[i-1].selected = true;
                        return;

                }
        }
}


function moveSelectionDown(mnu) {

        mnuOptions = mnu.options;

        if(mnuOptions[ mnuOptions.length -1].selected){
            return;
        }

        for(var i=0; i < mnuOptions.length; i++){
                if(mnuOptions[i].selected && i <  (mnuOptions.length-1)) {
                        mnuOptions[i].selected = false;
                        tmpVal = mnuOptions[i+1].value;
                        tmpTxt = mnuOptions[i+1].text;

                        mnuOptions[i+1].value = mnuOptions[i].value;
                        mnuOptions[i+1].text = mnuOptions[i].text;

                        mnuOptions[i].value = tmpVal;
                        mnuOptions[i].text = tmpTxt;
                        mnuOptions[i+1].selected = true;
                        return;

                }
        }
}

function selectAllAndSubmitForm (frm, mnu) {
    selectAll(frm.elements[mnu]);
    frm.submit();
}

function selectAll (mnu) {
        selectAll1(mnu.options);
}

function selectAll1(mnuOptions) {
    for(var i=0; i < mnuOptions.length; i++) {
        mnuOptions[i].selected = true;
        mnuOptions[i].checked = true;
    }
}

function modifyTableRowBGColor(id,rowIndex,  selectBox, customColorField) {
        if (document.getElementById) {
           obj = document.getElementById(id);
           if (selectBox.selectedIndex >= 0) {
             var selectedValue = selectBox.options[selectBox.selectedIndex].value;
             if (selectedValue == "-1") {
                selectedValue = customColorField.value;
             }
             if (rowIndex < 0) {
                obj.style.backgroundColor = selectedValue;
             } else {
                obj.rows[rowIndex].style.backgroundColor = selectedValue;
             }             
           }
        }
}

function modifyTableBGColor(id, selectBox, customColorField) {
        modifyTableRowBGColor(id, -1, selectBox, customColorField);
}



function getPos(obj) {
  var coord = new Object();
  o = obj;
  coord.left = o.offsetLeft;
  coord.top = o.offsetTop;
  while(o.offsetParent != null) {
    oParent = o.offsetParent;
    coord.left += oParent.offsetLeft;
    coord.top += oParent.offsetTop;
    o = oParent;
  }
  return coord;
}

function RaterControl(promptBoxId, strings, questionId, responseUri) {
  var imagePath = "/images/ratercontrol/";
  var promptBox = document.getElementById(promptBoxId);

  if (!promptBox) return;

  var promptDiv = document.createElement("div");
  var thanksDiv = document.createElement("div");
  var raterDiv = document.createElement("div");

  promptDiv.className = "raterPrompt";
  thanksDiv.className = "ratherThanks";

  var this_ = this;

  // create the thank you
  thanksDiv.style.display = "none";
  thanksDiv.className = "raterThanks";
  thanksDiv.innerHTML = strings["ThankYou"];
  promptBox.appendChild(thanksDiv);

  // create the rater
  raterDiv.style.display = "block";
  raterDiv.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'>"
      + "<tr><td class='raterContent'></td></tr></table>";
  var contents = raterDiv.getElementsByTagName("td")[0];
  var span = document.createElement("span");

  span.innerHTML = strings["RateThisTool"] + ":&nbsp;";

  /**
   * Creates an image object
   * @private
   */
  function createImage(uri){
    var img = document.createElement("img");
    img.src = uri;
    img.align = "absmiddle";
    return img;
  }

  faces = new Array();
  faces[0] = createImage(imagePath + 'sad.gif');
  faces[1] = createImage(imagePath + 'normal.gif');
  faces[2] = createImage(imagePath + 'happy.gif');

  for (var i=0; i< faces.length; i++){
    var face = faces[i];
    face.submitValue = i+1;
    face.rater = this;
    face.onclick = function(){
      this.rater.submitResponse(this.submitValue);
    }
    face.descText = strings["value_" + face.submitValue];
    face.onmouseover = function(){
      this.className = "faceOver";
      var coord = getPos(this);
      Bubble.show(this.descText, coord.left, coord.top);
    }
    face.onmouseout = function(){
      this.className = "";
      Bubble.hide();
    }
    face.style.cursor = "pointer";
    span.appendChild(face);
  }

  contents.appendChild(span);
  promptBox.appendChild(raterDiv);

  /**
   * Hides the rater control
   * @public
   */
  this.hide = function(opt_didSubmit){
    raterDiv.style.display = "none";
    Bubble.hide();
    if (opt_didSubmit) {
      thanksDiv.style.display = "block";
      window.setTimeout(this_.hide, 25000);
    } else {
      promptBox.style.display = "none";
    }
  }

  /**
   * Submits a response to the servlet URI using GET, and hides the
   * prompt box.  Does not check to make sure the data was sent without
   * error.
   * @param value numerical response value.
   * @param handler handler to invoke once the request is complete.
   */
  this.submitResponse = function(value) {
    var url = "/akira/RaterServlet";
    try {
        var pars = 'raterId=' + escape(questionId) + '&raterResponse=' + escape(value);
        ajaxLink1(thanksDiv, (url + "?" + pars));
    } catch (e) {
        // eat?
    }
    this_.hide(true);
  }
}


var Bubble = {
  imagePath:  "/images/ratercontrol/bubble/",

  init: function() {
    if (Bubble.bubbleDiv == null) {
      // initialize the bubble div if there isn't already one declared.
      var div = document.createElement("div");
      div.style.position = "absolute";
      div.style.top = 0;
      div.style.left = 0;

      // innerHTML building.  Multiple table wrapping for IE compatibility.
      var html = '<table cellpadding="0" cellspacing="0" border="0"><tr>'
          + '<td colspan="5"><div style="font-family:Arial;background:#fff;'
          + 'padding:6px;border-width:1px 1px 0px 1px;border-style:solid;'
          + 'border-color:#000;cursor:pointer;" id="bubble_msg"></div></td></tr>'
          + '<tr><td>'
          + '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>'
          + '<td style="width:2px" valign="top"><img src="'
          + Bubble.imagePath + 'bubble_left.gif" height="2" width="2">'
          + '</td><td valign="top"'
          + ' style="width:*;background-repeat:repeat-x;background-image:url(\''
          + Bubble.imagePath +'bubble_bg.gif\')"><img src="'
          + Bubble.imagePath + '1.gif"></td>'
          + '<td style="width:10px" valign="top"><img src="'
          + Bubble.imagePath+ 'bubble_tail.gif" height="11" width="10">'
          + '</td><td style="width:9px" '
          + 'valign="top"><img src="'
          + Bubble.imagePath + 'bubble_bg.gif" width="9" height="2"></td>'
          + '<td style="width:2px" valign="top"><img src="'
          + Bubble.imagePath + 'bubble_right.gif" height="2" width="2">'
          + '</td></tr>'
          + '</table></td></tr></table>';

      div.innerHTML = html;

      // Add to the document, reference as necessary.
      div.style.display = "none";
      div.style.visibility = "hidden";
      document.body.appendChild(div);
      Bubble.msgBox = document.getElementById("bubble_msg");
      Bubble.bubbleDiv = div;
    }
    Bubble.msgBox.innerHML = "&nbsp;";
  },

  showTip: function( message, obj ) {
    var coordinate = getPos(obj);
    Bubble.show(message, coordinate.left, coordinate.top);
    
    Bubble.msgBox.onclick = function() {
        Bubble.hide();
    };
    // Hide after 5 seconds
    setTimeout("Bubble.hide()", 5000);
  },
  show: function( message, absLeft, absTop ) {
    Bubble.init();
    var imagesOffsetY = 12;
    var imagesOffsetX = 16;
    Bubble.bubbleDiv.style.display = "block";
    Bubble.msgBox.innerHTML = message;

    Bubble.bubbleDiv.style.left = absLeft - Bubble.msgBox.offsetWidth
        + imagesOffsetX;
    Bubble.bubbleDiv.style.top = absTop - Bubble.msgBox.offsetHeight
        - imagesOffsetY;
    Bubble.bubbleDiv.style.visibility = "visible";
  },

  hide: function() {
    Bubble.bubbleDiv.style.visible = "hidden";
    Bubble.bubbleDiv.style.display = "none";
    Bubble.bubbleDiv.style.top = "0px";
    Bubble.bubbleDiv.style.left = "0px";

  }
}

function enablePollRoundedCorners (pollID) {
        pollRoundedCorners (pollID, "inline");        
}

function disablePollRoundedCorners (pollID) {
        pollRoundedCorners (pollID, "none");        
}

function pollRoundedCorners (pollID, displayMode) {
                
        document.getElementById("mp_table_view_top_left_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_view_top_right_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_view_bottom_right_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_view_bottom_left_" + pollID).style.display = displayMode;        

        document.getElementById("mp_table_result_top_left_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_result_top_right_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_result_bottom_right_" + pollID).style.display = displayMode;
        document.getElementById("mp_table_result_bottom_left_" + pollID).style.display = displayMode;        
}

function changeElementValue (elementID, val) {
        document.getElementById(elementID).value = val;
}

function changeBackgroundImage (elementID, val) {
        document.getElementById(elementID).style.backgroundImage="url(" + val + ")";
}

function getHTMLFormat (text) {        
        text = text.replace(/\n/gi,"<br>");
        return text;
}

function formatEmailInvitationPreview (text) {
        text = getHTMLFormat(text);
        text = "<br><br><TABLE width='95%' align='center' style='border: 1px solid #cccccc;'><TR><TD>" + text +
               "</TD><TR></TABLE>";
        return text;
}

function ajaxInlinePopup1 (data, id) {
        container = document.getElementById('shadowedBox');
        dataContainer = document.getElementById('shadowedBoxBody');
        linkNode = document.getElementById(id);
        // Update the Status Container
        dataContainer.innerHTML = '<img src="/images/ajax.gif">';
        container.style.left=220;
        container.style.top=100 + document.body.scrollTop;
        container.style.display='inline';
        dataContainer.style.height=300;
        dataContainer.style.overflow = "auto";
        dataContainer.innerHTML = data;
}

function markCursorPosition (textArea) {
        //alert (getCaterStartPosition (textArea)
        CURSOR_POS = getCaterStartPosition (textArea);
        //IE
        if (document.selection) {        
                if (textArea.value.charAt(CURSOR_POS + 1) == '\n') {
                        CURSOR_POS = CURSOR_POS + 1;
                }
        }
}

function insertTextAtCursor (textArea, value) {
        var str = textArea.value;
        str = str.substring (0, CURSOR_POS) + value + (CURSOR_POS < str.length ? str.substring(CURSOR_POS, str.length) : "");
        textArea.value = str;        
}

function monitorCursor (textArea) {
    textArea.onblur = function (e) {
        try{
            markCursorPosition(textArea);
        } catch(err){}
    };
    textArea.onfocus = function (e) {
        try{
            markCursorPosition(textArea);
        } catch(err){}
    };
    textArea.onkeyup = function (e) {
        try{
            markCursorPosition(textArea);
        } catch(err){}
    };
}

function getCaterStartPosition (textArea) {

  if ( document.selection ) { 
    // The current selection 
    var range = document.selection.createRange(); // We'll use this as a 'dummy' 
    var stored_range = range.duplicate(); // Select all text 
    stored_range.moveToElementText( textArea ); // Now move 'dummy' end point to end point of original range 
    stored_range.setEndPoint( 'EndToEnd', range ); // Now we can calculate start and end points 
    textArea.selectionStart = stored_range.text.length - range.text.length; 
    textArea.selectionEnd = textArea.selectionStart + range.text.length; 
    return textArea.selectionStart;
  }
        
  return textArea.selectionStart;

}

function closeWindowCallAjaxLink (myWin, divID, actionSrc) {
        ajaxLink(divID, actionSrc);
        myWin.close();
}

// Custom Reference Data Validator
function validateUSZip(value, divID, ajaxProcessorURL) {
  if (value != null && value.length == 5) {
        ajaxLink(divID, ajaxProcessorURL);
  } else {
     modifyTextNoCheck(divID, '');
  }
}       

function validateCAZip(value, divID, ajaxProcessorURL) {
  if (value != null && value.length == 7) {
        ajaxLink(divID, ajaxProcessorURL);
  } else {
        modifyTextNoCheck(divID, '');
  }
}       

function validateAUZip(value, divID, ajaxProcessorURL) {
  if (value != null && value.length == 4) {
        ajaxLink(divID, ajaxProcessorURL);
  } else {
        modifyTextNoCheck(divID, '');
  }
}       




if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
if(typeof infosoftglobal.PowerMapUtil == "undefined") infosoftglobal.PowerMapUtil = new Object();
infosoftglobal.PowerMap = function(swf, id, w, h, debugMode, registerWithJS, c, scaleMode, lang){
	if (!document.getElementById) { return; }
	
	//Flag to see whether data has been set initially
	this.initialDataSet = false;
	
	//Create container objects
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	//Set attributes for the SWF
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	
	//Set background color
	if(c) { this.addParam('bgcolor', c); }
	
	//Set Quality	
	this.addParam('quality', 'high');
	
	//Add scripting access parameter
	this.addParam('allowScriptAccess', 'always');
	
	//Pass width and height to be appended as mapWidth and mapHeight
	this.addVariable('mapWidth', w);
	this.addVariable('mapHeight', h);

	//Whether in debug mode
	debugMode = debugMode ? debugMode : 0;
	this.addVariable('debugMode', debugMode);
	//Pass DOM ID to Map
	this.addVariable('DOMId', id);
	//Whether to registed with JavaScript
	registerWithJS = registerWithJS ? registerWithJS : 0;
	this.addVariable('registerWithJS', registerWithJS);
	
	//Scale Mode of Map
	scaleMode = scaleMode ? scaleMode : 'noScale';
	this.addVariable('scaleMode', scaleMode);
	//Application Message Language
	lang = lang ? lang : 'EN';
	this.addVariable('lang', lang);
}

infosoftglobal.PowerMap.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { 
			// netscape plugin architecture			
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"  ';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE			
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");			
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	setDataURL: function(strDataURL){
		//This method sets the data URL for the Map.
		//If being set initially
		if (this.initialDataSet==false){
			this.addVariable('dataURL',strDataURL);
			//Update flag
			this.initialDataSet = true;
		}else{
			//Else, we update the Map data using External Interface
			//Get reference to map object
			var mapObj = infosoftglobal.PowerMapUtil.getMapObject(this.getAttribute('id'));
			mapObj.setDataURL(strDataURL);
		}
	},
	setDataXML: function(strDataXML){
		//If being set initially
		if (this.initialDataSet==false){
			//This method sets the data XML for the map INITIALLY.
			this.addVariable('dataXML',strDataXML);
			//Update flag
			this.initialDataSet = true;
		}else{
			//Else, we update the map data using External Interface
			//Get reference to map object
			var mapObj = infosoftglobal.PowerMapUtil.getMapObject(this.getAttribute('id'));
			mapObj.setDataXML(strDataXML);
		}
	},
	render: function(elementId){
		var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
		n.innerHTML = this.getSWFHTML();
		return true;		
	}
}

// ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
/* Fix for video streaming bug */
infosoftglobal.PowerMapUtil.cleanupSWFs = function() {
	if (window.opera || !document.all) return;
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// Fixes bug in fp9
infosoftglobal.PowerMapUtil.prepUnload = function() {
	__flash_unloadHandler = function(){};
	__flash_savedUnloadHandler = function(){};
	if (typeof window.onunload == 'function') {
		var oldUnload = window.onunload;
		window.onunload = function() {
			infosoftglobal.PowerMapUtil.cleanupSWFs();
			oldUnload();
		}
	} else {
		window.onunload = infosoftglobal.PowerMapUtil.cleanupSWFs;
	}
}
if (typeof window.onbeforeunload == 'function') {
	var oldBeforeUnload = window.onbeforeunload;
	window.onbeforeunload = function() {
		infosoftglobal.PowerMapUtil.prepUnload();
		oldBeforeUnload();
	}
} else {
	window.onbeforeunload = infosoftglobal.PowerMapUtil.prepUnload;
}

/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* Function to return Flash Object from ID */
infosoftglobal.PowerMapUtil.getMapObject = function(id)
{
  if (window.document[id]) {
      return window.document[id];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[id])
      return document.embeds[id]; 
  } else {
    return document.getElementById(id);
  }
}

function stringTrim (str) {
    str = str.replace(/^([ \r\n]+)([^ \r\n])/i, "$2");
    str = str.replace(/([ \r\n]+)$/i, "");
    return str;
}


/* Aliases for easy usage */
var getMapFromId = infosoftglobal.PowerMapUtil.getMapObject;
var PowerMap = infosoftglobal.PowerMap;

function showAllDivs (sudoID,start, limit) {
  changeAllDivsDisplay(sudoID, start, limit, true);
}

function hideAllDivs (sudoID,start, limit) {
  changeAllDivsDisplay(sudoID, start, limit, false);
}

function changeAllDivsDisplay (sudoID,start, limit, show) {
  for (i=start; i < limit; i++) {
    id = sudoID.replace(/\{0\}/gi,parseInt(i));
    if (document.getElementById(id)) {
      if (show) {
        showDiv(id);
      } else {
        hideDiv(id);
      }
    }
  }
}

function isInternetExplorer () {
    var browserName=navigator.appName;
    return (browserName && browserName.indexOf("Microsoft") > -1);
}


function displayInlineUploadInfo(id, value) {
  obj = document.getElementById(id);
  obj.innerHTML = "<img src='/images/iconshock/tick_16.gif'>&nbsp;" + value;
}

function refreshOpener (loc) {
     window.opener.document.location=loc;
}

function addOptionToSelectBox(selectElement, name, value) {
	addOptionToSelectBox(selectElement, name, value, null)
}

function addOptionToSelectBox(selectElement, name, value, selectElemet2) {
  if (selectElement) { 
    selectElement.options[selectElement.options.length] = new Option(name, value);
    selectElement.value = value;
  } else {
     var selectNames = document.getElementsByTagName("select")
     for (i=0; i<selectNames.length; i++) {
	if(selectNames[i].name.indexOf(selectElemet2)!= -1) {
		selectNames[i].options[selectNames[i].options.length] = new Option(name,value);
		selectNames[i].value = value;
	}
     } 

  }
} 

function transferFieldValue(form, sourceName, targetName) {
  var target = form.elements[targetName];
  target.value = form.elements[sourceName].value;
  target.focus();
  target.select();
}

function syncCheckBox(masterCheckBoxObject) {
    var myForm = masterCheckBoxObject.form;
    for (i=0; i < myForm.elements.length; i++) {
        var formElement = myForm.elements[i];
        if (formElement.type && formElement.type == "checkbox") {            
            formElement.checked = masterCheckBoxObject.checked;        
        }
    }
}

function sectionMenu(itemArray, currentItem) {
    for (i = 0; i < itemArray.length; ++i) {
        var tableId = 'section_menu_' +  itemArray[i];
        var obj = document.getElementById(tableId);
        if (obj) {
            if (itemArray[i] != currentItem) {
                obj.className = 'sectionMenuNormal';

		obj.setAttribute("onMouseOver","this.className='sectionMenuNormalhover'");
		obj.setAttribute("onMouseOut","this.className='sectionMenuNormal'");

                obj.onmouseover = function() {this.className='sectionMenuNormalhover'};
                obj.onmouseout = function()  {this.className='sectionMenuNormal'};

              
                var contentObj = document.getElementById('section_menu_content_' + itemArray[i]);
                if (contentObj) {    
                  contentObj.style.display = 'none';
                }
            } else {
		obj.className = 'sectionMenuHighlight';

  		obj.setAttribute("onMouseOver","this.className='sectionMenuHighlight'");
	        obj.setAttribute("onMouseOut","this.className='sectionMenuHighlight'");

                obj.onmouseover = function() {this.className='sectionMenuHighlight'};
                obj.onmouseout = function()  {this.className='sectionMenuHighlight'};
 
        	var contentObj = document.getElementById('section_menu_content_' + currentItem);
	        if (contentObj) {
        	    contentObj.style.display = 'block';
	        }
	    }
        }
    }
}

function showTableRow (tableID, rowID) {
    updateTableRowDisplay(tableID, rowID, "");
}

function hideTableRow (tableID, rowID) {
    updateTableRowDisplay(tableID, rowID, "none");
}

function updateTableRowDisplay (tableID, rowID, display) {
    var tableObject = document.getElementById(tableID);
    for (i=0; i < tableObject.rows.length; i++) {
        if (tableObject.rows[i].id == rowID) {
            tableObject.rows[i].style.display=display;
            break;
        }
    }
}


function ajaxSearch(inputBox, divId, resetURL) {
  if (inputBox.value != null && inputBox.value.length >= 3) {
    // 
    ajaxSubmitFormObject(divId, inputBox.form.action, inputBox.form);
  } else {
    if (inputBox.value == null || inputBox.value.length == 0) {
      // Reset the search
      ajaxLink(divId, resetURL);
    }
  }       
}


function setStyle(element, styleText) {
    element.setAttribute("style", styleText);
    element.style.cssText = styleText;
}

function addDiv(divID) {
    var dialog = document.createElement('div');
    dialog.innerHTML = '<div id="' + divID + '"></div>';
    document.body.appendChild(dialog);
    return document.getElementById(divID);
} 

function addImage(id, src) {
    var img = document.createElement("img");
    img.src = src;
    img.id = id;
    return img;
}

/*** START AJAX FUNCTIONS ***/
function ajaxInlinePopupForm(divID, htmlForm) {
    hideSeeThroughElements();

    container = document.getElementById('shadowedBox');
    dataContainer = document.getElementById('shadowedBoxBody');    
    linkNode = document.getElementById(divID);
    ajaxSubmitFormObjectFinal('shadowedBoxBody', htmlForm.action, htmlForm, false);

    container.style.left = 220 + document.body.scrollLeft;
    container.style.top = 100 + document.body.scrollTop;
    container.style.display='inline';
}

function ajaxSubmitFormObjectFinal(divID, url, htmlForm, evaluateJS) {
    var url = convertFormToURL(url, htmlForm);
    var element = document.getElementById(divID);
    var r = getAjaxRequestFinal(url, element, false);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        if (evaluateJS) {
            eval(r.responseText);
            element.innerHTML = "";
        } else {
          if (r.responseText.indexOf("//JavaScript") > 0) {
            eval(r.responseText);
          } else {
            element.innerHTML = r.responseText;
          }
        }
    }

    element.innerHTML = '<img src="/images/ajax.gif">';
    return false;
}


function ajaxSubmitSilent(htmlForm, callback) {
    var url = convertFormToURL(htmlForm.action, htmlForm);
    var element = null;
    var r = getAjaxRequestFinal(url, element, false);

    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }

        if (callback) {
          callback.call(this, r);
        }
    }
    return false;
}


function ajax2Form(spinnerDiv, targetDiv, htmlForm) {    
    var url = convertFormToURL(htmlForm.action, htmlForm);

    var spinnerDivElement = document.getElementById(spinnerDiv);
    var currentHTML = spinnerDivElement.innerHTML;

    var targetDivElement = document.getElementById(targetDiv);
    var threadId = 0;
    var r = getAjaxRequestFinal(url, targetDivElement, false);

    r.onreadystatechange = function () {

        if (r.readyState != 4) {
            return;
        }

        if (r.responseText.indexOf("//JavaScript") > 0) {
          eval(r.responseText);
        } else {
          targetDivElement.innerHTML = r.responseText;
        }

        spinnerDivElement.innerHTML = "";

        if (threadId != 0) { 
            clearTimeout(threadId);
        }
    }

    spinnerDivElement.innerHTML = '<img src="/images/ajax.gif">';
    return false;
}


function ajaxDeleteRow(rowID, url, identifierValue) {
        ajaxDeleteRow1(rowID, url, identifierValue, "Are you sure ?");
}

function ajaxDeleteRow1(rowID, url, identifierValue, confirmMessage, identifierName) {
    if (! identifierName) {
        identifierName = "id";
    }
    var element = document.getElementById(rowID);
    url = url + (url.indexOf("?") >= 0 ? "&" : "?") + identifierName + "=" + identifierValue;
    if (confirm(confirmMessage) && element) {
        var r = getAjaxRequest(url, element);
        r.onreadystatechange = function () {
            if (r.readyState != 4) {
                return;
            }
            
            element.parentNode.deleteRow(element.rowIndex);

            if (r.responseText.indexOf("//JavaScript") > 0) {
              eval(r.responseText);
            }
        }

        statusSpan = document.getElementById("status_" + identifierValue);
        if (statusSpan) {
            statusSpan.innerHTML = '<img src="/images/ajax.gif">';
        }
    }
}

function ajaxInlinePopup(id, url) {
    hideSeeThroughElements();

    container = document.getElementById('shadowedBox');
    if (!container) {
        alert('Container not found. Please wait for the page to load');
    }
    dataContainer = document.getElementById('shadowedBoxBody');
    linkNode = document.getElementById(id);

    var r = getAjaxRequest(url, dataContainer);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }


        if (r.responseText.indexOf("//JavaScript") > 0) {
          eval(r.responseText);
        } else {
          dataContainer.innerHTML = r.responseText;
        }
    }


    dataContainer.innerHTML = '<img src="/images/ajax.gif">';

    container.style.left = 220 + document.body.scrollLeft;
    container.style.top = 100 + document.body.scrollTop;
    container.style.display='inline';
}

function ajaxLink(divID, url, spinnerDivId) {
    var element = document.getElementById(divID);
    var spinnerElement;

    if (spinnerDivId) {
        spinnerElement = document.getElementById(spinnerDivId);
    }

    var r = getAjaxRequest(url, element);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }

        if (r.responseText.indexOf("//JavaScript") > 0) {
          eval(r.responseText);
        } else {
          element.innerHTML = r.responseText;
        }

        if (spinnerElement) {
          spinnerElement.innerHTML = '';
        }
    }
    if (spinnerElement) {
      spinnerElement.innerHTML = '<img src="/images/ajax.gif">';
    } else {
      element.innerHTML = '<img src="/images/ajax.gif">';
    }
}



function getAjaxRequestFinal(url, element, encURL) {
    var req = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));

    if (!req) {
        alert("Could not execute AJAX Request");
        return;
    }

    sendAjaxRequest(url, req, encURL);
    return req;
}

function getAjaxRequest(url, element) {
    return getAjaxRequestFinal(url, element, true);
}

function sendAjaxRequest(url, req, encURL) {
    var debugURL = encodeURIComponent("[" + url + "]");
    url = (url.indexOf("?") > 0 ? 
           url.split("?")[0] + "?ajax=true&engine=dojo&" + url.split("?")[1] : 
           url + "?ajax=true&engine=dojo");
    url = (encURL ? encodeURL(url) : url);    
    if (!encURL) {
        var baseurl = url.split("?")[0];    
        req.open("POST", baseurl ,true);
        req.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8');
        req.setRequestHeader('Connection', 'close');
        var params = url.split("?")[1];
        req.setRequestHeader('Content-length', params.length);
        req.send(params);
    } else {
        req.open("GET", url, true);
        req.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8');
        req.setRequestHeader('Connection', 'close');
        req.send(null);
    }
}

function encodeURL(url) {
    if (url.split("?").length == 0) {
        return;
    }
    url = url.split("#")[0];
    var ary = url.split("?")[1].split("&");
    var params = "";
    for (i=0; i < ary.length; i++) {
        params += ary[i].split("=")[0] + "=" + encodeURIComponent(ary[i].split("=")[1]) + "&";
    }
    return url.split("?")[0] + "?" + params.replace(/\&$/gi,"");
}

function convertFormToURL(url, formObj) {
    var str = "";
    for (i=0; i < formObj.elements.length;i++) {
        if (formObj[i].name && formObj[i].name != '' &&
            formObj[i].type &&
            formObj[i].type.toLowerCase() != 'button' &&
            formObj[i].type.toLowerCase() != 'submit') {
            if (formObj[i].type.toLowerCase() == 'checkbox' || formObj[i].type.toLowerCase() == 'radio') {
                str += (formObj[i].checked ?
                        formObj[i].name + "=" + encodeURIComponent(formObj[i].value) + "&" : "");
            } else {
                if (formObj[i].type.toLowerCase().indexOf('select') >= 0 &&
                    formObj[i].multiple) {
                    for (multiInd=0; multiInd < formObj[i].options.length; multiInd++) {
                        if (formObj[i].options[multiInd].selected) {
                            str += formObj[i].name + "=" + encodeURIComponent(formObj[i].options[multiInd].value) + "&";
                        }
                    }
                } else {
                    str += formObj[i].name + "=" + encodeURIComponent(formObj[i].value) + "&";
                }
            }
        }
    }
    str = url + (url.indexOf("?") >= 0 ? "&" : "?") + str.replace(/\&$/gi,"");
    return str;
}

function ajaxLinkForControl(controlID, url) {
    ajaxLinkForControl1(document.getElementById(controlID), url, true);
}

function ajaxLinkForControl1(element, url, append) {
    var r = getAjaxRequest(url, element);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        element.value = stringTrim(r.responseText) + (append ? element.value.replace(/Please wait\.\.\./i,""): "");
    }
    element.value = 'Please wait...' + element.value;
}

function ajaxLink1(element, url) {
    var r = getAjaxRequest(url, element);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        element.innerHTML = r.responseText;
    }
    element.innerHTML = '<img src="/images/ajax.gif">';
}

function ajaxLink2(divID, url) {
    element = document.getElementById(divID);
    var r = getAjaxRequest(url, element);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        eval(r.responseText);
        element.innerHTML = '';
    }
    element.innerHTML = '<img src="/images/ajax.gif">';
}

function ajaxLinkSilent(divID, url) {
    element = document.getElementById(divID);
    var r = getAjaxRequest(url, element);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        element.innerHTML = r.responseText;
    }
}

function ajaxFormValidation(divID, url, htmlForm) {
    var element = document.getElementById(divID);
    var url = convertFormToURL(url, htmlForm);
    var r = getAjaxRequestFinal(url, element, false);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        eval(r.responseText);
        element.innerHTML = "";
    }
    element.innerHTML = '<div align="center"><img src="/images/ajax.gif"><br/>Validation in processs..</div>';
}

function ajaxAddTableRowForm(tableID, formDiv, htmlForm, url) {
    var element = document.getElementById(tableID);
    var url = convertFormToURL(url, htmlForm);
    var r = getAjaxRequestFinal(url, element, false);
    r.onreadystatechange = function () {
        if (r.readyState != 4) {
            return;
        }
        addTableRow(tableID, r.responseText);
    }
    formDiv.innerHTML = 'Processing...';
}

/*** END AJAX FUNCTIONS ***/




/*** START LIGHTBOX FUNCTIONS ***/
if (!LightboxInternal) {
    var LightboxInternal = {};    
}

var LIGHTBOX_STYLES = new Array();
LIGHTBOX_STYLES['lightbox-overlay'] = 'position:absolute;' +
    '   border:2px solid #000000;' +
    '   top:0;' +
    '   left:0;' +
    '   width:100%; ' +
    '   height:5000px;' +
    '   z-index:5000;  ' +
    '   background-color:#000; ' +
    '   opacity:.70;' +
    '   -moz-opacity: 0.7; ' +
    '   filter: alpha(opacity=80); ';

LIGHTBOX_STYLES['lightbox-widget-body'] = 'position:absolute; ' +
    '   z-index:10001;    ' +
    '   border:1px solid #cccccc; ' +
    '   background-color:#fff;  ' +
    '   padding: 5px; ' +
    '   left:35%; ' +
    '   top:20%; ';

LightboxInternal.JS = {
    
    blockBg: function() {
        var div = (document.getElementById("lightboxOverlay") == null ?
                   addDiv("lightboxOverlay"):
                   document.getElementById("lightboxOverlay"));
        setStyle(div, LIGHTBOX_STYLES['lightbox-overlay']);
        div.style.display='block';        
        div.style.top = LightboxInternal.JS.getTopOffset() + "px";
        div.onclick = function() {
            LightboxInternal.JS.unblockBg();
        };
    },

    unblockBg: function() {
        hideDiv("lightboxBodyDiv");
        hideDiv("lightboxOverlay");
        showSeeThroughElements();
    },

    showDiv: function(url) {
        LightboxInternal.JS.showDiv1(url, 450, 500);
    },

    getLightboxDiv: function() {
        var div = (document.getElementById("lightboxBodyDiv") == null ?
                   addDiv("lightboxBodyDiv"):
                   document.getElementById("lightboxBodyDiv"));
        div.innerHTML = "";
        setStyle(div, LIGHTBOX_STYLES['lightbox-widget-body']);
        div.style.display='block';
        div.style.top = (parseInt(LightboxInternal.JS.getTopOffset()) + (screen.height/6)) + "px";
        return div;
    },

    showDiv1: function(url, height, width) {
        hideSeeThroughElements();
        LightboxInternal.JS.blockBg();                
        var div = LightboxInternal.JS.getLightboxDiv();
        var spinner = LightboxInternal.JS.getWaitingSpinner();
        div.appendChild(spinner);
        div.style.width = width + 'px';
        div.style.height = height + 'px';
        div.innerHTML = div.innerHTML + ('<div align="center">' +
                                         '<div align="right"><a href="javascript:LightboxInternal.JS.unblockBg();" class="iconLink"><img class="iconLink" ' +
                                         'src="' + (BASE_URL ? BASE_URL : '') + '/images/iconshock/delete_16.gif" border="0"></a></div>' +
                                         '<iframe src="' + url + '&rand=1" frameborder="0" scrolling="auto" style="width:95%;height:' + 
                                         (parseInt(height) - 10) + 'px;"></iframe></div>');
        setTimeout("hideDiv('waitingImg');", 2000);
    },

    playVid: function(url) {
        LightboxInternal.JS.playVid1(url, 400, 580);
    },

    playVid1: function(url, height, width) {
        hideSeeThroughElements();
        LightboxInternal.JS.blockBg();
        var div = LightboxInternal.JS.getLightboxDiv();
        div.innerHTML = "<object type=\"application/x-shockwave-flash\" data=\"/images/FlowPlayerDark.swf\" id=\"FlowPlayerObj\" " + 
        "width=\"580\" height=\"400\">" +
        "<param name=\"allowScriptAccess\" value=\"always\"/>" +
        "<param name=\"movie\" value=\"/images/FlowPlayerDark.swf\"/>" +
        "<param name=\"quality\" value=\"high\"/>" +
        "<param name=\"scale\" value=\"noScale\"/>" +
        "<param name=\"wmode\" value=\"transparent\"/>" +
        "<param name=\"flashvars\" value=\"config={ autoPlay:true,loop:false,bufferLength:1," +
        "playList:[{overlayId: 'play'}, { name: 'Help Video', url:'" + url + "'}], showMenu:false,showLoopButton:false}\"/>" +
        "<embed id=\"FlowPlayer\" wmode=\"transparent\" src=\"/images/FlowPlayerDark.swf\" " +
        "type=\"application/x-shockwave-flash\" width=\"320\" height=\"263\"></embed>" +
        "</object>";
        var overlayDiv = document.getElementById("lightboxOverlay");
        overlayDiv.onclick = function() {
            LightboxInternal.JS.unblockBg();
            div.innerHTML = "";
        };
    },
    
    getWaitingSpinner: function() {
        return (document.getElementById("waitingImg") == null ?
                addImage("waitingImg", (BASE_URL ? BASE_URL : '') + "/images/waiting.gif") :
                document.getElementById("waitingImg"));
    },
       
    getTopOffset: function() {
        var s;
        // scrolling offset calculation via www.quirksmode.org
        if (self.pageYOffset){
            s = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            s = document.documentElement.scrollTop;
        } else if (document.body) {
            s = document.body.scrollTop;
        }
        return s;
    }
};

/*** END LIGHTBOX FUNCTIONS ***/


DynamicSearcher = { 
  hookupFocus: function(searchInputElement, defaultValue) {
    if (!defaultValue) {
        defaultValue = "Search";
    }

    if (searchInputElement.value == defaultValue) {
      searchInputElement.value = '';
    }
  },
  hookupBlur: function(searchInputElement, defaultValue) {
    if (!defaultValue) {
        defaultValue = "Search";
    }
    if (searchInputElement.value == '') { 
      searchInputElement.value = defaultValue;
    }
  },
  search: function(query, url, divId, resetURL) {

    if (query != null && query.length >= 3) {
      // only do the search if more than 3 letters

      if (this.currentSearch != query) {
        if (query.split(" ").length <= 3) {
          ajaxLinkSilent(divId, url + query);
        } 

        this.currentSearch = query;
      }
    } else if (query == null || query.length == 0) { 
      // Reset the search
      ajaxLinkSilent(divId, resetURL);
    }    
  },
  currentSearch: null
};

AutoComplete = {
  complete: function(sourceInput, targetName, postFix) {
    var form = sourceInput.form;
    var targetObject = form[targetName];
    if (targetObject.value == '' && sourceInput.value != '') {
      targetObject.value = sourceInput.value + " " + postFix;
    }   
  },

  completeURL: function(sourceInput, targetName, postFix) {
    var form = sourceInput.form;
    var targetObject = form[targetName];
    if (sourceInput.value != '') {
      targetObject.value = (sourceInput.value.split(' ').join('') + postFix).toLowerCase();
    }
  }
};

SmartCommentBox = {
  mouseIn: function (textArea, div) {
        showDiv(div);
  },
  mouseOut: function(textArea, div) {
    if (textArea.value.length == 0) { 
        hideDiv(div);
    }
  }
};


SmartExplanation = {
  onFocus: function(inputElement, divId) {
    showDiv(divId);        
  },
  onBlur: function(inputElement, divId) {
    // Do Not Hide Immediately
    timeoutId = window.setTimeout(function() { 
        hideDiv(divId);
        }, 5000);
  }
};

DirtyBitProcessor = {
  register: function(inputElement) {
    // Register this inputElement
    // For Dirty bit processing
    var dirtyBitElement = DirtyBitProcessor.getDirtyBitElement(inputElement.form);
    if (dirtyBitElement) { 
      // We have storage
      dirtyBitElement.value = 'true';
    }
  },
  processAjaxLink: function(formName, divId, linkURL) {
    var myForm = document.forms[formName];
    if (myForm) {
      // Havea form
      var dirtyBitElement = DirtyBitProcessor.getDirtyBitElement(myForm);
      if (dirtyBitElement && dirtyBitElement.value == 'true') {
	if (confirm("You are about to navigate away from a page where changes have not been saved." + 
        " Select Cancel to return to the page. Select OK to discard changes.")) {
	        // This form is Dirty 
        	// Need to save this
	        ajaxSubmitSilent(myForm);
	}
      }
    } 

    return ajaxLink(divId, linkURL);         
  },
  getDirtyBitElement: function(form) {
    return form.elements['DirtyBitField'];
  }
};


InteractiveSurveyProcessor = {
  register: function(inputElement) {
    // Register this inputElement
        
  },
  delayedDisplay: function(divId, timeout) {
    divElement = document.getElementById(divId);
    if (divElement) {
        window.setTimeout(function() {
          showDiv(divId)
        }, timeout * 1000);
    }
  },
  displayContinueButton: function() {
    showDiv('SurveySubmitButton');
  },
  disableContinueButton: function() {
    $("#SurveySubmitButtonElement").attr("disabled", "disabled");
  },
  enableContinueButton: function() {
    $("#SurveySubmitButtonElement").removeAttr("disabled");
  },
  ajaxConditionalSubmit: function(inputElement) {
    if (inputElement.checked) {
      this.ajaxSubmit(inputElement);
    }
  },
  ajaxSubmit: function(inputElement) {
    var fadeDone = false;;
    var response = null;

    $("#SurveyAjaxContainer").fadeOut("slow", function() { 
                                                fadeDone = true;
                                                if (response) { 
                                                  InteractiveSurveyProcessor.displayResponse(response);
                                                }
                                              });

    ajaxSubmitSilent(inputElement.form, function(r) {   
                                          response = r;
                                          if (fadeDone) {
                                            InteractiveSurveyProcessor.displayResponse(response);
                                          }
                                      });
  },
  displayResponse: function(response) {
    $("#SurveyAjaxContainer").html(response.responseText );
    $("#SurveyAjaxContainer").fadeIn("slow");
  }
}


function showFBDD(divID) {
    var header = document.getElementById(divID + "Header");
    var selHeader = document.getElementById(divID + "SelHeader");    
    var ddbody = document.getElementById(divID + "-body");
    
    if (ddbody.style.display == 'none') {
	selHeader.style.display='';
	header.style.display='none';
        ddbody.style.display='';
        ddbody.className='fbDDBody';        
    } else {
        hideFBDD(divID);
    }
}

function hideFBDD(divID) {
    var header = document.getElementById(divID + "Header");
    var selHeader = document.getElementById(divID + "SelHeader");
    var ddbody = document.getElementById(divID + "-body");
    selHeader.style.display='none';
    header.style.display='';
    ddbody.style.display='none';    
}


function setElementText(eleID, text) {
    document.getElementById(eleID).innerHTML=text;
}


AIM = { 
        frame : function(c) {
                 var n = 'f' + Math.floor(Math.random() * 99999);
                var d = document.createElement('DIV');
                d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\', \''+c.responseDivId+'\')"></iframe>';
                document.body.appendChild(d);
 
                var i = document.getElementById(n);
                if (c && typeof(c.onComplete) == 'function') {
                        i.onComplete = c.onComplete;
                }
                return n;
        },
 
        form : function(f, name) {
                f.setAttribute('target', name);
        },
 
        submit : function(f, c) {
                AIM.form(f, AIM.frame(c));

                if (c) {
                  if (typeof(c.onStart) == 'function') {
                        return c.onStart();
                  }
                  if (c.spinnerDivId) {
                    document.getElementById(c.spinnerDivId).innerHTML = '<img src=/images/ajax.gif>';
                  }
                } 

                return true;
        },
 
        loaded : function(id, responseDivId) {
                var i = document.getElementById(id);
                if (i.contentDocument) {
                        var d = i.contentDocument;
                } else if (i.contentWindow) {
                        var d = i.contentWindow.document;
                } else {
                        var d = window.frames[id].document;
                }
                if (d.location.href == "about:blank") {
                        return;
                }
 
                if (responseDivId) {
                  document.getElementById(responseDivId).innerHTML = d.body.innerHTML;
                }

                if (typeof(i.onComplete) == 'function') {
                        i.onComplete(d.body.innerHTML);
                }
        }
 
}

