/***** Created By: Dion Carlo B. Reyes *****/

var xmlHttp;

function showList(month, day, year, filter, myCur)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cal_showList.php?month="+month+"&day="+day+"&year="+year+"&filter="+filter+"&myCur="+myCur;
	xmlHttp.onreadystatechange = stateChanged4;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged4()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("list").innerHTML=xmlHttp.responseText;
}

function ei_showlist(cur)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "ei_showlist.php?cur="+cur;
	xmlHttp.onreadystatechange = stateChanged5;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged5()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("ei_list").innerHTML=xmlHttp.responseText;
}

function setOptions(cur, flag)
{
	if(flag == 0)
		window.location = "cal_add.php?cur="+cur;
	else
		window.location = "USD2.php?cur="+cur;
}

function setOptions2(ei, cur, flag)
{
	if(flag == 0)
		window.location="cal_add.php?cur="+cur+"&ei="+ei;
	else
		window.location="USD2.php?cur="+cur+"&ei="+ei;
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("nlocation").innerHTML=xmlHttp.responseText;
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("calList").innerHTML=xmlHttp.responseText;
}

function addToCalendar()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;  
	}

	var nmonth = document.getElementById("nmonth").value;
	var days = document.getElementById("days").value;
	var nyear = document.getElementById("nyear").value;
	var hour = document.getElementById("hour").value;
	var ampm = document.getElementById("ampm").value;
	var minute = document.getElementById("minute").value;
	var nlocation = document.getElementById("nlocation").value;
	var Actual = document.getElementById("Actual").value;
	var Forecast = document.getElementById("Forecast").value;
	var optone = document.getElementById("optone").value;
	var opttwo = document.getElementById("opttwo").value;
	var url = "addToCalendar.php";	

	url = url+"?nmonth="+nmonth;
	url = url+"&days="+days+"&nyear="+nyear+"&hour="+hour+"&ampm="+ampm+"&minute="+minute+"&nlocation="+nlocation+"&Actual="+Actual+"&Forecast="+Forecast+"&optone="+optone+"&opttwo="+opttwo;

	xmlHttp.onreadystatechange = stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

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;
}

function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	URL = "http://"+window.location.hostname+"/"+URL;
	
	var leftx = (screen.width/2)-(767/2);
	var topx = (screen.height/2)-(440/2);
	eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars=1,location=1,status=1,menubar=0,resizable=0,width=767px,height=440px,top="+topx+",left="+leftx+"');");
}

function popUp2(URL)
{
	day = new Date();
	id = day.getTime();
	URL = "http://www.fsifx.com/"+URL;
	
	var leftx = (screen.width/2)-(410/2);
	var topx = (screen.height/2)-(599/2);	
	eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars=0,location=1,status=1,menubar=0,resizable=0,width=410px,height=599px,top="+topx+",left="+leftx+"');");
}

function popUp3(URL)
{
	//alert('wa');
	day = new Date();
	id = day.getTime();
	URL = "http://www.fsifx.com/"+URL;
	
	var leftx = (screen.width/2)-(410/2);
	var topx = (screen.height/2)-(599/2);	
	eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars=0,location=1,status=1,menubar=0,resizable=0,width=410px,height=599px,top="+topx+",left="+leftx+"');");
}

function popUp4(URL)
{
	//alert('wa');
	day = new Date();
	id = day.getTime();
	URL = "http://www.fsifx.com/"+URL;
	
	var leftx = (screen.width/2)-(620/2);
	var topx = (screen.height/2)-(420/2);	
	eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars=0,location=1,status=1,menubar=0,resizable=0,width=620px,height=420px,top="+topx+",left="+leftx+"');");
}

function Checkform()
{
	var u = document.login.uname.value;
	var p = document.login.pword.value;
	if(u == "")
	{
		document.getElementById("error").innerHTML="<font color='red' face='Arial'>Please enter your username</font>";
		document.login.uname.focus();
		return false;
	}
	else if(p == "")
	{
		document.getElementById("error").innerHTML="<font color='red' face='Arial'>Please enter your password</font>";
		document.login.pword.focus();
		return false;
	}
	else if(u != "Admin")
	{
		document.getElementById("error").innerHTML="<font color='red' face='Arial'>Incorrect Username</font>";
		document.login.pword.focus();
		return false;
	}
	else if(p != "Admin")
	{
		document.getElementById("error").innerHTML="<font color='red' face='Arial'>Incorrect Password</font>";
		document.login.pword.focus();
		return false;
	}	
	document.login.method="POST";
	document.login.action="createSession.php";	
	document.login.submit()
}

function cp_manage1()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cp_manageRights.php";
	xmlHttp.onreadystatechange = cp_manage_SC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cp_manage2()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cp_manageAccounts.php";
	xmlHttp.onreadystatechange = cp_manage_SC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cp_manage3()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cp_manageCreate.php";
	xmlHttp.onreadystatechange = cp_manage_SC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cp_manage_SC()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("user_mngmnt").innerHTML=xmlHttp.responseText;
}

function cp_rights(id)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cp_power.php?id="+id;
	xmlHttp.onreadystatechange = cp_SC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cp_accounts(id)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{ 
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = "cp_account.php?id="+id;
	xmlHttp.onreadystatechange = cp_SC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cp_SC()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("right_pane").innerHTML=xmlHttp.responseText;
}

function register_popup()
{
	day = new Date();
	id = day.getTime();
	URL = "register.php";
	eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars=1,top=0,location=0,status=1,menubar=0,resizable=0,width=300px,height=200px');");
}
