function hide(tag){
	document.getElementById(tag).style.display = "none";
}
function show(tag){
	document.getElementById(tag).style.display = "block";
}
function iframePage(iframeId,page,scrolling){
	document.getElementById(iframeId).src = page;
	document.getElementById(iframeId).scrolling = scrolling;
}
function chkBegin(year){
	year_next = parseInt(year) + 88;
	if(year_next > 2008 ){ year_next = 2008;}
	document.getElementById('end').value = year_next;
}
function chkEnd(year){
	if(year > 2008){
		alert("Cannot define the future !!!");
		document.getElementById('end').value = 2008;
	}
}
function chkAllBlank(ctrl,form){
	j=0;
	ctrl_arr = ctrl.split("~");	
	for(i=0;i<ctrl_arr.length;i++){
		tmp = document.getElementById(ctrl_arr[i]).value;
		if(tmp != ""){
			j++;
		}
	}
	if(j == ctrl_arr.length){//means all control was filled		
		alert("Congratulation! Your timeline is created aleardy.");
		document.getElementById(form).submit();
	}else{
		alert("Sorry! May be some error occurred.Please try again");	
	}
}
//==================================================================================
var xmlHttp;
divText = null;//for show in div
//==================================================================================
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	 // Firefox, Opera 8.0+, Safari
	 	xmlHttp=new XMLHttpRequest();
	 }catch (e){
	 //Internet Explorer
		  try{
			 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	return xmlHttp;
}
/*===================================================================================
									Check Username
=====================================================================================*/

function checkAvailable(divId,divShow){
	xmlHttp = GetXmlHttpObject();
	divText = divShow;
	username = document.getElementById(divId).value;
	url = "check.php?do=username&username="+username;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange=checkAvailableChanged;
	xmlHttp.send(null);
}
function checkAvailableChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(divText).innerHTML = xmlHttp.responseText;//show all page
	}else{
		document.getElementById(divText).innerHTML = "Please wait...";
	}
}
/*===================================================================================
								Check Password Match
=====================================================================================*/
function checkPassword(divId1,divId2,divShow){

	password1 = document.getElementById(divId1).value;
	password2 = document.getElementById(divId2).value;

	if(password1 != password2){
		document.getElementById(divShow).innerHTML = "Not Match,Please type again !";
	}else{
		document.getElementById(divShow).innerHTML = "OK !";
		document.getElementById('register0').style.display = "none";
		document.getElementById('register').style.display = "block";
	}
	if(password1 == ""){
		document.getElementById(divShow).innerHTML = "password are blank !";
		document.getElementById('register0').style.display = "block";
		document.getElementById('register').style.display = "none";
	}
}

/*===================================================================================
									Include Page
=====================================================================================*/
function includePage(divShow,page){
	xmlHttp = GetXmlHttpObject();
	divText = divShow;
	url = page;

	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange=includePageChanged;
	xmlHttp.send(null);
}
function includePageChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(divText).innerHTML = xmlHttp.responseText;//show all page
	}else{
		document.getElementById(divText).innerHTML = "Please wait...";
	}
}
/*===================================================================================
								Change Timeline in Node editor
=====================================================================================*/
function chgTimeline(timeline_id,divShow){
	divText = divShow;
	xmlHttp = GetXmlHttpObject();
	url = "chgTimeline.php?timeline_id="+timeline_id;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange=chgTimelineChanged;
	xmlHttp.send(null);
}
function chgTimelineChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(divText).innerHTML = xmlHttp.responseText;//show all page
	}else{
		document.getElementById(divText).innerHTML = "Please wait...";
	}
}
//=====================================================================================
function voteTimeline(timeline_id){
	xmlHttp = GetXmlHttpObject();
	url = "vote_save.php?tm_id="+timeline_id;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(null);
}
/*==================================================================================
								    EDIT
===================================================================================*/
var div_id_edit = "";
function getControlEdit(tmp){
	div_id_edit = tmp;
}
function editData(url){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
	xmlHttp.onreadystatechange=editStateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
//====================================================
function editStateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		var textSplit = xmlHttp.responseText.split("&");
		var div_id_edit_split = div_id_edit.split("&");
		for(i=0;i<div_id_edit_split.length;i++){
			var control_name = div_id_edit_split[i];
			//alert("'"+control_name + "="+textSplit[i]+"'");
			if(document.getElementById(control_name).value != 'undefined'){
				document.getElementById(control_name).value = textSplit[i];	
				
			}
		}
	} 
}
