	
  	var publishResultsWin = null;
	function LoadWinPublishResults(publishId)
	{
		//  if (self.specWin == null) alert ('specwin is null')
	   OpenWinPublishResults();
      if (checkOpened(self.publishResultsWin)) {
   	   self.publishResultsWin.status = 'Loading publish results...' 
   	   self.publishResultsWin.location.href = 'surPublishResults.asp?publish_id=' + publishId;
   	   self.publishResultsWin.focus();
      }
	}
		
	function OpenWinPublishResults()
	{
	   if(publishResultsWin) 
	   {
	      if (!self.publishResultsWin.closed) return;
	   }
	   publishResultsWin = open("", "publishResultsWin", "height=600,width=800,toolbar=yes,scrollbars=yes,resizable=yes,status=yes,menubar=yes,location=yes")
	}

	var previewWin = null;
	function LoadPreviewWin (URL, height, width)
	{
	   
		OpenPreviewWin(height, width);
      if (checkOpened(self.previewWin)) {
   	   self.previewWin.status = 'Loading page...' 
   	   self.previewWin.location.href = URL;
   	   self.previewWin.focus();
	   }
   }
	
	function OpenPreviewWin (height, width)
	{
	   var winHeight = 400;
	   var winWidth  = 400;
	   
	   //if(height < winHeight && height > 0) {winHeight = height;}
		if(height > 0) {winHeight = height;}
	   //if(width < winWidth && width > 0) {winWidth = width;}
	   if(width > 0) {winWidth = width;}
		
		//alert('test' + previewWin); 
	   if(previewWin) 
	   {
			if (!self.previewWin.closed) return;
	   }  
	   previewWin = open("", "previewWin", "height=" + winHeight + ",width=" + winWidth + ",toolbar=yes,scrollbars=yes,resizable=yes,status=yes")
		
	}

	var itemClassesWin = null;
	function LoadItemClassesWin (URL, height, width)
	{
	   
		OpenItemClassesWin(height, width);
      if (checkOpened(self.itemClassesWin)) {
   	   self.itemClassesWin.status = 'Loading page...' 
   	   self.itemClassesWin.location.href = URL;
   	   self.itemClassesWin.focus();
      }
	}
	
	function OpenItemClassesWin (height, width)
	{
	   var winHeight = 400;
	   var winWidth  = 400;
	   
	   //if(height < winHeight && height > 0) {winHeight = height;}
		if(height > 0) {winHeight = height;}
	   //if(width < winWidth && width > 0) {winWidth = width;}
	   if(width > 0) {winWidth = width;}
		
		//alert('test' + previewWin); 
	   if(itemClassesWin) 
	   {
			if (!self.itemClassesWin.closed) return;
	   }  
	   itemClassesWin = open("", "itemClassesWin", "height=" + winHeight + ",width=" + winWidth + ",toolbar=yes,scrollbars=yes,resizable=yes,status=yes")	
	}
	
	var stdResponsesWin = null;
	function LoadWinStdResponses(frm, fld, type)
	{
		//  if (self.specWin == null) alert ('specwin is null')
	   OpenWinStdResponses();
      if (checkOpened(self.stdResponsesWin)) {
   	   self.stdResponsesWin.status = 'Loading data...' 
	      self.stdResponsesWin.location.href = 'pop_std_responses.asp?fid='+frm+'&fieldName='+fld+'&type='+type;
	      self.stdResponsesWin.focus();
	   }
   }
		
	function OpenWinStdResponses()
	{
	   if(stdResponsesWin) 
	   {
	      if (!self.stdResponsesWin.closed) return;
	   }
	   stdResponsesWin = open("", "stdResponsesWin", "height=400,width=500,toolbar=yes,scrollbars=yes,resizable=yes,status=yes,left=430,top=160,screenX=430,screenY=160")
	}
		
	var textGridSettingsWin = null;
	function LoadWinTextGridSettings(isDataSpecific, hasPrefixSuffix, value, isPublished)
	{
		
		var arVal;
		arVal = value.split('\n');
		var comma;
		comma = '';
		value = '';
		//alert(arVal.length);
		for (var i =0;i<arVal.length;i++) {
			arVal[i] = arVal[i].replace(/&/g,"%26");
			arVal[i] = arVal[i].replace(/'/g,"");
			arVal[i] = arVal[i].replace(/"/g,"");
			value = value + comma + arVal[i];
			comma  = '~';
		}
		
		//alert(arVal[1] + '-' + arVal[2]);
	//	alert(isDataSpecific + '-' + hasPrefixSuffix + '-' + value);
		
		//alert(document.surFrmItemAttribs.surFrmItemHorizontalAxis.textarea.value());
		//  if (self.specWin == null) alert ('specwin is null')
	   OpenWinTextGridSettings();
      if (checkOpened(self.textGridSettingsWin)) {
   	   self.textGridSettingsWin.status = 'Loading items...' 
	      self.textGridSettingsWin.location.href = 'pop_textgrid_settings.asp?fid=surFormItemAttribs&dataSpec=' + isDataSpecific + '&prefSuf=' + hasPrefixSuffix +  '&data=' + value + '&dTypes=' + document.surFormItemAttribs.matrixColDataTypes.value + '&cPulldownOptions=' + document.surFormItemAttribs.matrixPulldownOptions.value + '&cTotal=' + document.surFormItemAttribs.matrixCalculateColTotal.value+ '&cTxtSize=' + document.surFormItemAttribs.matrixColTextSize.value + '&cLanguageIds=' + document.surFormItemAttribs.languageIds.value + '&cLanguageNames=' + document.surFormItemAttribs.languageNames.value + '&cPulldownTrans=' + document.surFormItemAttribs.matrixPulldownTrans.value +'&p=' + isPublished;
	      self.textGridSettingsWin.focus();
      }
	}
		
	function OpenWinTextGridSettings()
	{
	   if(textGridSettingsWin) 
	   {
	      if (!self.textGridSettingsWin.closed) return;
	   }
	   textGridSettingsWin = open("", "textGridSettingsWin", "height=600,width=680,toolbar=yes,scrollbars=yes,resizable=yes,status=yes,left=330,top=40,screenX=330,screenY=40")
	}
	
	
	
	var stylesWin = null;
	function LoadWinStyles(frame,surveyId, classId, text)
	{
		//  if (self.specWin == null) alert ('specwin is null')
	   OpenWinStyles();
      if (checkOpened(self.stylesWin)) {
   	   self.stylesWin.status = 'Loading style...' 
   		self.stylesWin.location.href = 'pop_styles.asp?open_class_Id=' + classId + '&survey_id=' + surveyId + '&textContents=' + text + '&frame=' + frame;
   	   self.stylesWin.focus();
      }
	}
		
	function OpenWinStyles()
	{
	   if(stylesWin) 
	   {
			//if (!self.stylesWin.closed) return;
			
			//if not closed then close it and reopen
			if (!self.stylesWin.closed)
			{
				stylesWin.close();
			}
	   }
	   stylesWin = open("", "stylesWin", "height=580,width=700,toolbar=no,scrollbars=yes,resizable=yes,status=yes,left=800,top=800,screenX=800,screenY=800")
	}
	

	var colourSelectorWin = null;
	function LoadWinColourSelector(colour, field)
	{
		
		//  if (self.specWin == null) alert ('specwin is null')
	   OpenWinColourSelector();
      if (checkOpened(self.colourSelectorWin)) {
   	   self.colourSelectorWin.status = 'Loading colour pallettes...' 
   	   self.colourSelectorWin.location.href = 'colourSelector.asp?colour=' + colour + '&field=' + field;
   	   self.colourSelectorWin.focus();
      }
	}
		
	function OpenWinColourSelector()
	{
	   if(colourSelectorWin) 
	   {
	      //if (!self.colourSelectorWin.closed) return;
			
			//if not closed then close it and reopen
			if (!self.colourSelectorWin.closed)
			{
				colourSelectorWin.close();
			}
	   }
	   colourSelectorWin = open("", "colourSelectorWin", "height=200,width=500,toolbar=no,scrollbars=no,resizable=yes,status=yes,left=600,top=800,screenX=600,screenY=800")
	}

	var imagesCopyrightWin = null;
	function LoadWinImagesCopyright()
	{
		
	   OpenWinImagesCopyright();
      if (checkOpened(self.imagesCopyrightWin)) {
   	   self.imagesCopyrightWin.status = 'Loading images help...' 
   	   self.imagesCopyrightWin.location.href = 'pop_image_copyright.asp';
   	   self.imagesCopyrightWin.focus();
      }
	}
		
	function OpenWinImagesCopyright()
	{
	   if(imagesCopyrightWin) 
	   {
			//if not closed then close it and reopen
			if (!self.imagesCopyrightWin.closed)
			{
				imagesCopyrightWin.close();
			}
	   }
	   imagesCopyrightWin = open("", "imagesCopyrightWin", "height=480,width=620,toolbar=no,scrollbars=yes,resizable=yes,status=yes,left=200,top=160,screenX=200,screenY=160")
	}

	var agreementWin = null;
	function LoadWinAgreement()
	{
		
	   OpenWinAgreement();
      if (checkOpened(self.agreementWin)) {
   	   self.agreementWin.status = 'Loading terms and conditions...' 
   	   self.agreementWin.location.href = 'privacyagreement.html';
   	   self.agreementWin.focus();
      }
	}
		
	function OpenWinAgreement()
	{
	   if(agreementWin) 
	   {
			//if not closed then close it and reopen
			if (!self.agreementWin.closed)
			{
				agreementWin.close();
			}
	   }
	   agreementWin = open("", "agreementWin", "height=480,width=620,toolbar=no,scrollbars=yes,resizable=yes,status=yes,left=200,top=160,screenX=200,screenY=160")
	}

	
function Mod(a, b) { return a-Math.floor(a/b)*b }



   
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
   return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
   if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if (strDateArray.length != 3) {
         err = 1;
         return false;
      }
      else {
         strDay = strDateArray[0];
         strMonth = strDateArray[1];
         strYear = strDateArray[2];
      }
      booFound = true;
   }
}
if (booFound == false) {
   if (isNaN (strDate.value)) { 
      if (strDate.length = 6) {
         strDay = strDate.substr(0, 2);
         strMonth = strDate.substr(2, 2);
         strYear = 20 + strDate.substr(4);
      }
      else if (strDate.length = 8) {
         strDay = strDate.substr(0, 2);
         strMonth = strDate.substr(2, 2);
         strYear = strDate.substr(4);
      }
      else
      { 
         return false;
      }
   }
   else
   { 
      return false;
   }
     
}

