// JavaScript Document
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.01
  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 && d.getElementById) x=d.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_openBrWindow(window_page, window_width, window_height) { //v2.0

	var screenleft = (screen.width/2) - (window_width/2);
	var screentop = (screen.height/2) - (window_height/2);
	var windowstr = 'width=' + window_width + ',height=' + window_height + ',left=' + screenleft + ',top=' + screentop + ',screenX=0,screenY=0,scrollbars=no';
	var windowpagestr = window_page + '.htm'
	
	window.open(windowpagestr,'samplewindow',windowstr);
	  
}

document.getElementsByClassName = function (needle)
{
  var         my_array = document.getElementsByTagName("*");
  var         retvalue = new Array();
  var        i;
  var        j;

  for (i = 0, j = 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}

// ADD METHODS TO CLASSES
Array.prototype.removeItems = function(itemsToRemove) {
	var j;
	for (var i = 0; i < itemsToRemove.length; i++) {
		j = 0;
		while (j < this.length) {
			if (this[j] == itemsToRemove[i]) {
				this.splice(j, 1);
			} else {
				j++;
			}
		}
	}
}

function popUp(url,w,h,scrol){
	if(!scrol){
		scrol = 'auto';
	}
	window.open(url,'','toolbar=0,scrollbars='+scrol+',location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h+',left='+Math.round((window.screen.width/2)-(w/2))+',top='+Math.round((window.screen.height/2)-(h/2)));
}

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function walkSelection(element,arr,limit){
	//alert(element+' | '+arr+' | '+limit);
	if(element.checked==false){
		arr.removeItems(new Array(element.id));
		for(i=0; i<arr.length; i++){
			document.getElementById(arr[i]).checked=true;
		}
	}
	
	if(element.checked==true){
		arr.push(element.id);
		if(arr.length>limit){
			uncheck = arr.shift();
			document.getElementById(uncheck).checked=false;
		}
	}
	
}

function setHdcpVals(target,minmax){
	obj = eval(target+'_lastHdcpVals');
	if(minmax=='min'){
		index = 0;
	}
	if(minmax=='max'){
		index = 1;
	}
	obj[index] = document.getElementById(target+'_hdcp_'+minmax).selectedIndex;
}

function toggleHDCP(target,set){
	obj = eval(target+'_lastHdcpVals');
	if(set==1){
		document.getElementById(target+'_hdcp_min').disabled = false;
		document.getElementById(target+'_hdcp_max').disabled = false;
		document.getElementById(target+'_hdcp_min').selectedIndex = obj[0];
		document.getElementById(target+'_hdcp_max').selectedIndex = obj[1];
	}
	if(set==0){
		document.getElementById(target+'_hdcp_min').disabled = true;
		document.getElementById(target+'_hdcp_max').disabled = true;
		document.getElementById(target+'_hdcp_min').selectedIndex = 0;
		document.getElementById(target+'_hdcp_max').selectedIndex = 0;
	}
}

function disableSelections(vals){
	vals = vals.split(',');
	for(i=0; i<vals.length; i++){
		document.getElementById(vals[i]).disabled=true;
	}
}

function enableSelections(vals){
	vals = vals.split(',');
	for(i=0; i<vals.length; i++){
		document.getElementById(vals[i]).disabled=false;
	}
}

function clearSelections(vals){
	vals = vals.split(',');
	for(i=0; i<vals.length; i++){
		document.getElementById(vals[i]).checked=false;
	}
}

function eval_phone(p,f,m){
	if(p != ''){
		v = new Array('0','1','2','3','4','5','6','7','8','9');
		t = '';
		for(i=0; i<p.length; i++){
			for(j=0; j<v.length; j++){
				if(p.charAt(i) == v[j]){				
					t += p.charAt(i);
					j = v.length;
				}
			}
		}
		if(t.length != 10){
			//document.getElementById(f).focus();
			//document.getElementById(f).select();
			alert(m);
		}else{
			document.getElementById(f).value = '('+t.substr(0,3)+')'+t.substr(3,3)+'-'+t.substr(6,4);
		}
	}
}

function HelpHover()
{
	this._mousePosX = 0;
	this._mousePosY = 0;
	this._hoverItem = null;
	this._hoverContents = null;
}

HelpHover.prototype.init = function()
{
	var hh = this;
	var helpItems = document.getElementsByClassName('hasHelp');
	for (var i=0; i<helpItems.length; i++)
	{
		helpItems[i].onmousemove = function(e)
		{
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
				hh.mousePosX = e.pageX;
				hh.mousePosY = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				hh.mousePosX = e.clientX;
				hh.mousePosY = e.clientY;
			}
			hh._hoverItem = this;
			hh._hoverContents = document.getElementById(this.id+'Help');
			hh.move();
		}
		helpItems[i].onmouseout = function (e)
		{
			hh.out();
		}
	}
}

HelpHover.prototype.out = function()
{
	this._hoverContents.style.top = -10000+'px';
	this._hoverContents.style.left = -10000+'px';
	this._hoverItem = null;
	this._hoverContents = null;
}

HelpHover.prototype.move = function()
{
	this._hoverContents.style.top = this.mousePosY+'px';
	this._hoverContents.style.left = this.mousePosX+'px';
	
	float_xpos = parseFloat(this._hoverContents.style.top);
	float_height  = this._hoverContents.offsetHeight;
	float_width  = 600;
	
	var scrOfX = 0, scrOfY = 0;
	var myWidth = 0, myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
  
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
		
	this._hoverContents.style.top = Math.round((scrOfY+(myHeight/3))-(float_height/3))+'px';
	this._hoverContents.style.left = 180+'px';
	
}

addEvent(window, 'load', function()
{
	var hh = new HelpHover();
	hh.init();
});