// JavaScript Document
// 


/*
// Roll Over Images
*/

function initRollOvers() {
	
	var image_cache = new Object();
	
	$("img.swap").each( function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
	
}



/*
// New Window
*/

function initNewWindow() {
	
	var popupEvent = function(event) {
		if( this.rel ) {
			window.open(this.href, 'popup', this.rel).focus();
		} else {
			window.open(this.href, '_blank').focus();
		}
		event.preventDefault();
		event.stopPropagation();
	}
	
	$("a.popup").each(function(i) {
		$(this).click(popupEvent);
		$(this).keypress(popupEvent);
	});
	
}

$(document).ready( function(){
	$(initNewWindow);
	$(initRollOvers);
})








// Hide Box Global
function viewBoxGlobal(dt,img,boxid) {
	dt.style.display = "block";
	if (img) {
		img.src = '../common/img/g_nav' + boxid + '_ac.jpg';
	}
}
function hideBoxGlobal(dt,img,boxid) {
	dt.style.display = "none";
	if (img) {
		img.src = '../common/img/g_nav' + boxid + '_plus.jpg';
	}
}
function showListGlobal(boxid) {
	var gref = "";
	var gimg = "";
	var docref = "";
	var docimg = "";

	gref = "gref_" + boxid;
	gimg = "gimg_" + boxid;
	docref = document.getElementById(gref);
	docimg = document.getElementById(gimg);
	if (docref.style.display == 'none' || docref.style.display == '') {
		viewBoxGlobal(docref,docimg,boxid);
	} else {
		hideBoxGlobal(docref,docimg,boxid);
	}
}

function centerWindow(wx,wy,file) {
	x = (screen.width  - wx) / 2;
	y = (screen.height - wy) / 2;
	subWin = window.open( file, "sub", "left="+x+", top="+y+", width="+wx+", height="+wy );
}







// Hide Box
function viewBox(dt,img,boxid) {
	dt.style.display = "block";
	if (img) {
		img.src = 'img/s_menu_' + boxid + '_ac.gif';
	}
}
function hideBox(dt,img,boxid) {
	dt.style.display = "none";
	if (img) {
		img.src = 'img/s_menu_' + boxid + '.gif';
	}
}
function showList(boxid) {
	var ref = "";
	var img = "";
	var docref = "";
	var docimg = "";

	ref = "ref_" + boxid;
	img = "img_" + boxid;
	docref = document.getElementById(ref);
	docimg = document.getElementById(img);
	if (docref.style.display == 'none' || docref.style.display == '') {
		viewBox(docref,docimg,boxid);
	} else {
		hideBox(docref,docimg,boxid);
	}
}

function centerWindow(wx,wy,file) {
	x = (screen.width  - wx) / 2;
	y = (screen.height - wy) / 2;
	subWin = window.open( file, "sub", "left="+x+", top="+y+", width="+wx+", height="+wy );
}





// Hide Box sec
function viewBoxSec(dt,img,boxid) {
	dt.style.display = "block";
	if (img) {
		img.src = '../img/s_menu_' + boxid + '_ac.gif';
	}
}
function hideBoxSec(dt,img,boxid) {
	dt.style.display = "none";
	if (img) {
		img.src = '../img/s_menu_' + boxid + '.gif';
	}
}
function showListSec(boxid) {
	var ref = "";
	var img = "";
	var docref = "";
	var docimg = "";

	ref = "ref_" + boxid;
	img = "img_" + boxid;
	docref = document.getElementById(ref);
	docimg = document.getElementById(img);
	if (docref.style.display == 'none' || docref.style.display == '') {
		viewBoxSec(docref,docimg,boxid);
	} else {
		hideBoxSec(docref,docimg,boxid);
	}
}

function centerWindow(wx,wy,file) {
	x = (screen.width  - wx) / 2;
	y = (screen.height - wy) / 2;
	subWin = window.open( file, "sub", "left="+x+", top="+y+", width="+wx+", height="+wy );
}












// Write Cookie
function setCookie(nam, val, exp){
	if(nam && val && exp){
		var d = new Date();
		d.setTime(d.getTime() + (exp * 1000 * 60 * 60 * 24));
		exp = d.toGMTString();
		document.cookie = nam + "=" + escape(val) + ";expires=" + exp;
		return true;
	}
	
	return false;
}




// Read Cookie
function getCookie(nam){
	nam += "=";
	var c = document.cookie + ";";
	var s = c.indexOf(nam);
	if(s != -1){
		var e = c.indexOf(";", s);
		return unescape(c.substring(s + nam.length, e));
	}
	
	return false;
}


// Read Cookie
function MaxWin(url){
	maxWin = window.open(url,"","toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes");
	maxWin.moveTo(0,0);
	maxWin.resizeTo(screen.availWidth,screen.availHeight);
}

function chgPage(url){
	location.href = url;
}

