var arr_Checked = new Array();

var bool_showing = false;

Xoffset = 10;    // modify these values to ...
Yoffset = 20;    // change the popup position.

var old,skn;
var iex=(document.all);
var yyy = -1500;

var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all&&!document.getElementById;
var ie5 = false;

var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');

var getDragDropData = false;

is_ie   = ((iePos!=-1));

if(!is_ie)
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesMAC.css\" />");
else
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesIE.css\" />");

function setBox(x)
{
		document.getElementById(x).focus();
}

function loadCode() {
	
	if(iePos != -1) {
	
		//skn=document.getElementById("dek").style
		ie5 = true;
	}
	else if (ns4) {
		skn=document.dek
	}else if (ns6) {
		//skn=document.getElementById("dek").style
	} else if (ie4) {
		skn=document.all.dek.style
	}

	if(ns4) {
		document.captureEvents(Event.MOUSEMOVE);
	} else {
		//skn.visibility="visible"
		//skn.display="none"
	}

	document.onmousemove=get_mouse;
}

function changePage() {
   window.location.href = "Display.aspx?project=<%=getProjectHASH() %>&respNo=<%=getID()%>&RotationProgress=<%=getRotationProgress()%>&currentPage=" + document.getElementById("newPage").value;
}
        
function cancelPage() {

  //$("#container").css("display","none"); 
  return false;
}
            
function showOptions() {
   
   if(document.getElementById("divComments").style.display == "inline"){
    
        document.getElementById("divComments").style.display = "none"; 
        document.getElementById("aShowComments").innerHTML = "Show Programming Comments";
   
   }else {
   
        document.getElementById("aShowComments").innerHTML = "Hide Programming Comments";
        document.getElementById("divComments").style.display = "inline";
        document.getElementById("divComments").style.height = "200px";
    }
}

function showChangePage() {
    if(document.getElementById("container").style.display == "inline"){
       document.getElementById("container").style.display = "none"; 
    }else {
       document.getElementById("container").style.display = "inline"; 
    }
}

function popup(msg,bak){
	var content="<TABLE  WIDTH=150 style='border: solid 1px #707070' CELLPADDING=4 CELLSPACING=0 "+
	"BGCOLOR="+bak+"><TD><FONT COLOR=black SIZE=2>"+msg+"</FONT></TD></TABLE>";
	
	yyy=Yoffset;
 	
	if(ns4){
		//skn.document.write(content);
		//skn.document.close();
		//skn.visibility="visible";
	}
 	
	if(ie5) {
		document.getElementById("dek").innerHTML=content;
		skn.display = "inline";
	}

	if(ns6){
		document.getElementById("dek").innerHTML=content;
		//skn.display=''
	}
 	
	if(ie4){
		document.all("dek").innerHTML=content;
		//skn.display=''
	}
}

function get_mouse(e){
	var x=(ns4||ns6)?e.pageX:event.x + 75;
	var y=(ns4||ns6)?e.pageY:event.y + 180;
	//skn.top=y + Yoffset;
	//skn.left=x+Xoffset;
}

function kill(){
	//yyy=-1500;
	
	if(ns4){
		//skn.visibility="hidden";
	}
	else if (ns6||ie4) {
		//skn.display="none";
	}
	
	if(ie5) {
		skn.display = "none";
	}
}

function switchvisibility(x)
{
           
	if (document.getElementById("x_other").style.visibility == "hidden")
		{document.getElementById("x_other").style.visibility = "visible";
		 document.getElementById("x_other").style.position = "static";
		 setTimeout("document.getElementById('" + x + "_other" + "').focus();",200);
		}
	else
		{document.getElementById("x_other").style.visibility = "hidden";
		 document.getElementById("x_other").style.position = "absolute";	}
}

function showOther(x)
{
           
	document.getElementById("x_other").style.visibility = "visible";
	document.getElementById("x_other").style.position = "static";
	setTimeout("document.getElementById('" + x + "_other" + "').focus();",200);
		
}

function output_numpad(str_name, str_inputmask, int_min, int_max, int_height, int_width)
{
	document.writeln("<object width='" + int_width + "px' height='" + int_height + "px' id='" + str_name + "' name='" + str_name + "' classid=\"InkPad.dll#InkPad.InkPad1\">")
	document.writeln("<param name='InputMask' value='" + str_inputmask + "'>")
	document.writeln("<param name='minValue' value='" + int_min + "'>")
	document.writeln("<param name='maxValue' value='" + int_max + "'>")
	document.writeln("</object>")
}

