var d = new Date();
var cntdwnT;
function NewWindow(mypage, myname, w, h, scroll, resizable) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', resizable='+resizable
	win = window.open(mypage, myname, winprops)
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function gotoPage(mod)
{
	document.getElementById(oldmod).className = "";
	document.getElementById("div_top").style.display = "";
	document.getElementById("div_forgetpwd").style.display = "none";
	if (mod == "home.htm")
	{
		oldmod = "home";
		document.getElementById(oldmod).className = "current";
		document.getElementById("div_flash").style.display = "";
		document.getElementById("div_teastu").style.display = "";
		document.getElementById("div_load1").style.display = "none";
		document.getElementById("div_load2").style.display = "none";
	}
	else
	{
		document.getElementById(oldmod).className = "";
		document.getElementById("div_teastu").style.display = "none";
		document.getElementById("div_load1").style.display = "";
		if (!mod.match("stu_"))
		{
			if (mod.split(',').length > 1)
			{
				document.getElementById("div_flash").style.display = "none";
				document.getElementById("div_load2").style.display = "";
				oldmod = mod.split(',')[0].split('.')[0];
				document.getElementById(oldmod).className = "current";
			} else
			{
				document.getElementById("div_flash").style.display = "";
				document.getElementById("div_load2").style.display = "none";
				document.getElementById(mod.split('.')[0]).className = "current";
				oldmod = mod.split('.')[0];
			}
		}
		
		for (var i=0;i<mod.split(',').length; i++)
		{
			var objXMLHTTP = makeReq(); //new ActiveXObject ("Microsoft.XMLHTTP");
			objXMLHTTP.open("GET",mod.split(',')[i]+"?d="+d.getTime(),false);
			objXMLHTTP.send( null );
			document.getElementById("div_load"+(i+1)).innerHTML = objXMLHTTP.responseText;
		}
		/*if (mod == "abtLEAD.htm")
			loadevent2("cast.htm", 1);*/
	}
	//if (mod.match("aboutus")){loadevent2(mod.split(',')[1],mod.split(',').length==2?0:mod.split(',')[2]);}
	//clearTimeout(cntdwnT);
}
function forgetPwd(htm)
{
	document.getElementById("div_forgetpwd").style.display = "";
	document.getElementById("div_teastu").style.display = "";
	document.getElementById("div_top").style.display = "none";
	document.getElementById("div_load1").style.display = "none";
	document.getElementById("div_load2").style.display = "none";
	document.getElementById("div_flash").style.display = "none";

	var objXMLHTTP = makeReq(); 
	objXMLHTTP.open("GET",htm+"?d="+d.getTime(),false);
	objXMLHTTP.send( null );
	document.getElementById("div_forgetpwd").innerHTML = objXMLHTTP.responseText;
}
function loadenquiry()
{
	var objXMLHTTP = makeReq(); 
	objXMLHTTP.open("GET","enquiry.htm?d="+d.getTime(),false);
	objXMLHTTP.send( null );
	document.getElementById("div_load1").innerHTML = objXMLHTTP.responseText;
}
function loadevent2(mod,link)
{
	resetLinkColor("#666666","abtLead");
	var bAnchor = false;
	if (document.getElementById("abtLead"+link) == null){link = link.split('|')[0]; bAnchor = true;}
	document.getElementById("abtLead"+link).style.color="#FE860C";
	var objXMLHTTP = makeReq(); //new ActiveXObject ("Microsoft.XMLHTTP");
	objXMLHTTP.open("GET",mod+"?d="+d.getTime(),false);
	objXMLHTTP.send( null );
	document.getElementById("loadhere2").innerHTML = objXMLHTTP.responseText;
	if (bAnchor)
		document.getElementById("loadhere2").scrollTop=document.getElementById("loadhere2").scrollHeight;
	else
		document.getElementById("loadhere2").scrollTop=0;

}
function user_input(flag)
{
	document.getElementById("user_inputTxt").style.display = flag?"":"none";
	document.getElementById("user_inputTxt").value = "";
}
function submit_data(name,ex)
{
	var user_ans="";
	for (var i=0; i<document.getElementsByName("rdoPoll").length; i++)
	{
		if (document.getElementById("opt"+i).checked)
		{
			if (i == ex)
				user_ans = document.getElementById("user_inputTxt").value;
			else
				user_ans = document.getElementById("opt"+i).value;
			break;
		}
	}
	if (ex == -1)
		user_ans = document.getElementById("user_inputTxt").value;
	if (user_ans == "" && ex != -2) {
		alert("Please make a selection or enter your opinion in the text box provided before clicking on Submit. Thank you.");return;
	}

	var dataXml=new ActiveXObject("MSXML2.DOMDocument");
	var xmlroot = dataXml.createElement("root");
	dataXml.appendChild(xmlroot);
	xmlroot = dataXml.createElement("poll");
	xmlroot.setAttribute("nametype", name);
	xmlroot.setAttribute("userans", user_ans.replace(/'/g,"''"));
	xmlroot.setAttribute("user_ip", "");//document.getElementById("user_ip_address").value);
	dataXml.selectSingleNode("//root").appendChild(xmlroot);
	if (ex != -2)
		document.getElementById("user_inputTxt").value = "";
//alert(dataXml.xml);return;
	try
	{
		var objXMLHTTP = makeReq(); //new ActiveXObject ("Microsoft.XMLHTTP");
		//Have to change when host machine change.
		objXMLHTTP.open("POST","quickadd.aspx",false);
		objXMLHTTP.send(dataXml); 	
	}
	catch(e)
	{
		alert("Error details: " & e);
		document.body.releaseCapture();
		return;
	}
	if (objXMLHTTP.responseText.match("error") && objXMLHTTP.responseText.match("duplicate"))
		alert("You have already submitted previously. Thank you for participating.");
	else		
		alert(objXMLHTTP.responseText);
}
function resetLinkColor(col,name)
{
	if (name == "abtLead")
	{
		for (var i=0; i<4; i++)
		{
			if (document.getElementById(name+i) != null)
				document.getElementById(name+i).style.color=col;
		}
	}
	else
	{
		document.getElementById("sublink0").style.color=col;
		document.getElementById("sublink1").style.color=col;
		document.getElementById("sublink6").style.color=col;
		document.getElementById("sublink9").style.color=col;
	}
}
function showtip(txt,id){
	document.getElementById("tooltip").innerHTML = txt;
	document.getElementById("tooltip").style.posLeft = event.clientX;
	document.getElementById("tooltip").style.posTop = event.clientY-10;
	document.getElementById("tooltip").style.position = "absolute";
	document.getElementById("tooltip").style.display = "";
}
function hidetip(){
document.getElementById("tooltip").style.display = "none";
}
function tableShowHide(divName1, divName2, divName3) {
	if (document.getElementById(divName2).style.display == "none") {
		document.getElementById(divName2).style.display = "";
		document.getElementById(divName3).style.display = "";
		document.getElementById(divName1).style.display = "none";
	} else {
		document.getElementById(divName2).style.display = "none";
		document.getElementById(divName3).style.display = "none";
		document.getElementById(divName1).style.display = "";
	}
}
function makeReq()
{
	var xmlHttpReq = null;
	
	if(window.XMLHttpRequest)
	{
  		xmlHttpReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		try{
			xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
    	}catch(e){
        	try{
				xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        	}catch(e){
          		try{
					xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        		}catch(e){
          			xmlHttpReq = false;
       			}
        	}
		}
	}
	return xmlHttpReq;
}
function sendEnquiry()
{
	var oName = document.getElementById("cont_name").value;
	var oEmail = document.getElementById("cont_email").value;
	var oContact = document.getElementById("cont_contact").value;
	var oSchCo = document.getElementById("cont_schCo").value;
	var oAdd = document.getElementById("cont_add").innerText;
	var oRemark = document.getElementById("cont_remark").innerText;
	alert(oName + ", "+oEmail + ", "+oContact + ", "+oSchCo + ", "+oAdd + ", "+oRemark);
//	return;
	if (!isValid(oName) || !isValid(oEmail) || !isValid(oContact) || !isValid(oSchCo) || !isValid(oAdd) || !isValid(oRemark))
	{
		alert("Please make sure that all text fields do not contains < > '"); return;
	}
	if (oName == "" || oEmail == "" || oContact == "" || oRemark == "")
		{alert("Please make sure you have fill in the required information.");return;}

	if(!isEmailAddr(oEmail) && oEmail!="")
	{
		alert("Please provide a valid email address. Example: john@lead.com.sg"); return;
	}
	
	var dataXml=new ActiveXObject("MSXML2.DOMDocument");
	var xmlroot = dataXml.createElement("root");
	dataXml.appendChild(xmlroot);
	xmlroot = dataXml.createElement("mail");
	xmlroot.setAttribute("name", oName);
	xmlroot.setAttribute("email", oEmail);
	xmlroot.setAttribute("contact", oContact);
	xmlroot.setAttribute("schCo", oSchCo);
	xmlroot.setAttribute("add", oAdd);
	xmlroot.setAttribute("remark", oRemark);
	dataXml.selectSingleNode("//root").appendChild(xmlroot);

	try
	{
		var objXMLHTTP = makeReq(); //new ActiveXObject ("Microsoft.XMLHTTP");
		objXMLHTTP.open("POST","sendfeedback.asp",false);
		objXMLHTTP.send(dataXml); 	
	}
	catch(e)
	{
		alert("Error in send Enquiries/Feeback. The details: " & e);
		document.body.releaseCapture();
		return;
	}
	if (objXMLHTTP.responseText.match("error"))
		alert("Error: " + objXMLHTTP.responseText);
	else
	{
		alert(objXMLHTTP.responseText);	
		document.getElementById("cont_form").reset();
	}
}
function isValid(val) {
	return (val.indexOf("<")<0 && val.indexOf(">")<0 && val.indexOf("'")<0)
}
	
function isEmailAddr(email)
{
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}

