// JavaScript Document
var xmlHttp;
var rootpath;
var divid
var bip
var timer
var alldata
var alldataarr
var num
var myPano;
var loadzone;
var postby

 
//rootpath = "http://path.com/to/root/location/";   // be sure to change this to your URL

function CheckFields(showzone)
{
	if(document.getElementById("subject").value == "" || document.getElementById("comments").value == "")
	{
		alert("Subject and Comments cannot be empty")
		return false
	}
	return true
}

function reply(showzone)
{
	//alert(showzone)
	document.getElementById("replyZone"+showzone).innerHTML="<hr><div id='warnings'></div><table><tr><td align='left'>Posted By:</td><td align='left'>"+postby+"</td></tr><tr><td align='left'>Subject:</td><td align='left'><input type='text' id='subject' name='subject' class='compstyle'></td></tr><tr><td valign='top' align='left'>Your comments:</td><td align='left'><textarea id='comments' name='comments' COLS=60 ROWS=8 class='compstyle'></textarea></td></tr><tr><td>&nbsp;</td><td><INPUT TYPE='submit' VALUE='Submit' name='save' class='compstyle'><INPUT TYPE='reset' VALUE='Reset' class='compstyle'></td></tr></table>"	
	
}

function ShowReplyThreads(msgid,showzone,alias_name)
{
	//alert(msgid)
	var url= "ShowReplyThreads.asp?msgid="+msgid
	//alert(msgid + "," + showzone)
    divid = "contentzone"+showzone
	loadzone = ""
	if(alias_name == "")
		document.getElementById("replyZone"+showzone).innerHTML = "<font color='red'><b>* Reply function will not be available until you login with your user name</b></font>"
	else
		document.getElementById("replyZone"+showzone).innerHTML = "<a href='javascript:void(0)' onclick='reply("+showzone+")'>[ Reply ]</a>"
	document.getElementById("msg"+showzone).value = msgid
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}

function ShowAll(msgid,showzone,postname)
{
	//alert(msgid+showzone)
	postby = postname
	var url= "showall.asp?msgid="+msgid+"&showzone="+showzone
	//alert(url)
    divid = "showzone"+showzone
	loadzone = "loadzone" + showzone
	document.getElementById(loadzone).innerHTML = "<img src='images/thloader.gif' />"
	for(var i=1;i<=20;i++)
	{
		if(i==showzone)
			document.getElementById("showzone"+i).style.display="inline"
		else
			document.getElementById("showzone"+i).style.display="none"
	}
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}

function DisplayStreet(geocodes)
{
	document.getElementById("map").innerHTML = "";
	myPano = new GStreetviewPanorama(document.getElementById("map"), panoramaOptions);	
	GEvent.addListener(myPano, "error", handleNoFlash);
	
}

function handleNoFlash(errorCode)
{
	if (errorCode == 603)
	{
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	}
}

function GetEditorialView(orderID)
{
	var obj = document.getElementById("editorialID"+orderID)
	var objvalue = obj.options[obj.selectedIndex].value
	loadzone = ""
	
	var url= "editorialview.asp?editorialID="+objvalue
    divid = "showroom"+orderID
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
	
	//document.getElementById("showroom"+orderID).innerHTML = "hello"
	
}

function jetcheck()
{
	if(document.getElementById("login").value == "")
	{
		alert("Please enter your login name")
		return false
	}
	if(document.getElementById("pwd").value == "")
	{
		alert("Please enter your password")
		return false
	}
	if(document.getElementById("strCAPTCHA").value == "")
	{
		alert("Please enter your verification code")	
		return false
	}
	
	return true
}

function checkvfcode()
{
	if(document.getElementById("strCAPTCHA").value == "")
	{
		alert("Please enter your verification code")	
		return false
	}
	return true

}