function output_writepad(var_name, size)
{
	document.writeln("<object id='<" + var_name+ ">' name='" + var_name + "' classid='PC1.dll#PC1.UserControl1'>")
	document.writeln("	<param name='lines' value='2'>")
	if (size == "short")
		{document.writeln("	<param name='size' value='800:100'>")}
	document.writeln("</object>")
}
// this function validates that the enty type is numeric
function checkNumeric(textArea, MinValue, MaxValue) {
	
	// check to see that we only have numeric characters
	var str_Value = textArea.value;
	var str_TempString ="";
	var str_NewString = "";
	var bool_Error = false;
	var bool_Match = true;
	
	// array of permissable values
	var arr_numbers = new Array(10);
	arr_numbers[0] = "0";
	arr_numbers[1] = "1";
	arr_numbers[2] = "2";
	arr_numbers[3] = "3";
	arr_numbers[4] = "4";
	arr_numbers[5] = "5";
	arr_numbers[6] = "6";
	arr_numbers[7] = "7";
	arr_numbers[8] = "8";
	arr_numbers[9] = "9";
	
	// we are allowed a :-" for the first char.
	
	for(n=0; n < str_Value.length;n++) {
		
		str_TempString = str_Value.substring(n,n+1);
		
		bool_Match = false;
		
		if(str_TempString == "-" && n==0) {
			bool_Match = true;
			str_NewString = str_NewString + str_TempString;
		} else {
		// loop through the list if we fail to match then raise an error
		
		    for(x=0; x < arr_numbers.length;x++) {
			    if(str_TempString == arr_numbers[x]) {
				    bool_Match = true;
				    str_NewString = str_NewString + str_TempString;
			    }
		    }
		    
		}
		
		if(!bool_Match)
			bool_Error = true;
	}
	
	if(bool_Error) {
		alert("Sorry this box can only accept numeric characters ");
	}else {
		// now check the range of values
		if(str_NewString > MaxValue) {
			alert("Sorry this box can only values between " + MinValue + " and " + MaxValue);
		str_NewString = "";
		}
	}
		
	

	textArea.value = str_NewString;
}

// this function invalidates all other column and row option 
function zSelect(arr_Groups, selectedCol, selectedRow) {

    if(arr_Groups.length == 1)
        return;

    //arr_Groups = array list of row groups
    //selectedCol = column number in the matrix
    //selectedRow = currently selected row
   
    // first disable all elements in the current column
    for(n=0; n < arr_Groups.length;n++) {

        if(n != selectedRow) {
            document.frmCheckMe[arr_Groups[n]][selectedCol].parentNode.parentNode.style.backgroundPosition = "25%";
            document.frmCheckMe[arr_Groups[n]][selectedCol].parentNode.parentNode.disabled = true;
            document.frmCheckMe[arr_Groups[n]][selectedCol].disabled = true;
        }
        
    }
    
    // now do the current column
    for(c=0; c < document.frmCheckMe[arr_Groups[selectedRow]].length;c++) {
        if(c != selectedCol) {
            document.frmCheckMe[arr_Groups[selectedRow]][c].parentNode.parentNode.style.backgroundPosition = "25%";
            document.frmCheckMe[arr_Groups[selectedRow]][c].parentNode.parentNode.disabled = true;
            document.frmCheckMe[arr_Groups[selectedRow]][c].disabled = true;
        }
    }
    
    return;

}

// this function check to see if we have any selected radio buttons in the matrix and sorts out the group
function zSelectPrev(arr_Groups) {
    
    var arr_selectedCol = new Array();
    var arr_selectedRow = new Array();
    
    
    for(n=0; n < arr_Groups.length;n++) {
        
            for(c=0; c < document.frmCheckMe[arr_Groups[n]].length;c++) {
                
                // if we find a selected item then disable the rest of the group
                
                    if(document.frmCheckMe[arr_Groups[n]][c].checked == true) {
                        
                        arr_selectedCol[arr_selectedCol.length] = c;
                        arr_selectedRow[arr_selectedRow.length] = n;
                    }
            
            }
                
    }
    
    // now deselect all the other options
    for(t=0; t < arr_selectedCol.length;t++) {
        zSelect(arr_Groups,arr_selectedCol[t],arr_selectedRow[t]);
    }
    

}

function resetSelection(RadioGroup) {

	// loop through all groups and let checked and disabled to false
	
	for(g=0; g < RadioGroup.length;g++) {
		
		for(r=0; r < document.frmCheckMe[RadioGroup[g]].length;r++) {
			//alert(RadioGroup[g].length + " " + g + " " + r);
			document.frmCheckMe[RadioGroup[g]][r].parentNode.parentNode.style.backgroundPosition = "25% top";
            document.frmCheckMe[RadioGroup[g]][r].parentNode.parentNode.disabled = false;
            document.frmCheckMe[RadioGroup[g]][r].disabled = false;
			document.frmCheckMe[RadioGroup[g]][r].checked = false;
			document.frmCheckMe[RadioGroup[g]][r].parentNode.parentNode.style.backgroundColor = "";
			
		}
		
	}

}

