﻿
function Debug(str) {
    var DebugConsoleID = "debugconsole";
    var DebugConsole = getElement(DebugConsoleID);
    var iframe = getElement("iframe");
    if (!DebugConsole) {
        DebugConsole = document.createElement('textarea');
        DebugConsole.setAttribute('id', DebugConsoleID);
        DebugConsole.setAttribute('style', 'width:98%;height:400px;margin:5px;');
        DebugConsole.innerHTML = 'console created\n';
        if (iframe) {
            iframe.appendChild(DebugConsole);
        }
        else {
            document.body.appendChild(DebugConsole);
        }
    }
    if (DebugConsole) {
        DebugConsole.innerHTML += str + '\n';
        DebugConsole.scrollTop = DebugConsole.scrollHeight;
    }
    else {
        alert(str);
    }
}

// --------- site search -------------- //

var keywords;
var keywordobj;

function KeywordBlur(myobj){
	if (keywordobj) {
	    keywordobj = myobj;
	    keywords = keywordobj.value;
	    keywordobj.value = "";
	}
}
function KeywordRestore(){
	if (keywordobj) {
    	keywordobj.value = keywords;
	}
}

// ------------------------------------- //

// --------- common functions --------- //

function getInternetExplorerVersion() {

	var rv = -1; // Return value assumes failure.

	if (navigator.appName == 'Microsoft Internet Explorer') {

		var ua = navigator.userAgent;

		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

		if (re.exec(ua) != null)

			rv = parseFloat(RegExp.$1);

	}

	return rv;

}

function getWindowWidth() {
	var WindowWidth;

	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		WindowWidth = window.innerWidth;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		WindowWidth = document.documentElement.clientWidth;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		WindowWidth = document.body.clientWidth;
	}
	return WindowWidth;
}

function getWindowHeight() {
	var WindowHeight;

	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		WindowHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		WindowHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		WindowHeight = document.body.clientHeight;
	}
	return WindowHeight;
}

function getScrollTop() {
	var ScrollTop = 0;
	if (window.pageYOffset) {
		ScrollTop = window.pageYOffset;
	}
	else if (document.body.scrollTop) {
		ScrollTop = document.body.scrollTop;
	}
	else if (document.documentElement.scrollTop) {
		ScrollTop = document.documentElement.scrollTop;
	}
	if (ScrollTop != "") {
		ScrollTop = parseFloat(ScrollTop);
	}
	else {
		ScrollTop = 0;
	}
	return ScrollTop;
}

function getElement(name) {
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	return o1;
}
function showElement(name,displaytype) {
	if(displaytype==undefined){displaytype='';}
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	if(o1!=null) {
		o1.style.display = displaytype;
	}
}
function hideElement(name) {
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	if(o1!=null) {
		o1.style.display = "none";
	}
}
function toggleElement(name,displaytype){
	if(displaytype==undefined){displaytype='';}
	if(getElement(name) != null){
		if(getElement(name).style.display == displaytype || getElement(name).style.display == ""){
			hideElement(name);
		}
		else{
			showElement(name,displaytype);
		}
	}
}



function ClearSearchBox(FormItem)
{

	if(document.all){
		if(document.all(FormItem).value == " Enter first or last name"){
			document.all(FormItem).value="";
		}
	}
	else{
		if(document.getElementById(FormItem).value == " Enter first or last name"){
			document.getElementById(FormItem).value="";
		}
	}
	
}

function FillSearchBox(FormItem)
{
	if(document.all){
		if(document.all(FormItem).value == ""){
			document.all(FormItem).value=" Enter first or last name";
		}
	}
	else{
		if(document.getElementById(FormItem).value == ""){
		    document.getElementById(FormItem).value=" Enter first or last name";
			document.getElementById(FormItem).style.color="#ABABAB";
		}
	}
}


function center(element){

	var o = null;

	if(document.all) { o = document.all(element); }
	else if(document.getElementById) { o = document.getElementById(element); }


    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    o.style.position = 'absolute';
    o.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = getDimensions(element);

    var setX = ( my_width  - elementDimensions[0]  ) / 2;
    var setY = ( my_height - elementDimensions[1] ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    o.style.left = setX + "px";
    o.style.top  = setY + "px";

    o.style.display  = 'block';
}

function getDimensions(element) {

	var dimensionArr = new Array;

	var o = null;

	if(document.all) { o = document.all(element); }
	else if(document.getElementById) { o = document.getElementById(element); }


	if (o.style.display!='none') {
		dimensionArr[0] = o.offsetWidth;
		dimensionArr[1] = o.offsetHeight;
		return dimensionArr;
	}

	// All *Width and *Height properties give 0 on elements with display none,
	// so enable the element temporarily
	var els = o.style;
	var originalVisibility = els.visibility;
	var originalPosition = els.position;
	els.visibility = 'hidden';
	els.position = 'absolute';
	els.display = '';
	var originalWidth = o.clientWidth;
	var originalHeight = o.clientHeight;
	els.display = 'none';
	els.position = originalPosition;
	els.visibility = originalVisibility;

	dimensionArr[0] = originalWidth;
	dimensionArr[1] = originalHeight;
	return dimensionArr;
  }
