function printpage() {
  bV = parseInt(navigator.appVersion);
  if (bV >= 4) window.print();
}

function mailpage(){
  mail_str = "mailto:";
  mail_str += "?subject=Visit Singapore for a Unique Experience!";
  mail_str += "&body= You should check this out at, " + location.href;
  location.href = mail_str;
}


//print cart related
var popupmailpage = null; 
function popupMailPage () {
  my_width = 400;
  my_height = 370;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  popupmailpage = window.open('','popupmailpage',myvar);
  
  return true;
}

var popupprintpage = null; 
function popupPrintFriendly () {
  document.fm_printfriendly.radiobuttonvalue.value = getRadioValue("myradiobutton");
  my_width = 670;
  my_height = 500;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left + ",scrollbars=yes";
  popupprintpage = window.open('','popupprintpage',myvar);
  return true;
}

function getRadioValue(RadioName){
  var colRadio = document.getElementsByName(RadioName);
  for (var i = 0; i < colRadio.length; i++){
    if (colRadio[i].checked){
      return colRadio[i].value;
    }
  }  
  return null;
}

function isEmail_1(input){
	var inputStr=input;
	//alert("inputStr" + inputStr);
	if(window.RegExp && inputStr){
		var regstr1 = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var regstr2 = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
		var regExp1 = new RegExp(regstr1);
		var regExp2 = new RegExp(regstr2);
		var regExp3 = /[^a-zA-Z0-9\-_.@]/;
		if(!(!regExp1.test(inputStr) && regExp2.test(inputStr) && !regExp3.test(inputStr)) || !(inputStr.indexOf("@")>=0)) {
			return false;
		}
		return true;
	}
}

var popupaddpage = null; 
function popupAddToPrintCart () {
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  popupaddpage = window.open('','popupaddpage',myvar);
  return true;
}

function popupAddToIPCart () {
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  popupaddpage = window.open('','popupaddpage',myvar);
  return true;
}

function SubmitSelect(thisform){
  var currenturl = location.href;
  //alert(currenturl);
  var myvalue = thisform.elements[0].value;
  if(myvalue==0){
    return false;
  }else if(myvalue=="it"){
    window.open("http://it.visitsingapore.com");
    return false;
  }else if(myvalue=="pl"){
    window.open("http://pl.visitsingapore.com");
    return false;
  }else{
    thisform.submit();
  }
} 

function SubmitIndexSelect(thisform){
  //var tempValue="";
  var tempValue=thisform.elements[0].value;
  if(thisform.elements[0].value==0){
    return false;
  }
  if(thisform.elements[0].value==8){
    window.open("http://www.singaporeedu.gov.sg");
  }else if(thisform.elements[0].value==9){
    window.open("http://www.singaporemedicine.com");
  }else{
    //setCookie("interest", thisform.elements[0].value, getExpireDate());
    setCookie("interest", tempValue, getExpireDate());
    thisform.submit();
  }


} 

function setCookie(name, value, expire ){
	document.cookie = name + "=" + escape(value) + ((expire==null ? "":(";expires=" + expire.toGMTString())));
}

function setGlobalCookie(name, value, expire ){
	document.cookie = name + "=" + escape(value) + ";path=/;" + ((expire==null ? "":(";expires=" + expire.toGMTString())));
}

function getExpireDate(){
	var expires = new Date();
	expires.setTime((new Date().getTime()) + 1000*60*60*24*365);
	return expires;
}
function writeSessionCookie (cookieName, cookieValue) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    //document.location.reload();
    return true;
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function OpenAsPopupPage (url, my_width, my_height) {
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  mywindow = window.open('url','',myvar);
  mywindow.location=url;
  //window.open(theURL,winName,features);
}

function OpenAsPopupPageMap (url, my_width, my_height) {
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left + ",scrollbars=yes";
  mywindow = window.open('url','',myvar);
  mywindow.location=url;
  //window.open(theURL,winName,features);
}


//not finished.
function addAppToIPcartApp(actionurl){
  alert("actionurl is " + actionurl);
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  window.open(actionurl,"newWindow",myvar);
}
//not finished.

