function layoutUpdate() {
    var h1 = document.getElementById("left_banner").offsetHeight;
    var h2 = document.getElementById("main_content").offsetHeight;
    var h3 = document.getElementById("right_banner").offsetHeight;
    h2 += 15;
    h3 += 15;
    var h = h1;
    if(h2 > h) h = h2;
    if(h3 > h) h = h3;
    document.getElementById("wrap").style.height = (h+194) + 'px';
}

/*
window.onload = function() {
     layoutUpdate();
}
*/

function openUrl(url){
    
   // document.getElementById("top_banner_iframe").style.left = (screen.width - 800)/2 + 'px';
    document.getElementById("menu_nav").style.display = "none";
    document.getElementById("middle_banner").style.display = "none";
    document.getElementById("left_banner").style.display = "none";
    document.getElementById("main_content").style.display = "none";
    document.getElementById("right_banner").style.display = "none";
    document.getElementById("footer").style.display = "none";
    
    document.getElementById("wrap").style.display = "none";
    //document.getElementById("top_banner_txt").style.display = "none";
        
    document.getElementById("iframeDiv").style.display = "block";
    document.getElementById("top_banner_txt_iframe").style.display = "block";
    document.getElementById("top_banner_iframe").style.display = "block";

    document.getElementById("infrm").width = screen.width-4;
    //document.getElementById("infrm").height = screen.height+58;
    //document.getElementById("infrm").height = screen.height-229;
    
    var tmpPageHeight=getPageSize();
    document.getElementById("infrm").height =tmpPageHeight-document.getElementById("top_banner_iframe").offsetHeight-16;

    infrm.location = url; 
    
    return false;
}

function backToMytest(){
    document.getElementById("menu_nav").style.display = "block";
    document.getElementById("middle_banner").style.display = "block";
    document.getElementById("left_banner").style.display = "block";
    document.getElementById("main_content").style.display = "block";
    document.getElementById("right_banner").style.display = "block";
    document.getElementById("footer").style.display = "block";
    
    document.getElementById("wrap").style.display = "block";
    
    document.getElementById("top_banner_txt_iframe").style.display = "none";
    document.getElementById("top_banner_iframe").style.display = "none";
   // document.getElementById("top_banner_txt").style.display = "none";
    document.getElementById("iframeDiv").style.display = "none";
    
    return false;
}

function getAbsPos(obj) {
	var param = [];
	
	if (! obj || ! obj.offsetParent){
		return param;
	}
	
	param[0]   = obj.offsetLeft;
	param[1]    = obj.offsetTop;
	var objParent = obj.offsetParent;

	while (objParent.tagName.toUpperCase() != "BODY" && objParent.tagName.toUpperCase() != "HTML"){
		param[0] += objParent.offsetLeft;
		param[1] += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}
	return param;
}
function getChildByClassName(srcObj, name){
    for(var i=0; i < srcObj.childNodes.length; i++){
        if(srcObj.childNodes[i].className == name){
            return srcObj.childNodes[i];
        }
    }
    return null;
}

function showButton(id, colorId){
    return;
    var srcObj = document.getElementById(id);
    if(!srcObj) return;
    var color="yellow";
    switch (colorId)
        {
            case 0:
            case 1:
                color = "green";
                break;
            case 2:
                color = "purple";
                break;
            case 3:
                color = "blue";
                break;
            case 4:
                color = "red";
                break;
            case 5:
                color = "orange";
                break;
        }

    
    var wrap = document.getElementById("wrap");
    var srcPos = getAbsPos(srcObj);
    var parentPos = getAbsPos(wrap);
	var xx = srcPos[0] - parentPos[0];
	var yy = srcPos[1] - parentPos[1];
	var label = getChildByClassName(srcObj, 'middle_part2').innerHTML;
	
	var div = document.createElement('div');
    div.style.zIndex = 97;
    div.style.position = "absolute";
    div.style.top = yy + 'px';
    div.style.left = xx + 'px';
    
    var strHtml="";
    
    strHtml +="<div class=btnCell>";
    strHtml +="<img src=images/buttons/but_" + color + "_left.gif border=0 alt=''/>";
    strHtml +="</div>";
    strHtml +="<div class=middle_part style=background-image:url(images/buttons/but_" + color + "_1pix.gif)>" + label + "</div>";
    strHtml +="<div class=btnCell>";
    strHtml +="<img src=images/buttons/but_" + color + "_right.gif border=0 alt=''/>";
    strHtml +="</div>";
    
    div.innerHTML = strHtml;
    wrap.appendChild(div);
    
    var linkObj = srcObj.cloneNode(true);
    if(document.all){
        for(var i=0; i < linkObj.childNodes.length; i++){
            linkObj.removeChild(linkObj.childNodes[i]);
        }
        linkObj.innerHTML = '<img  src="images/transparent.png" width="' + div.offsetWidth + '" height="22" border="0" alt="" />';
    }
    linkObj.style.zIndex = 98;
    linkObj.style.position = "absolute";
    linkObj.style.top = yy + 'px';
    linkObj.style.left = xx + 'px';
    wrap.appendChild(linkObj);
}

