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

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
<!--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 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=750,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.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() {
  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[1].elements[elementName].value = value;
    window.close();
}

function lookupDivAndClose(elementName, value, divId) {
    opener.document.forms[1].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 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);
          obj.childNodes[0].data = text;
        }
}

function modifyTextNoCheck(id, text) {
        if(document.getElementById) {
          obj = document.getElementById(id);
          obj.childNodes[0].data = 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;
           }
        }
}

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 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) {
        if(document.getElementById) {
          var signID = id + "_sign";

          obj = document.getElementById(id);
          if (obj.style.display == 'inline') {
            obj.style.display='none';
            if (document.getElementById(signID)) {
		  document.images[signID].src='/images/plus.gif';
            }
	       
          } else {
            obj.style.display='inline';        
            if (document.getElementById(signID)) {
		  document.images[signID].src='/images/minus.gif';
            }
		  
          }

        }
}


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) {
			//alert(str);
			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='inline';        
          } else {
            obj.style.display='none';
          }
      }
}

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


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

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) {
        if (selectInput.selectedIndex >= 0) {
                var index = selectInput.selectedIndex;
                docLocation = "/help/" + selectInput.options[index].value + "-window.html";
                gotoLoc(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){

	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){

		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 = "Current Total:&nbsp;&nbsp;&nbsp;&nbsp;" +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 ajaxSubmitForm(divID, url, formName) {
  var htmlForm = document.forms[formName];
  ajaxSubmitFormObject(divID, url, htmlForm);
}
function ajaxSubmitFormObject(divID, url, htmlForm) {
  ajaxSubmitFormObjectFinal(divID, url, htmlForm, false);
}

function ajaxSubmitFormObjectFinal(divID, url, htmlForm, evaluateJS) {
  var container = document.getElementById(divID);
  if (container && htmlForm) {
        // Sanity Check Passed
        dojo.io.bind({
            url: url,
            content: {
                ajax: true,
                engine: 'dojo'
            },
            formNode: htmlForm,
            load: function(type, data) {
                if (evaluateJS) {
                  eval(data);
                  container.innerHTML = "";
                } else {
                  container.innerHTML = data;
                }
            }
        });
        container.innerHTML = '<div align="center"><img src="/images/ajax.gif"><br/>Processing</div>';
  }

}



function ajaxDeleteRow(rowID, url, identifierValue) {
  container = document.getElementById(rowID);
  if (confirm("Are you sure?") && container) { 
    dojo.io.bind({
        url: url,
        content: {
            ajax:true,
            engine: 'dojo',
            id:identifierValue
        },
        load:function(type, data, event) {
          container.parentNode.deleteRow(container.rowIndex);
        }
    });
    // Update the Status Containter
    statusSpan = document.getElementById("status_" + identifierValue);
    if (statusSpan) {
        statusSpan.innerHTML = '<img src="/images/ajax.gif">';
    }
  }
}

function ajaxFormValidation(divID, url, htmlForm) {

  var container = document.getElementById(divID);
  if (container && htmlForm) {
        dojo.io.bind({
            url: url,
            content: {
                ajax: true,
                engine: 'dojo'
            },
            formNode: htmlForm,
            load: function(type, data) {
                eval(data);
            }
        });
        container.innerHTML = '<div align="center"><img src="/images/ajax.gif"><br/>Validation in processs..</div>';
  }

}



function ajaxAddTableRowForm (tableID, formDiv, htmlForm, url) {
        
  container = document.getElementById(tableID);
  if (container) {
        dojo.io.bind (
           {  url: url,
              content: {
                ajax:true, 
                engine: 'dojo'
              },
              formNode: htmlForm,
              load:function(type, data, event) {
                addTableRow (tableID, data);
              }
           }
        );  
        formDiv.innerHTML = 'Processing...';
  }       
               
}

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);
   }       
           
}

function ajaxLink(divID, url) {
  container = document.getElementById(divID);
  dojo.io.bind({
        url: url,
        content: {
            ajax:true,
            engine: 'dojo'
        },
        load:function(type, data, event) {
          container.innerHTML = data;
        }
  });
  // Update the Status Container
  container.innerHTML = '<img src="/images/ajax.gif">';
}


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 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 modifyMicroPollProgressBarColor (sudoID, selectBox, customColorField) {
         
        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)) {
                        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.bgColor = customColor;
        }
}
