/**
 * @version Id: try2js.js v1.13 build 110609 tuzki.org ÌØ±ðÐÞ¸Ä°æ
 */

/************************* Global *************************/
function try2$(id)
{
	return document.getElementById(id);	
}
/************************* Global *************************/

/************************* AJAX *************************/
function send_request(url,obj,LoadingPic)
{
	objectID = obj;
	if (LoadingPic)
	{
		try2$(obj).innerHTML = "<p align=center><img src='images/loading.gif'></p>";
	}
	
	var http_request = newXMLHttpRequest();
	var handler = getReadyStateHandler(http_request,objectID); 
	
	http_request.onreadystatechange = handler; 
	
	http_request.open("GET",url,true);
	
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	
	http_request.send(null);
}

function newXMLHttpRequest()
{
	if(window.XMLHttpRequest)	//Mozilla Browser
	{
		http_request = new XMLHttpRequest();
		if(http_request.overrideMimeType)
		{
			http_request.overrideMimeType("text/xml");
		}
	}
	else if(window.ActiveXObject)	//IE Browser
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)	{}
		}
	}
	if(!http_request)
	{
		window.alert("Error: Cannot create XMLHttpRequest object");
		return false;
	}
	return http_request;
}

function getReadyStateHandler(req,obj)
{ 
	return function () 
	{ 
		if (req.readyState == 4) 
		{ 
			if (req.status == 200) 
			{
				document.getElementById(obj).innerHTML = unescape(req.responseText); 
				cont = req.responseText.split("<script");
				if (cont[1])
				{
					cont1 = cont[1].split("</script>");
					cont2 = cont1[0].substr(cont1[0].indexOf(">")+1);
					eval(cont2);	
				}
			}
			else 
			{ 
				document.getElementById(obj).innerHTML = "Error: Cannot read data"; 
			} 
		} 
	} 
}

function Send_Open(form_obj)
{
    okey=form_obj.OpenKey.value;
    location=okey;
}
/************************* AJAX *************************/