//trim function
 function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


//function returns number of checked boxes on multi punch questions
function oneChecked()
{
	var intCheckCount = 0;
	for (i=0; i < document.frmCheckMe.length; i++)
		{
			if (document.frmCheckMe.elements[i].checked == true)
				{intCheckCount ++}
		}

	return(intCheckCount);
}

//used on rollovers on question responses
function highlighton(z)
{
  z.style.backgroundColor='#cccccc';
 }

function highlightoff(z)
{
  z.style.backgroundColor='';
}

//used on rollovers for grid questions
function mhighlighton(z,r)
{
  highlighton(z);
  highlighton(document.getElementById(r));
}

function mhighlightoff(z,r)
{
  highlightoff(z);
  highlightoff(document.getElementById(r));
}


function setValue(x)
	{document.getElementById(x).value = 'DK';}

function deselector(x)
{
    var frm = document.frmCheckMe;
  
    if (x.checked == false)
    {

        for(var ii=0; ii<frm.elements.length; ii++)
        {
            if (frm.elements[ii].type == "checkbox" && frm.elements[ii] != x) {
                frm.elements[ii].parentNode.style.backgroundPosition = "4px 0";
                frm.elements[ii].parentNode.disabled = false;
                frm.elements[ii].disabled = false;
            }
        }

	    x.checked = true;
	    x.disabled = false;
	
	} else {
	
		//x.checked = false;
        for(var ii=0; ii<frm.elements.length; ii++)
        {
            if (frm.elements[ii].type == "checkbox" && frm.elements[ii] != x) {
                frm.elements[ii].checked = false;
                frm.elements[ii].parentNode.style.backgroundPosition = "25%";
                frm.elements[ii].parentNode.style.backgroundColor = "#FFFFFF";
                frm.elements[ii].parentNode.disabled = true;
                frm.elements[ii].disabled = true;
            }
        }

	}
}

function divstyle()
{
var divstyle;
divstyle= document.getElementById('reminder').style;

  if(divstyle.display == "none")
  {
    divstyle.display = "inline";
    document.getElementById('rembutton').innerHTML = "";
  }
 else{
    divstyle.display = "none";
    document.getElementById('rembutton').innerHTML = "";
 }
}

//hides the next button for conjoint
function hideNext(button)
  {
    document.getElementById('NextbuttonMain').style.display = 'none';
    
    if(getDragDropData) {
        getValues()
    }else {
        document.frmCheckMe.submit();
    }
    
  }

//submits the page after conjoint
	function submitMe()
	{
	document.frmCheckMe.submit();
	}


function checkRecording() {
	if(bool_Record){
		alert("Please stop recording then press next");
		return true;
	}else {
		return false;
	}
}
  // stuff for the drag and drop
var flashProxy

function setupDragDrop(str_FlashVars) {
	var uid = new Date().getTime();
	flashProxy = new FlashProxy(uid, 'JavaScriptFlashGateway.swf');
	var tag = new FlashTag('DragDrop.swf', 910, 450,"XMLData",str_FlashVars.replace(/"/gi,"'")); // last two arguments are height and width
	tag.setFlashvars('lcId='+uid);
	tag.bgcolor = 'FFFFFF';
	tag.write(document);
	getDragDropData = true;
}

function setupCarChoice(str_FlashVars) {
	var uid = new Date().getTime();
	flashProxy = new FlashProxy(uid, 'JavaScriptFlashGateway.swf');
	var tag = new FlashTag('carChoice.swf', 600, 320,"xmlFile",str_FlashVars); // last two arguments are height and width
	tag.setFlashvars('lcId='+uid);
	tag.bgcolor = 'FFFFFF';
	tag.write(document);
}

function getValues() {
    
	flashProxy.call('getDataValues');
}

function getValuesReturn(value) {
	//data will be returned like so
	//qa_qa=2,ab_qb=3

	//parse the returned data and save it into the hidden form fields
	var arr_Pairs;
	var arr_values;

	arr_Pairs = value.split(",");

	for(var n=0;n < arr_Pairs.length - 1;n++) {
		arr_values = arr_Pairs[n].split('=');
		document.getElementById(arr_values[0]).value = arr_values[1];
	}
    
    // submit the form 
    document.frmCheckMe.submit();

}

function hideOtherBox() {
    if (document.getElementById("x_other"))
		{
		 document.getElementById("x_other").style.visibility = "hidden";
		 document.getElementById("x_other").style.position = "absolute";
		}
}

// This function sets the value of a hidden text box it is used for !Q
function setHidden(fieldName,stringValue) {

    var element = document.getElementById(fieldName);
    element.value = stringValue;
}