function addAppToPrintcartApp(actionurl, id,country,pagename,url){
  //alert("url is " + url + "&myhandle=" + actionurl);
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  window.open(actionurl + "?printcartclicked=yes&addjsp=yes&id=" +id+ "&country="+ country +"&pagename=" + pagename + "&url=" + escape(url) + "&myhandle=" + escape(actionurl),"newWindow",myvar);
}

function addAppToPrintcartApp2(actionurl, id,country,pagename,url, type, htmlstring){
  //alert("htmlstring is " + htmlstring);
  //alert("htmlstring2 is " + escape(htmlstring));
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;

  //alert(actionurl + "?printcartclicked=yes&addjsp=yes&id=" +id+ "&country="+ country +"&pagename=" + pagename + "&myhandle=" + escape(actionurl) + "&type=" + type + "&htmlstring=" + escape(htmlstring) + "&url=" + escape(url));
  window.open(actionurl + "?printcartclicked=yes&addjsp=yes&id=" +id+ "&country="+ country +"&pagename=" + pagename + "&myhandle=" + escape(actionurl) + "&type=" + type + "&url=" + escape(url) + "&htmlstring=" + htmlstring,"newWindow",myvar);
}

function addAppToPrintcartApp3(actionurl, id,country,pagename,url,eventtype){
  //alert("url is " + url + "&myhandle=" + actionurl);
  my_width = 300;
  my_height = 200;
  my_top = screen.height/2 - my_height/2;
  my_left = screen.width/2 - my_width/2	;	
  myvar = "height=" + my_height + ", width=" + my_width + ", top=" + my_top + ", left=" + my_left;
  window.open(actionurl + "?printcartclicked=yes&addjsp=yes&eventType=" + eventtype + "&id=" +id+ "&country="+ country +"&pagename=" + pagename + "&url=" + escape(url) + "&myhandle=" + escape(actionurl),"newWindow",myvar);
 

}


// do you know images
// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}
var page_loaded;
var jsDYKHead = "";
var jsDYKInfo = "";
function writeDYK(){
  page_loaded = true;
  document.dykheaderimg.src=jsDYKHead;
  writeToLayer('dykinfoDiv', jsDYKInfo, 'greetingmessagesample');
}
function writeToLayer(id, sHTML, myclass) {
  if (page_loaded) {
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
    var cntnt = '<div class='+ myclass +'>' + sHTML + '</div>';
    if (typeof el.innerHTML!="undefined") {
        el.innerHTML = cntnt;
    }else if (document.layers){
  	el.document.write(cntnt);
  	el.document.close();
    }
  }
}
function getLyrRef(lyr,doc) {
  if (document.layers) {
    var theLyr;
    for (var i=0; i<doc.layers.length; i++) {
      theLyr = doc.layers[i];
      if (theLyr.name == lyr) return theLyr;
      else if (theLyr.document.layers.length > 0)
        if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
	  return theLyr;
    }
    return null;
  }
}


var xmlhttp
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  //alert("XML data OK")
  document.getElementById('Menu').innerHTML=xmlhttp.responseText
  }
  else
  {
  //alert("Problem retrieving XML data:" + xmlhttp.statusText)
  }
  }
}

function clearTextField(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); 
  if (obj) obj.value = newText;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


//add by chunlong to reset forms for apps
function jsResetForm(myform){
  var pass=true;
  var first=-1;
  if (document.images){
    for (i=0;i<myform.length;i++){
      var tempobj=myform.elements[i]
      if (tempobj.type=="text"){
        eval(tempobj.value="")
        if (first==-1) {first=i;}
     
      }
       else if (tempobj.type=="hidden"){
        if (first==-1) {first=i;}
       }
	   else if (tempobj.type=="checkbox") {
        eval(tempobj.checked=0)
        if (first==-1) {first=i;}
      }else if (tempobj.col!="") {
        eval(tempobj.value="")
        if (first==-1) {first=i;}
      }
    }
  }
}
function jsResetStaticForm(myform){
  myform.reset();
}

function reloadPage(){
  document.location.reload();
}


function heightLightError( eleID , cssName){
  try{
    var elem = document.getElementById(eleID);
    elem.className = cssName; 
  }catch(e){}  
} 