if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
}
return true;
}



function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
alert("The dates are valid.");
}
else {
if (from.value == "" || to.value == "") 
alert("Both dates must be entered.");
else 
alert("To date must occur after the from date.");
   }
}
   

	
var where = ""; // which link
var isNav = (navigator.appName == "Netscape") ? true:false;

function checkwhere(e, winW, winH) {
        if(isNav) {evt = e;}
        else {evt = event;}
        xCoord = window.evt.x;
        yCoord = window.evt.y;

		  var xCoordRel, yCoordRel;
	  	  xCoordRel = window.evt.screenX;
		  yCoordRel = window.evt.screenY;
		  helpTxtWin.moveTo(xCoordRel+10,yCoordRel + 10)
        }


//document.onmousemove = checkwhere;
if(isNav) {document.captureEvents(Event.MOUSEMOVE);}

function openHelpText(helpText,theUrlPop, winW, winH){

	// set the popup window width and height
	
	var windowW= winW //214 // wide
	var windowH= winH  //398 // high
	
	// set the screen position where the popup should appear
	
	var windowX = 260 // from left
	var windowY = 100 // from top
	
	// set the url of the page to show in the popup
	
	var urlPop = theUrlPop + '?helpText=' + helpText
	
	// set the title of the page
	
	var title =  "This Is A Frameless Popup Window"
	
	// set this to true if the popup should close
	// upon leaving the launching page; else, false
	
	var autoclose = true
	
	// ============================
	// do not edit below this line
	// ============================
	
	s = "width="+windowW+",height="+windowH;
	var beIE = document.all?true:false

  if (beIE){
    helpTxtWin = window.open("","popFrameless","fullscreen,"+s)     
    helpTxtWin.blur()
    window.focus()       
    helpTxtWin.resizeTo(windowW,windowH)
	 
    helpTxtWin.moveTo(windowX,windowY)
    var frameString=""+
		"<html>"+
		"<head>"+
		"<title>"+title+"</title>"+
		"</head>"+
		"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
		"<frame name='top' src='"+urlPop+"' scrolling='no' bordercolor='#ffffff'>"+
		"<frame name='bottom' src='about:blank' scrolling='no'>"+
		"</frameset>"+
		"</html>"
    helpTxtWin.document.open();
    helpTxtWin.document.write(frameString)
    helpTxtWin.document.close()
  } else {
    helpTxtWin=window.open(urlPop,"popFrameless","scrollbars,"+s)
    helpTxtWin.blur()
    window.focus()
    helpTxtWin.resizeTo(windowW,windowH)
    helpTxtWin.moveTo(windowX,windowY)
  }   
  helpTxtWin.focus()   
  if (autoclose){
    window.onunload = function(){helpTxtWin.close()}
  }
}

