
// Start of functions used by new QS/1 search
function trim(value)
{
  s = new String(value);
  if (value != null) {
    var beginIndex = -1;
    var endIndex   = s.length;

    for (var i = 0; i < s.length; i++)
    {
      if (s.charAt(i) != " ") {
        beginIndex = i;
        break;
      }
    }
    if (beginIndex == -1) return "";

    for (var j = s.length -1; j > beginIndex; j--) {
      if (s.charAt(j) != " ") {
        endIndex = j;
        break;
      }
    }
    if (endIndex != s.length) return s.substring(beginIndex, endIndex);
    else return s.charAt(beginIndex);
  }
  return value;
}

function isNotNull(value)
{
  if (value == null || trim(value).length == 0 || value == "search site"  )
  {
    alert('Please enter the keyword(s) to search for.');
    return false;
  }
  else
    return true;
}  

function checkSearch( value )
{
  if ( document.searchForm && document.searchForm.datasetId && typeof( langDataSetId ) != 'undefined' && langDataSetId )
  {
    document.searchForm.datasetId.value = langDataSetId;
  }

  if ( value == null || trim(value).length == 0 )
  {
    alert('Please enter the keyword(s) to search for');
    return false;
  }
  else 
  {
    if ( document.searchForm ) document.searchForm.submit();
    return true;
  }
}

function checkGlobalSearch( value )
{
  return checkSearch( value );
}


function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
document.getElementById("products").style.display="none"
document.getElementById("services").style.display="none"
document.getElementById("market_solutions").style.display="none"
document.getElementById("support").style.display="none"
document.getElementById("company").style.display="none"
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 
//Do not delete these comments. 
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
//Attribution required on all accounts 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}


// NRx video programming script

var openedWin = null;
var wpercent = 100;

function launch(){
	var args = launch.arguments
	var url = args[0]
	var width = args[1]
	var height = args[2]
	
	if (!url || !width || !height) {
		alert("Error");
	} else {
		var scr_w = screen.availWidth
		var scr_h = screen.availHeight
		var target_w = 0
		var target_h = 0
		wpercent = 100

		if(width >= scr_w || height >= scr_h){
			if((width+8) >= (height+27)){
				target_w = scr_w - 8	//target width is screen width - 8
				wpercent = Math.floor((target_w * 100)/width) //get percentage scaled down
				target_h = Math.floor((height * wpercent)/100) - 27 //scale height to  percentage then subtract standard title bar height
				wpercent = Math.floor((target_h * 100)/height)	//re-adjust percentage
				target_w = Math.floor((width * wpercent)/100)	//scale width to new percentage
				width = target_w
				height = target_h
			}else if((height+27) > (width+8)){
				target_h = scr_h - 27
				wpercent = Math.floor((target_h * 100)/height)
				target_w = Math.floor((width * wpercent)/100) - 8
				wpercent = Math.floor((target_w * 100)/width)
				target_h = Math.floor((height * wpercent)/100)
				width = target_w
				height = target_h
			}
		}
		_launch(url, width, height, args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
	}
}

function _launch(){
	closeChild()
	
	var args = _launch.arguments
	var url = args[0]
	var width = args[1]
	var height = args[2]
	var resizable = args[3] ? "yes" : "no"
	var scrollbars = args[4] ? "yes" : "no"
	var toolbar = args[5] ? "yes" : "no"
	var menubar = args[6] ? "yes" : "no"
	var status = args[7] ? "yes" : "no"
	var address = args[8] ? "yes" : "no"
	var directories = args[9] ? "yes" : "no"
	
	var NewX = Math.max(0, Math.floor((screen.availWidth-(width+8))/2));
	var NewY = Math.max(0, Math.floor((screen.availHeight-(height+27))/2));
	
	var params = ''
	
	params += "width="+width // 1
	params += ",height="+height // 2
	params += ",screenx="+NewX
	params += ",screeny="+NewY
	params += ",left="+NewX
	params += ",top="+NewY
	params += ",resizable="+resizable // 3
	params += ",scrollbars="+scrollbars // 4
	params += ",toolbar="+toolbar // 5
	params += ",menubar="+menubar // 6
	params += ",status="+status // 7
	params += ",location="+address // 8
	params += ",directories="+directories // 9
	
	openedWin = window.open(url, "demodashboard", params);
}

function closeChild () {
	if (openedWin != null) {
		if (!openedWin.closed) {
			openedWin.close();
		}
	}
}
onunload = closeChild;