/* Cookie  */
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

	/******************************************
	Top Page Option --> Function
	******************************************/
	var SetFontSize = function(num){
		var ini_char_size = Get_Cookie('chsize');
		if(ini_char_size != num){
			Set_Cookie('chsize', num, 15, '/');
		}
		return true;
	}

	var SetBackground = function(Bchar){
		var ini_bc_type = Get_Cookie('color');
		if(Bchar != ini_bc_type){
			Set_Cookie('color', Bchar, 15, '/');
			window.location.href=window.location.href;
		}
	}		

	var SetFontType = function(oType){
		var ini_char_type = Get_Cookie('chtype');
		if(ini_char_type != oType){
			Set_Cookie('chtype', oType, 15, '/');
		}	
		return true;
	}

	var openPageOption = function(){
		if(document.getElementById('pgOption')){
			var oDiv = document.getElementById('pgOption');
			if(oDiv.style.display == 'block')	oDiv.style.display = 'none';
			else								oDiv.style.display = 'block';
		}
	}
// 8pt/10pt/13pt/16pt/20pt
/* Font setting */
/*
function setActiveTextSize(activetSize){
	Csize=document.getElementById('contents').style.fontSize;
	document.getElementById('contents').style.fontSize = activetSize."px";
	createCookie("ActiveFontSize",activetSize,1000);
}
/// initial function 
function applystyle(){
var Currentfontsize = 11;
	if (var fontSize = Get_Cookie('ActiveFontSize')) {
		document.getElementById('contents').style.fontSize = fontSize;
	} else {
		document.getElementById('contents').style.fontSize = fontSize;
	}
}
*/

/**************************************************************************
Form Check Function
**************************************************************************/
function FormUserIDCheck(str){
		var strcheck = /^[_0-9a-zA-Z]+$/;
		if(str.length < 5)			return false;
		if(str.length > 30)			return false;
		if(!strcheck.test(str))		return false;
		else						return true;
}

function FormEmailCheck(str){
		var strcheck = /^[_0-9a-zA-Z-]+(.[_0-9a-zA-Z-]+)*@[0-9a-zA-Z-]+(.[0-9a-zA-Z-]+)*$/;
		if(!strcheck.test(str))		return false;
		else						return true;
}

function FormWebsiteCheck(str){
		var strcheck = /^[a-zA-Z]+\:\/\/([^\/:]+(:(d+))?)(\/.*)?$/;
		if(!strcheck.test(str))		return false;
		else						return true;
}
function FormPhoneCheck(str){
		var strcheck = /^[0-9\-\+]+$/;
		if(!strcheck.test(str))		return false;
		else						return true;

}


	function FormCheck(oForm,form_arr,form_name){
		var checkele;
		for(var i=0;i < form_arr.length ;i++){
			checkele		= form_arr[i];
			if(oForm.elements[checkele].value == "" ||
				oForm.elements[checkele].value == null){
				alert("Please Enter your " + form_name[i] );
				oForm.elements[checkele].focus();
				return false;
			}
		}
		return true;
	}




/* In FF use insertAdjacentHTML */
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this);
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}


var agt =navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);














