﻿// JScript File
function showhide(obj)
{
    if(document.getElementById(obj) != null) {
    if(document.getElementById(obj).style.display == 'none')
    {
        show(obj);
    }
    else
    {
        hide(obj);
    }
    }
    return false;
}
function hide(obj) 
{
    document.getElementById(obj).style.display = 'none';
    document.getElementById(obj).style.visibility = 'hidden';
}
function show(obj) 
{
    document.getElementById(obj).style.display = '';
    document.getElementById(obj).style.visibility = 'visible';
}

function setEnabled(obj,value) 
{
    if(document.getElementById(obj) != null) {
    if(value == false)
    {
    document.getElementById(obj).disabled = 'disabled';
    }
    else
    {
    document.getElementById(obj).disabled = '';
    }
    }
    return false;
}


function showNextTo(obj, nextto)
{
    objj = document.getElementById(obj);
    if(objj != null)
    {
        objj.style.display = 'block';
        objj.style.visibility = 'visible';
        objj.style.position = 'absolute';
        objj.Y = findY(nextto);
        objj.X = findX(nextto);
    }
}

function findX(obj) {
var x = 0;
while (obj) {
x += obj.offsetLeft
obj = obj.offsetParent;
}
//alert(x);
return x;
}
function findY(obj) {
var y = 0;
while (obj) {
y += obj.offsetTop
obj = obj.offsetParent;
}
//alert(y);
return y;
}



function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	
	if (typeof window.innerHeight != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		window_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			window_height = document.body.parentNode.clientHeight;
		} else {
			window_height = document.body.parentNode.scrollHeight;
		}
	}

	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-300;
	popUpDiv.style.left = window_width + 'px';
	popUpDiv.style.top = '150px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