function calpopup(lnk) { 
window.open(lnk, "calendar","height=230,width=200,scrollbars=no") ;
checkOpened(lnk) ;

}

function trim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.squeeze = function() {
	return this.replace(/ /g," ");
}

// function to convert a form select array into a list
function getSelectList (f)
{
   var sOpt = ''; 
   for (var i=0; i<f.length; i++) { if (f[i].checked) { sOpt = ',' + f[i].value + sOpt }};
   return sOpt.substring (1)
}



// set the focus on the first form field, unless a search form (paging required)
function focusField () {
   for (var frm=0; frm< document.forms.length; frm++) { 
      if (document.forms[frm].name.search ('search') >= 0) {
         return false;
      }
      for (var i = 0; i < document.forms[frm].elements.length; i++) {
         f = document.forms[frm].elements[i];
         if (f.type=='text' || f.type=='password' || f.type=='textarea' || f.type=='checkbox' || f.type=='select' || f.type=='radio') {
            f.focus ();
            return true ;
         }
      }      

   }
}

function checkOpened (win) {
   if (!win) {
      alert ('Unable to open the window. This is probably due to a pop-up blocker which must be removed in order to continue.');
      return false;
   } else {
      return true ;
   }
}

function setShade (f, en) {
   if (f) {
      if (en) {
         if (f.filters) { if (f.filters.alpha) { f.filters.alpha.opacity=50; }}
         if (f.style) { f.style.opacity=0.5; }
      } else {
         if (f.filters) { if (f.filters.alpha) { f.filters.alpha.opacity=100; }}
         if (f.style) { f.style.opacity=1; }
      }
   }
}
function composerProtect (val) {

    var retVal = true ; // object may not be loaded, so check each one and return if any fail TBD
    
    top.menu.document.protected = val;  
    
    if (top.menu.document.setStyle) { 
      top.menu.document.setStyle.style_id.disabled = val; 
    } else { retVal = false }
    
    if (top.menu.document.composeOptions) {
       top.menu.document.composeOptions.showRefs.disabled = val; 
       top.menu.document.composeOptions.showSubtext.disabled = val; 
      top.menu.document.composeOptions.showHelp.disabled = val;
    } else { retVal = false }
    
    if (top.menu.document.setLanguage) {
      top.menu.document.setLanguage.language_selected.disabled = val; 
    } else { retVal = false }
   
    if (top.menu.document.userSurItems) {
       top.menu.document.userSurItems.surFrmItemName.disabled = val ;
       setShade (top.menu.document.userSurItems.surFrmItemName, val)
    } else { retVal = false }
      
   // controls
   for (var i=1; i<=8;i++) { 
      if (top.menu.document.getElementById('ctl' + i)) { 
         setShade (top.menu.document.getElementById('ctl' + i), val)
      }
   }
    
    // buttons
    for (i=1;i<=4;i++) {
      if (top.menu.document.getElementById('btn'+i)) { 
          top.menu.document.getElementById('btn'+i).disabled = val;
          setShade (top.menu.document.getElementById('btn'+i), val)         
      }
    }
    if (top.menu.document.getElementById('train1')) { 
        if (val) { 
         top.menu.document.getElementById('train1').style.display='none' 
        } else { 
         top.menu.document.getElementById('train1').style.display='inline' 
        } 
    }
   
    if (top.menu.document.setEditor) { 
      top.menu.document.setEditor.editor_type.disabled = val
    } else { retVal = false }
    
    if (top.menu.document.surveySelector) { 
      top.menu.document.surveySelector.newSurveyId.disabled = val 
    } else { retVal = false }
   
    return retVal ; 
} 
   
