function setCookie(name, value, expire)
{
  document.cookie
    = name + "=" + escape(value)
    + ((expire==null)?"":("; expires="+expire.toGMTString()));
}

function getCookie(Name)
{
	var search = Name + "=";
	if (document.cookie.length > 0)
	{ // if there are any cookies
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ // if cookie exists 
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset) ;
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return "";
}
// Login box---------------------------------------------------
function funcSubLogin(){
	var arrayPageSize = getPageSize();
	$("overlay").style.height = arrayPageSize[1]+"px"
	$("overlay").style.display = "block";
	$("overlay").onclick = function(){
		registboxClose();
	}
	$("registbox").style.top = ((parseInt(arrayPageSize[3])/2)-150)+"px"
	$("registbox").style.display = "block";
	InitPage();
}
function registboxClose(){
	$("overlay").style.display = "none";
	$("registbox").style.display = "none";
}

// ---------------------------------------------------
function calcImgSize(imgWidth,imgHeight,screenWidth,screenHeight){
	var fScaleX;
	var fScaleY;
	var fScale;
	var tWidth;
	var tHeight;
	imgWidth = parseInt(imgWidth);
	imgHeight = parseInt(imgHeight);
	screenWidth = parseInt(screenWidth);
	screenHeight = parseInt(screenHeight);
	
	if(screenWidth < imgWidth || screenHeight < imgHeight){
		fScaleX = (screenWidth + 1) / imgWidth;
		fScaleY = (screenHeight + 1) / imgHeight;
		if(fScaleX > fScaleY){
			fScale = fScaleY;
		}else{
			fScale = fScaleX;
		}
		tWidth = parseInt(imgWidth * fScale);
		tHeight = parseInt(imgHeight * fScale);
		if(tWidth > screenWidth){
			tWidth = screenWidth;
		}
		if(tHeight > screenHeight){
			tHeight = screenHeight;
		}
	}else{
		tWidth = imgWidth;
		tHeight = imgHeight;
	}
	arrayImgSize = new Array(tWidth,tHeight);
	return arrayImgSize;
}
// ---------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll);
	return arrayPageScroll;
}


//whats new
function whatsnew(date) {
	var pic = "images/front/ver2/new_mrk.gif";
	expdate = new Date(date);
	curdate = new Date();
	if (expdate.getTime() > curdate.getTime())
	document.write("<img src=" + pic + " align=absmiddle />");
}

//Cover
function initpreonload(){
	//cover
	chkfrontcover();
}
function chkfrontcover(){
	var frontcover = getCookie("front-cover");
	if(frontcover == "on"){
		$("front-wrapper").style.display="none";
	}else{
		setWrapperSize();
		$("front-wrapper").style.display="block";
	}
}
function setWrapperSize(){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var sh = parseInt(arrayPageSize[1])+parseInt(arrayPageScroll[1]);
	var wrappertop = 220;
	sh = parseInt(sh)-parseInt(wrappertop);
	$("front-wrapper").style.height="620px";
}
function setCoverImage(sr,w,h){
	var objCoverImage = new Image();
	objCoverImage.src = sr;
	if(objCoverImage.complete){
		showCoverImage(sr,w,h);
	}else{
		objCoverImage.onload = function(){
			showCoverImage(sr,w,h);
		}
	}
}
function showCoverImage(sr,w,h){
	$("coverimg").style.display = "none";
	$("coverimg").src = sr;
	$("coverimg").style.width = w+"px";
	$("coverimg").style.height = h+"px";
	new Effect.Appear("coverimg", { duration:1.0, from: 0.2, to: 1.0 });
}
