﻿function Gid( xid ) { 
	var xo = document.getElementById( xid );
	if ( xo != undefined ) {
		if ( xo.id != xid ){
			var axo = document.getElementsByName( xid ); 
			for (var i=0; i != axo.length; i++ ){
//				alert ( axo[i].id +"::"+ xid  )
				if ( axo[i].id == xid ) {
					xo = axo[i];
				}
			}		
		}
	}
	return xo; 	
}

function GetVal( xid ) { 
	var xo = Gid( xid ) ;
	if ( xo != undefined ) 
		return xo.value; 
	else 
		return ""; }

function KReplace(inString,oldText,newText) {
	return (inString.split(oldText).join(newText));
}

function ShowProfile (xwhat, id, img) {
  var profile = document.getElementById( xwhat +"_"+ id);
  if (profile.style.visibility == "visible") {
    return;
  }

  var bigImg = document.getElementById( xwhat + "_q_" + id );
  bigImg.src = img.getAttribute("src").replace("/s/", "/m/");
  bigImg.height = img.height*2; 

  var x = this.GetX(img);
  var y = this.GetY(img);

  var browserWidth = document.body.clientWidth;
  var browserHeight = document.body.clientHeight;

  if (x + img.width + profile.clientWidth > browserWidth) {
    profile.style.left = x - 5 - profile.clientWidth;
  } else {
    profile.style.left = x + 5 + img.width;
  }

  var totalHeight = browserHeight + GetScrollHeight();
  if (y + profile.clientHeight > totalHeight) 
    profile.style.top = totalHeight - 5 - profile.clientHeight;
  else 
	profile.style.top = y;
  
  profile.style.visibility = "visible";
}

function HideProfile (xwhat, id) {
  document.getElementById(xwhat+ "_"+ id).style.visibility = "hidden";
}


function GetScrollHeight () {
  // firefox
  if (typeof(window.pageYOffset) == "number") {
    return window.pageYOffset;
  }
  // IE
  else if (document.body &&
    (document.body.scrollLeft || document.body.scrollTop)) {
    return document.body.scrollTop;
  }
}

function GetX (node) {
  if (node.offsetParent) {
    for (var x = 0; node.offsetParent; node = node.offsetParent) {
      x += node.offsetLeft;
    }
    return x;
  }
  return node.x;
}

function GetY (node) {
  if (node.offsetParent) {
    for (var y=0; node.offsetParent; node=node.offsetParent) {
      y += node.offsetTop;
    }
    return y;
  }
  return node.y;
}



function PersonSetInterviewPanel ( xsPanel, xsLang )
{
	document.getElementById( "tblPerson" ).style.display = "none";
	document.getElementById( "tblPersonProfessional" ).style.display = "none";
	document.getElementById( "tblPersonPersonal" ).style.display = "none";
	document.getElementById( "imgPersonTabButton").src = xsLang +"/design/person/Person_tab.jpg"; 
	document.getElementById( "imgPersonProfessionalTabButton").src = xsLang +"/design/person/PersonProfessional_tab.jpg"; 
	document.getElementById( "imgPersonPersonalTabButton").src = xsLang +"/design/person/PersonPersonal_tab.jpg"; 

	document.getElementById( "tbl"+ xsPanel  ).style.display = "block";	
	document.getElementById( "img"+ xsPanel +"TabButton").src = xsLang +"/design/person/"+ xsPanel +"_tab_act.jpg"; 
}

var ForceInterval;
function Force( command, millisec){
	ForceInterval = window.setInterval(command, 50); 
	window.setTimeout("window.clearInterval(ForceInterval)", millisec);
}




var agent = navigator.userAgent.toLowerCase();
var isIe = (agent.indexOf('msie') != -1);
var isIe5 = (agent.indexOf('msie 5') != -1);


function createXmlHttpReq(handler) {
  var xmlhttp = null;
  if (isIe) {
    var control = (isIe5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    try {
      xmlhttp = new ActiveXObject(control);
      xmlhttp.onreadystatechange = handler;
    } catch (e) {
    }
  } else {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  }
  return xmlhttp;
}

function xmlHttpGET(xmlhttp, url) {
  xmlhttp.open('GET', url, true);
  xmlhttp.send(null) ;
  alert( xmlhttp.status ) ;
}

var xTime = (new Date).getTime();
function SendRequest( xsUrl ) {
  var xmlhttp = createXmlHttpReq( function() {});
  ++ xTime;
  xmlHttpGET(xmlhttp, xsUrl  + "&rand=" + xTime);
}

function GetPressedKey ( src ) {
	return (window.event ? src.keyCode : src.which);
}


function sortNumbers(a, b) { 
	return a - b;
}

	function IsNull ( FirstValue, SecondValue ) {
		if ( FirstValue.length > 0 )
			return FirstValue;
		else 
			return SecondValue;
	}
	function IfFirstAddSecond ( FirstValue, SecondValue ) {
		if ( FirstValue.length > 0 )
			return FirstValue + SecondValue;
		else 
			return FirstValue;
	}

function PopUp ( xsUrl, xiWidth, xiHeight ) {
	window.open ( xsUrl, "popup", "channelmode=no,directories=no,fullscreen=no,height="+ xiHeight 
		+"location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,width="+ xiWidth );
}





function SetMaxLength ( oTxt )
{
	if ( oTxt.value.length > oTxt.getAttribute("maxlength") )
		oTxt.value = oTxt.value.substr( 0, oTxt.getAttribute("maxlength") );
}



// used from ArticleView.ascx & Topic.aspx
function CommunityForumFormSubmit( sQueryString )
{
	bFormIsValid = true;
	for( i=0; i!=CommunityForumForm.elements.length; i++ )
		if ( CommunityForumForm.elements[i].name.substr(0,4) == "req_")
			if ( CommunityForumForm.elements[i].value.length == 0) {
				document.getElementById("err_"+ CommunityForumForm.elements[i].name ).style.display = "inline";
				bFormIsValid = false;
				}
			else 
				document.getElementById("err_"+ CommunityForumForm.elements[i].name ).style.display = "none";

	if ( bFormIsValid ) {
		document.getElementById( "kQueryString" ).value = sQueryString;
		document.getElementById( "CommunityForumForm" ).submit(); 
	}
}