function convertDecimalToRomanNumerals(inNumber) {
	if (!+inNumber)
		return false;
	var	digits = String(+inNumber).split(""),
		key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
		       "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
		       "","I","II","III","IV","V","VI","VII","VIII","IX"],
		roman = "",
		i = 3;
	while (i--)
		roman = (key[+digits.pop() + (i * 10)] || "") + roman;
	return Array(+digits.join("") + 1).join("M") + roman;
}

// higlight a pulldown field if index > 0 - used for branching
function highlightSelected (f) {
   if (f.selectedIndex > 0) {
      f.style.color='blue'
   } else { 
      f.style.color='#606060'
   }
}   

function isNumeric (a) {
   var charpos = a.search("[^0-9]"); 
   if( charpos >= 0) 
   { return false; } else { return true; }
}	

// check for a valid date format
function isDate (inp) {
   
//   alert (Date.parse (numDate (inp)) + ' ' + (Date.parse (numDate (inp))  == 'NaN') )
   return true 
//   return Date.parse (numDate (inp)) != 'NaN';
}


// replaces the month string with a numeric month number
function numDate (inp) {

   var d = inp.toLowerCase ();
   d = d.replace ('jan', '1');
   d = d.replace ('feb', '2');
   d = d.replace ('mar', '3');
   d = d.replace ('apr', '4');
   d = d.replace ('may', '5');
   d = d.replace ('jun', '6');
   d = d.replace ('jul', '7');
   d = d.replace ('aug', '8');
   d = d.replace ('sep', '9');
   d = d.replace ('oct', '10');
   d = d.replace ('nov', '11');
   d = d.replace ('dec', '12');

   return d; 
}