/************************* AJAX Form *************************/
if (!window.XMLHttpRequest) {
   window.XMLHttpRequest=function (){
   	return new ActiveXObject("Microsoft.XMLHTTP");
   }
}
function ajaxLoadPage(url,request,method,container)
{
	method=method.toUpperCase();
	var loading_msg='<center><img src="images/loading.gif"></center>';	//the text shows on the container on loading.
	var loader=new XMLHttpRequest;	//require Cross-Browser XMLHttpRequest
	if (method=='GET')
	{
		urls=url.split("?");
		if (urls[1]=='' || typeof urls[1]=='undefined')
		{
			url=urls[0]+"?"+request;
		}
		else
		{
			url=urls[0]+"?"+urls[1]+"&"+request;
		}
		
		request=null;	//for GET method,loader should send NULL
	}
	loader.open(method,url,true);
	if (method=="POST")
	{
		loader.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	loader.onreadystatechange=function(){
		if (loader.readyState==1)
		{
			container.innerHTML=loading_msg;
			
		}
		if (loader.readyState==4)
		{
			container.innerHTML=loader.responseText;
		}
	}
	loader.send(request);
}
function formToRequestString(form_obj)
{
	var query_string='';
	var and='';
	for (i=0;i<form_obj.length ;i++ )
	{
		e=form_obj[i];
		if (e.name!='')
		{
			if (e.type=='select-one')
			{
				element_value=e.options[e.selectedIndex].value;
			}
			else if (e.type=='checkbox' || e.type=='radio')
			{
				if (e.checked==false)
				{
					continue;	
				}
				element_value=e.value;
			}
			else
			{
				element_value=e.value;
			}
			query_string+=and+e.name+'='+element_value.replace(/\&/g,"%26");
			and="&"
		}
		
	}
	return query_string;
}
function ajaxFormSubmit(form_obj,container)
{
	ajaxLoadPage(form_obj.getAttributeNode("action").value,formToRequestString(form_obj),form_obj.method,container)
}
/************************* AJAX Form *************************/

/************************* Light Box *************************/
/*Preferences div & table*/
document.write("<div id='Try2LightBoxBG'></div>");
document.write("<div id='Try2LightBoxCon'>");
document.write("<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%' id='Try2LightBoxConTable'>");
document.write("<tr><td align='center' valign='middle' id='Try2LightBoxConTD'>");

document.write("<div id='try2_lb_window'>");
document.write("<div id='try2_lb_menu'><a href=\"javascript:try2LightBox('close')\"><img src='try2lb_close.gif' border='0'></a></div>");
document.write("<div id='try2lb_con'>");

document.write("</div></div></td></tr></table>");
document.write("</div>");

/*Hold window position*/
function try2_lb_hold_win()
{
	try2$('Try2LightBoxCon').style.top = document.documentElement.scrollTop ? document.documentElement.scrollTop+"px" : document.body.scrollTop+"px";
	setTimeout("try2_lb_hold_win();",200);
}

/*LightBox action*/
function try2LightBox(oc,url,w,h,lbstyle)
{
	lbstyle = !lbstyle ? 1 : lbstyle;
	w = !w ? 500 : w;
	h = !h ? 300 : h;
	if (oc == "open" || oc == "1") {
		try2$('Try2LightBoxBG').style.display = 'block';
		try2$('Try2LightBoxCon').style.display = 'block';
		
		dcobj = document.documentElement.clientHeight ? document.documentElement : document.body;		
		try2$('Try2LightBoxCon').style.top = dcobj.scrollTop+"px";
		try2$('Try2LightBoxCon').style.height=dcobj.clientHeight+"px";
		try2$('Try2LightBoxBG').style.width=dcobj.scrollWidth+"px";
		try2$('Try2LightBoxBG').style.height=dcobj.scrollHeight+"px";
		try2$('Try2LightBoxCon').focus();
		switch (lbstyle)  {
			case 1: 
				try2lb_move_wh(w,h);
				break;
			case 2: 
				try2lb_move_w(w,0,h);
				break;
			case 3: 
				try2$('try2_lb_window').style.width = w+'px';
				try2$('try2_lb_window').style.height = h+'px';
				try2$('try2lb_con').style.display = 'block';
				break;
		}
		send_request(url,"try2lb_con");
		try2_lb_hold_win();
	}
	else if (oc == "close" || oc == "2") {
		try2$('try2lb_con').style.display = 'none';
		try2lb_move_close("","",try2$('try2_lb_window').clientWidth,try2$('try2_lb_window').clientHeight);
	}
}

/*Dynamic effects*/
var trylb_to;
var try2lb_speed,try2lb_speedw,try2lb_speedh;
var try2lb_speed_x = 2;	//Speed control
/*Style 1 begin*/
function try2lb_move_w(max,w,maxh)
{
	try2lb_speed = parseInt(max / try2lb_speed_x);
	w = !w ? try2lb_speed : w + try2lb_speed;
	try2$('try2_lb_window').style.width = w+'px';
	if (w <= max) trylb_to = setTimeout("try2lb_move_w("+max+","+w+","+maxh+");",1);
	else try2lb_move_h(maxh,100)
}
function try2lb_move_h(max,h)
{
	try2lb_speed = parseInt(max / try2lb_speed_x);
	h = !h ? try2lb_speed : h + try2lb_speed;
	try2$('try2_lb_window').style.height = h+'px';
	if (h <= max) trylb_to = setTimeout("try2lb_move_h("+max+","+h+");",1);
	else {
		try2$('try2lb_con').style.display = 'block';
		try2$('try2lb_con').style.height = (h-40)+'px';
	}
}
/*Style 1 end*/

/*Style 2 begin*/
function try2lb_move_wh(wmax,hmax,w,h)
{
	var try2lb_speedw = parseInt(wmax / try2lb_speed_x);
	var try2lb_speedh = parseInt(hmax / try2lb_speed_x);
	w = !w ? try2lb_speedw : w + try2lb_speedw;
	try2$('try2_lb_window').style.width = w+'px';
	
	h = !h ? try2lb_speedh : h + try2lb_speedh;
	try2$('try2_lb_window').style.height = h+'px';
	
	if (h <= hmax || w <= wmax) trylb_to = setTimeout("try2lb_move_wh("+wmax+","+hmax+","+w+","+h+");",1);
	else {
		try2$('try2lb_con').style.display = 'block';
		try2$('try2lb_con').style.height = (h-40)+'px';
	}
}
/*Style 2 end*/

/*Close window begin*/
function try2lb_move_close(w,h,noww,nowh)
{
	try2$('Try2LightBoxBG').style.display = 'none';
	try2$('Try2LightBoxCon').style.display = 'none';
	try2$('try2lb_con').innerHTML = '';
	try2$('try2_lb_window').style.height = '100px';
}
/*Close window end*/
/************************* Light Box *************************/
