// JavaScript Document

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 isLeapYear( yyyy ) {
	if( ( yyyy%4==0 && yyyy % 100 !=0 ) || yyyy%400==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 = "subcribe.php?action="+act+"&email="+obj.value+"&url="+doc_url;
		window.location = baseref+url;
	}else{
		alert("email address is invalid !");
		obj.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 disableselect(e){
	return false
} 
  
function reEnable(){
	return true
} 
  
//if IE4+
document.onselectstart=new Function ("return false") 
  
//if NS6
if (window.sidebar){
	document.onmousedown=disableselect
	document.onclick=reEnable
}


var omitformtags=["|input|", "|textarea|", "|select|"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf("|"+e.target.tagName.toLowerCase()+"|")==-1)
return false
}

function reEnable(){
	return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}*/-->

<!--// <![CDATA[
var OA_p=location.protocol=='https:'?'https:':'http:';
var OA_r=Math.floor(Math.random()*99999999);
if (!document.OA_used) document.OA_used = ',';
function OA_adjs(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//www.findahomedirect.com/openx/www/delivery/ajs.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    az+="&mmm_fo="+(document.mmm_fo)?'1':'0';
    if (document.context) az+= "&context=" + escape(document.context);
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}
function OA_adpop(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//www.findahomedirect.com/openx/www/delivery/apu.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}
// ]]> -->

<!--// <![CDATA[
  var OA_channel = 'FHD';
// ]]> -->

function Check_Value(){
	 var frm = document.frmSearch;
       var error = "";
	   if((isNaN( trim(frm.zip_code.value) ) || frm.zip_code.value<=0) && !isBlank(frm.zip_code.value))
       {
               error = "The format of the Zip Code you entered incorrect. The proper format must be a number. Example : 77072";
               alert(error);
               eval(frm.zip_code.focus());
       } 
	   if(frm.distance.options[frm.distance.selectedIndex].value>0 && isBlank(frm.zip_code.value))
	   {
	   		error = "The Zip Code need entered. The proper format must be a number. Example : 77072";
            alert(error);
            eval(frm.zip_code.focus());
	   }
	   /*if(  ((isNaN( trim(frm.zip_code.value)) || frm.zip_code.value<=0) && !isBlank(frm.zip_code.value)) ||  ((isNaN( trim(frm.distance.value)) || frm.distance.value<=0) && !isBlank(frm.distance.value)) )
	   {
	   	
	   }*/
	  
	   if(error!="")
               return false;
       return true;
}
<?php

$sql_lstate = "select state_id from state";
$stmt = new sutrix_query($db,$sql_lstate);
$array_state = array();
while(list($lstate_id)=$stmt->getrow())
{
       $array_state[] = $lstate_id;
}

$outputstr = "
                       var city0=new Array();\n
                       var cityID0=new Array();\n
                       ";

for($i=0; $i<sizeof($array_state); $i++)
{
       $newsql_city = "select city_id,city_name from city where state_id='".$array_state["$i"]."' order by city_name asc";
       //echo $newsql_city;
       $stmt = new sutrix_query($db,$newsql_city);
       $outputstr .= "var city".$array_state["$i"]."=new Array(\"Select State...\"\n";

                       $str_id = "";
                       $l_id = 0;
                       while(list($c_id,$c_name)=$stmt->getrow())
                       {
                               $outputstr .=",\"$c_name\"\n";
                               $str_id .= ",\"".$c_id."\"";

                       }
                       $outputstr .= ")\n";

                       $outputstr .= " var cityID".$array_state["$i"]."=new Array(-1".$str_id.")\n\t";
}

echo $outputstr;
?>
function state_city(inForm,selected)
{
       //alert(selected);
       var selectedArray = eval("city"+selected);

       var valueArray = eval("cityID"+selected);
       while (selectedArray.length < inForm.city_id.options.length)
       {
               inForm.city_id.options[(inForm.city_id.options.length - 1)] = null;
       }
       for (var i=0; i < selectedArray.length; i++)
       {
//             inForm.tour.options[i] = eval("new Option(" + selectedArray[i] + "," + valueArray[i] + ")" );
//             eval("inForm.tour.options[i]=" + "new Option(" + selectedArray[i]);//+","+valueArray[i]+")");
               var option = new Option(selectedArray[i],valueArray[i]);
               eval("inForm.city_id.options[i]=option");
       }
//     window.history.go(0);
}