function removealias(alias_key)
{
	//alert(alias_key)
	document.getElementById("alias_key").value=alias_key
}
function DrawWinnerSmart()
{
	loadzone = ""
	joinfrom = document.getElementById("join_date_from").value
	jointo = document.getElementById("join_date_to").value
    var url= "clubwinnerlookup.asp?joinfrom=" + joinfrom + "&jointo=" + jointo
    divid = "clubwinner"
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
function DrawWinner()
{
	loadzone = ""
	document.getElementById("winnerdetails").innerHTML = ""
	var obj = document.getElementById("complist")
	var objvalue = obj.options[obj.selectedIndex].value
    var url= "competitorlookup.asp?compid=" + objvalue
    divid = "winneris"
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
function WinnerDetails(winnerID,comptype)
{
	loadzone = ""
	var url= "winnerdetails.asp?winnerid=" + winnerID + "&comptype=" + comptype
	//alert(url)
    if(comptype == 1)
		divid = "winnerdetails"
	else
		divid = "clubwinnerdetails"
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}

function GenRes()
{
	dtvalue = document.getElementById("dt").value;
	luvalue = document.getElementById("lu").value;
	

	if(dtvalue != "" && luvalue != "")
	{
		res = parseFloat(luvalue)*100
		res = res/parseFloat(dtvalue)
		res1 = res.toFixed(2)
		document.getElementById("litre").innerHTML = res.toFixed(2)
		
		res = parseFloat(dtvalue)/parseFloat(luvalue)
		document.getElementById("kilom").innerHTML = res.toFixed(2)
		
		res =  res * 2.82480848939
		document.getElementById("mpg").innerHTML = res.toFixed(2)
	}
	else
	{
		alert("The value of distance travelled and litres used are complusary")
	}
}
function clearNoNum(obj)
{
	obj.value = obj.value.replace(/[^\d.]/g,"");
	obj.value = obj.value.replace(/^\./g,"");
	obj.value = obj.value.replace(/\.{2,}/g,".");
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
function changeYear()
{
	var obj = document.getElementById("years")
	var objvalue = obj.options[obj.selectedIndex].value
	
	document.location.href = "statsviewslog.asp?y=" + objvalue
	//alert("statsviewslog.asp?y=" + objvalue)

}

function interchange(type,keyid,state,city,cname,baseip,email,firstpic)
{
	
	obj1 = document.getElementById("lvinterchange")
	switch(type)
	{
		case "lens":
			//obj1.innerHTML = "Thru the lens"
			obj1.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td colspan=2 valign='top' width=149 height=75 background='/images/thru_the_Lens_T.jpg' align='center'><a href='gallery/"+state+"/"+city+"/"+keyid+"/"+cname+"/accommodation/'><font color='#008000' face='Comic Sans MS' size='4'>Through<br>the lens</font></a></td><td rowspan=3 valign='top' width=101 height=211><img src='/images/thru_the_Lens_R.jpg' alt='Park Gallery'></td></tr><tr><td width=21 height=88><img src='/images/thru_the_Lens_L.jpg' alt='Park Gallery'></td><td id='VU' bgcolor='#ffffff' width=128 height=88><div align='center'><a href='/gallery/"+state+"/"+city+"/"+keyid+"/"+cname+"/accommodation/' ><img src='"+firstpic+"' id='SlideShow' alt='photo gallery' border=0 width='110' height='82'></a></div></td></tr><tr><td colspan=2 width=149 height=48 background='/images/thru_the_Lens_B.jpg' align='center'><a href='gallery/"+state+"/"+city+"/"+keyid+"/"+cname+"/accommodation/' ><small>more photos here</small></a></td></tr></table>"
			break;
		case "video":
			if(firstpic!=1)
				stopslide()
			obj1.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td valign='top'>"
			obj1.innerHTML = obj1.innerHTML + "<object id='player' height='220' width='240' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param NAME='AutoStart' VALUE='-1'><param NAME='Balance' VALUE='0'><param name='enabled' value='-1'><param NAME='EnableContextMenu' VALUE='-1'><param NAME='url' value='/streaming_media/"+keyid+"'><param NAME='PlayCount' VALUE='1'><param name='rate' value='1'><param name='currentPosition' value='0'><param name='currentMarker' value='0'><param name='defaultFrame' value=''><param name='invokeURLs' value='0'><param name='baseURL' value=''><param name='stretchToFit' value='0'><param name='volume' value='50'><param name='mute' value='0'><param name='uiMode' value='mini'><param name='windowlessVideo' value='0'><param name='fullScreen' value='0'><param name='enableErrorDialogs' value='-1'><param name='SAMIStyle' value><param name='SAMILang' value><param name='SAMIFilename' value></object>"
			obj1.innerHTML = obj1.innerHTML + "</td></tr></table>"
			break;
	}
	
}
//Count for ATDW DATA
function countATDW(baseIP,strKeyID,strStatID, strDiv)
{
	loadzone = ""
    var url= baseIP + "statslookup.asp?keyID=" + strKeyID + "&StatID=" + strStatID + "&ATDW=true"
    divid = strDiv
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
} 
 
//Count for GSA & GNZ DATA
function count(baseIP,strKeyID, strEmailAddress, strStatID, strDiv)
{
	loadzone = ""
    var url= baseIP + "statslookup.asp?keyID=" + strKeyID + "&Email=" + strEmailAddress + "&StatID=" + strStatID
    //alert(url)
	divid = strDiv
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
 
function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		if(divid!="booking")
	        document.getElementById(divid).innerHTML=xmlHttp.responseText
    }
}
 

function compus()
{
	alert("Please put in your trailer detail at STEP1")
	/*if(document.getElementById("ballweight").value!="" && document.getElementById("tareweight").value!="" && document.getElementById("maxweight").value!="")
		return true
	else
	{
		alert("Please put in your trailer detail at STEP1")
		return false
	}*/
}
 
//for towing compatability using
function getgross()
{
	loadzone = ""
	var ballweight = document.getElementById("ballweight").value	
	var tareweight = document.getElementById("tareweight").value
	var maxweight = document.getElementById("maxweight").value
	if(tareweight == "")
		tareweight = 0
	if(maxweight == "")
		maxweight = 0
	//document.getElementById("grossweight").innerHTML = parseInt(tareweight) + parseInt(maxweight)+ " KG"
	var url= "towing.asp?ttarew=" + tareweight + "&tmaxw=" + maxweight + "&tballw=" + ballweight
	divid = "grossweight"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
function reports(make,part,lug,trailer,ball)
{
	loadzone = ""
	var url = "towing.asp?vmake=" + make + "&vpart=" + part + "&lug=" + lug + "&trailer=" + trailer + "&ball=" + ball
	divid = "vdetails"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
	document.getElementById("genbutton").style.visibility = "visible"
	document.getElementById("vdetails").style.visibility = "visible"
}

function compt1(make,strDiv,baseIP,logo)
{
	loadzone = ""
	document.getElementById("detail").innerHTML = ""
	document.getElementById("report").innerHTML = ""
	document.getElementById("genbutton").style.visibility = "hidden"
    var url= baseIP + "towing.asp?make=" + make + "&logo=" + logo
	bip = baseIP
	divid = strDiv
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
function compt2(make,descp,strDiv)
{
	loadzone = ""
    var url= bip + "towing.asp?make=" + make + "&descp=" + descp
	divid = strDiv
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
	document.getElementById("genbutton").style.visibility = "hidden"
	document.getElementById("vdetails").innerHTML = ""
}

 
function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        if(divid == "winneris" || divid == "clubwinner")
		{
			//alert(xmlHttp.responseText)
			alldata = xmlHttp.responseText
			alldataarr = alldata.split("|")
			num = alldataarr.length-1
			start()
		}
		else
		{
			if(divid != "nodiv" && divid != "booking")
			{
				document.getElementById(divid).innerHTML=xmlHttp.responseText
				if(loadzone != "")
					document.getElementById(loadzone).innerHTML = ""
			}
		}
		//alert(xmlHttp.responseText)
    }
}

function change(){
    document.getElementById(divid).innerHTML = alldataarr[GetRnd(0,num)];
}

function start(){
    clearInterval(timer);
    timer = setInterval('change()',50);    //50（毫秒）为变换间隔，越小变换的越快
}

function ok(){
    clearInterval(timer);
}

function GetRnd(min,max){
    return parseInt(Math.random()*(max-min+1));
}

function GetXmlHttpObject(handler)
{
    var objXmlHttp=null
 
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        alert("Opera not supported...")
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
            return objXmlHttp
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled")
            return
        }
    }
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
}