function buildDropList(id, base_text, base_value, value_sel){
    var objSel = document.getElementById(id);
    objSel.options.length=base_text.length;
	selindex=0;
	for (loop=0; loop < base_text.length; loop++)
	{
		objSel.options[loop].text=base_text[loop];
		objSel.options[loop].value=base_value[loop];
		if(base_value[loop]==value_sel)selindex=loop;
	}
	objSel.selectedIndex=selindex;
}

function buildCheckList(id, base_text, base_value, value_sel){
    var objSel = document.getElementById("div" + id); 
	var strHtml = "";
	
	if(objSel!= null){
	    //build checkbox list
	    strHtml = "<table cellspacing='0' cellpadding='0' border='0'>";
	    for (loop=0; loop < base_text.length; loop++)
	    {
	        strHtml += "<tr><td>";
		    strHtml += "<input type=\"checkbox\" id=\"chk" + base_value[loop] + "\" name=\"chk" + base_value[loop] 
		        + "\" value=\"" + base_text[loop] + "\" onclick=\"selectTest('" + id + "', " + base_value[loop] + ", " + value_sel + ")\" />"; 
		    strHtml += " <span>" + base_text[loop] + "</span>"
		    strHtml += "</td></tr>";
	    }
	    strHtml += "</table>";
	    objSel.innerHTML = strHtml;
	}
}

function selectTest(id, value, selectable){
    var objSel = document.getElementById(id); 
    var strTest = "";
    var numberArr = "";
    var chkBox = document.getElementById("chk" + value);
    var validlist = "false";
    
    if (objSel!= ""){
        //check if number selected exceed allowed - done on submit
        /*if(objSel.value!=""){
            strTest = objSel.value;
            numberArr = strTest.split(",");
            if(numberArr.length<=selectable){
                validlist = "true";
            }            
        }*/
        
        //if(validlist){
            if(chkBox.checked){
                //add test id to list
                if(objSel.value==""){
                    strTest = value;
                }
                else {
                    strTest = objSel.value + "," + value;
                }
            }        
            else {
                //remove test id from list
                if(objSel.value!=""){
                    strTest = objSel.value;
                    if(strTest.match("," + value)!=null){
				        strTest = strTest.replace("," + value, "");
			        }
			        else if(strTest.match(value + ",")!=null){
				        strTest = strTest.replace(value + ",", "");
			        }
			        else if(strTest.match(value)!=null){
				        strTest = strTest.replace(value, "");			
			        }
                }
            }
        //}
        //else {
        //    alert('invalid list');
        //}
    }    
    objSel.value = strTest;
}

function getPageSize(){  
  var xScroll, yScroll;  
  if (window.innerHeight && window.scrollMaxY) {  
    //xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
   // xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    //xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {  // all except Explorer
    //windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    //windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    //windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }  
  
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }
  //if(xScroll < windowWidth){  
    //pageWidth = windowWidth;
  //} else {
   // pageWidth = xScroll;
  //}

  //arrayPageSize = new Array(pageWidth,pageHeight)
  return pageHeight;
}



function CreateHTTP() {
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest!='undefined')
    xmlhttp = new XMLHttpRequest();
  return xmlhttp;
}

function HTTPGet(uri, callback_function, callback_parameter) {
  var xmlhttp = CreateHTTP();
  var bAsync = true;
  if (!callback_function)
    bAsync = false;
  xmlhttp.open('GET', uri, bAsync);
  xmlhttp.send(null);

  if (bAsync) {
    if (callback_function)
      xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
			
          callback_function(xmlhttp.responseText, xmlhttp, callback_parameter);
		}
      }
    return true;
  } else
    return xmlhttp.responseText;
}