function frmValDate (f, oVal) {

   if (f.value == '') {
      return true 
   } else if (objDate (f.value) == '') {
      f.value = oVal;
      f.focus();
      alert ('Error in date format, please use format "1-Jan-2008" ');
      return false;         
   } else {
      return true 
   }
}

// converts a string date into a date object, can also be used to validate date format
function objDate (inp) {
   
   var parts, dObj = new Date ();
   
   var d = numDate (inp);
   
   // get the elements into an array, rebuilding to replace slahses with dashes, must be 3 parts
   parts = d.split ('/').join ('-').split ('-')
   if (parts.length != 3) {
      return '' 
   }   
   
   parts[1] --; // numDate or numeric input returns 1-12, adjust for array subscript
   
   // create the date 
   dObj.setFullYear (parts[2],parts[1],parts[0]) 

   //alert ('"' + dObj.getDate () + '-' + dObj.getMonth () + '-' + dObj.getFullYear () + '" "' + parts.join ('-'))

   // since the above function gives the wrong date if the day rolls over a month, check it against original
   if (dObj.getDate () + '-' + dObj.getMonth () + '-' + dObj.getFullYear () == parts.join ('-')) {
      return dObj; 
   } else {
      return ''; 
   }
}  


// function to suppress the form submission on the return key
function noenter() {
  return !(window.event && window.event.keyCode == 13); }

function checkNumber (field) {
  f = field.value.replace ('.',''); 
  if ( !isNumeric(f) || f.value == "" || f.value < 1 || f.value > 1000 )
  {
	alert("Numeric input required ");
   field.value=''; field.focus(); return false;
  
  }
  return true; 
}
function isNumeric (a) {
   var charpos = a.search("[^0-9]"); 
   if( charpos >= 0) 
   { return false; } else { return true; }
}	
