
// NRMA Travel Planner Widget
// Version 1.0

// URL to Trip Planner
window.TRIP_PLANNER_URL="http://www.drivethere.com.au/";
// URL to Book a Room
window.BOOK_A_ROOM_URL="http://www.mynrma.com.au/cps/rde/xchg/mynrma/hs.xsl/nrma_accommodation.htm";

if(window.devnet===undefined){window.devnet={}}

if(window.devnet.tripplanner===undefined){window.devnet.tripplanner={}}

if(window.devnet.util===undefined){window.devnet.util={}}

(
function()
{
devnet.tripplanner.Widget=function(){};

devnet.tripplanner.Widget.prototype=
{
from_:null,to_:null,render:function(el){var container=document.getElementById(el),wrapper=this.createWrapper_(),topSection=this.createTopSection_(),form=this.createForm_(),example=this.createExample_(),bottom=this.createBottom_();wrapper.inject(container);topSection.inject(wrapper);form.inject(wrapper);example.inject(wrapper);bottom.inject(wrapper)},createWrapper_:function(){return new devnet.util.Element("div","","partTravel")},createTopSection_:function(){var el=new devnet.util.Element("div","","top"),heading=new devnet.util.Element("h2"),text=new devnet.util.Element("p");heading.set("html","Travel Planner");text.set("html","Map your travel route and find accommodation &amp; attractions.");heading.inject(el);text.inject(el);return el},createForm_:function(){var el=new devnet.util.Element("div"),fromLabel=new devnet.util.Element("label"),fromInput=new devnet.util.Element("input"),toLabel=new devnet.util.Element("label"),toInput=new devnet.util.Element("input"),button=new devnet.util.Element("input"),me=this;fromLabel.set("html","From:");fromLabel.set("styles",{"float":"left",padding:"0px 5px 0px 0px"});fromInput.set("styles",{"float":"left",width:"130px"});fromInput.set("type","text");toLabel.set("html","To:");toLabel.set("styles",{"float":"left",padding:"0px 5px 0px 10px"});toInput.set("type","text");toInput.set("styles",{"float":"left",width:"130px"});button.set("type","button");button.set("value","Go");button.set("click",function(){var se=new devnet.util.SimpleEnc(),to=me.to_.get("value"),from=me.from_.get("value"),str=from+"||"+to,encode=se.encode(str);window.location.href=TRIP_PLANNER_URL+"?e="+encodeURIComponent(encode)});button.set("styles",{margin:"0px 0px 0px 10px"});fromLabel.inject(el);fromInput.inject(el);toLabel.inject(el);toInput.inject(el);button.inject(el);this.from_=fromInput;this.to_=toInput;return el},createExample_:function(){var el=new devnet.util.Element("div");el.set("html","Example: Sydney, NSW");el.set("styles",{"font-style":"oblique",color:"#999999"});return el},createBottom_:function(){var el=new devnet.util.Element("div","","bottom"),left=new devnet.util.Element("div","","left"),right=new devnet.util.Element("div","","right"),clear=new devnet.util.Element("div","","clear"),getDirection=new devnet.util.Element("a"),bookRoom=new devnet.util.Element("a");getDirection.set("target","blank");getDirection.set("href",TRIP_PLANNER_URL);getDirection.set("html","Get directions >");getDirection.inject(left);bookRoom.set("target","blank");bookRoom.set("href",BOOK_A_ROOM_URL);bookRoom.set("html","Book a room >");bookRoom.inject(right);left.inject(el);right.inject(el);clear.inject(el);return el}
};

devnet.util.Element=function(type,id,cn)
{cn=cn||"";id=id||"";this.el=document.createElement(type);if(id.length>0){this.el.setAttribute("id",id)}if(cn.length>0){this.el.setAttribute("class",cn)}};

devnet.util.Element.prototype={type_:"[object DevnetUtilElement]",set:function(type,value){switch(type){case"html":this.el.innerHTML=value;break;case"styles":for(var style in value){if(value.hasOwnProperty(style)){var jsStyle="";var seg=style.split("-");for(var i=0;i<seg.length;i+=1){if(i===0){jsStyle+=seg[i]}else{jsStyle+=seg[i].substr(0,1).toUpperCase()+seg[i].substr(1,seg[i].length-1)}}if(jsStyle==="float"){jsStyle="cssFloat"}eval("this.el.style."+jsStyle+" = value[style]")}}break;case"click":devnet.util.addEvent(this.el,"click",value);break;default:eval("this.el."+type+" = value")}},get:function(type){if(type==="html"){return this.el.innerHTML}else{return eval("this.el."+type)}},inject:function(parent){parent.appendChild(this.el)},toString:function(){return this.type_},appendChild:function(el){this.el.appendChild(el)}};

devnet.util.addEvent=function(obj,evType,fn,useCapture)
{useCapture=useCapture||false;if(obj.addEventListener){obj.addEventListener(evType,fn,useCapture);return true}else{if(obj.attachEvent){var r=obj.attachEvent("on"+evType,fn);return r}}};

devnet.util.SimpleEnc=function(){};

devnet.util.SimpleEnc.prototype=
{dchar_:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","W","Z","1","2","3","4","5","6","7","8","9","0",",","|"],echar_:["2","c","E","k","N","7","H","w","R","q","9","G","a","Z","n","4","F","g","K","M","0","o","V","y","d","A","5","l","I","Q","e","3","s","U","Y",",","8","j","D","J","O","u","r","b","C","S","x","W","h","B","P","m","i","L","z","t","p","T","v","f","X","1","6","@"],getEncChar_:function(chr){var enc=chr;for(var i=0;i<this.dchar_.length;i+=1){var c=this.dchar_[i];if(c===chr){enc=this.echar_[i];break}}return enc},getDecChar_:function(chr){var dec=chr;for(var i=0;i<this.echar_.length;i+=1){var c=this.echar_[i];if(c===chr){dec=this.dchar_[i];break}}return dec},encode:function(str){var enc="";for(var i=0;i<str.length;i+=1){enc+=this.getEncChar_(str.charAt(i))}return enc},decode:function(str){var dec="";for(var i=0;i<str.length;i+=1){dec+=this.getDecChar_(str.charAt(i))}return dec}
}

}()
);



function formOk()
{


if (document.tripplanner.txtFrom.value == "" || document.tripplanner.txtTo.value == "")
{return false;}

devnet.util.SimpleEnc.prototype=
{
dchar_:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","W","Z","1","2","3","4","5","6","7","8","9","0",",","|"],echar_:["2","c","E","k","N","7","H","w","R","q","9","G","a","Z","n","4","F","g","K","M","0","o","V","y","d","A","5","l","I","Q","e","3","s","U","Y",",","8","j","D","J","O","u","r","b","C","S","x","W","h","B","P","m","i","L","z","t","p","T","v","f","X","1","6","@"],getEncChar_:function(chr){var enc=chr;for(var i=0;i<this.dchar_.length;i+=1){var c=this.dchar_[i];if(c===chr){enc=this.echar_[i];break}}return enc},getDecChar_:function(chr){var dec=chr;for(var i=0;i<this.echar_.length;i+=1){var c=this.echar_[i];if(c===chr){dec=this.dchar_[i];break}}return dec},encode:function(str){var enc="";for(var i=0;i<str.length;i+=1){enc+=this.getEncChar_(str.charAt(i))}return enc},decode:function(str){var dec="";for(var i=0;i<str.length;i+=1){dec+=this.getDecChar_(str.charAt(i))}return dec}
}
	
	var fromTown = document.tripplanner.txtFrom.value + ', ' + document.tripplanner.fromState.options[document.tripplanner.fromState.selectedIndex].value;
	var toTown = document.tripplanner.txtTo.value + ', ' + document.tripplanner.toState.options[document.tripplanner.toState.selectedIndex].value;

	//alert('From: ' + fromTown);
	//alert('To: ' + toTown);
	
	var se=new devnet.util.SimpleEnc(), to=toTown, from=fromTown, str=from+"||"+to, encode=se.encode(str);
	//alert('encode:' + encode + 'e=' +encodeURIComponent(encode));
	//window.location.href = 'http://www.drivethere.com.au/?e=' + encodeURIComponent(encode);
	
	window.open('http://www.drivethere.com.au/?e=' + encodeURIComponent(encode));
}

function formOk2()
{

if (document.tripplanner2.txtPlace.value == "")
{return false;}

devnet.util.SimpleEnc.prototype=
{
dchar_:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","W","Z","1","2","3","4","5","6","7","8","9","0",",","|"],echar_:["2","c","E","k","N","7","H","w","R","q","9","G","a","Z","n","4","F","g","K","M","0","o","V","y","d","A","5","l","I","Q","e","3","s","U","Y",",","8","j","D","J","O","u","r","b","C","S","x","W","h","B","P","m","i","L","z","t","p","T","v","f","X","1","6","@"],getEncChar_:function(chr){var enc=chr;for(var i=0;i<this.dchar_.length;i+=1){var c=this.dchar_[i];if(c===chr){enc=this.echar_[i];break}}return enc},getDecChar_:function(chr){var dec=chr;for(var i=0;i<this.echar_.length;i+=1){var c=this.echar_[i];if(c===chr){dec=this.dchar_[i];break}}return dec},encode:function(str){var enc="";for(var i=0;i<str.length;i+=1){enc+=this.getEncChar_(str.charAt(i))}return enc},decode:function(str){var dec="";for(var i=0;i<str.length;i+=1){dec+=this.getDecChar_(str.charAt(i))}return dec}
}
	
	var place = document.tripplanner2.txtPlace.value + ', ' + document.tripplanner2.placeState.options[document.tripplanner2.placeState.selectedIndex].value;
	
	var se=new devnet.util.SimpleEnc(), to=place, from=place, str=from+"||"+to, encode=se.encode(str);
	//alert('encode:' + encode + 'e=' +encodeURIComponent(encode));
	//window.location.href = 'http://www.drivethere.com.au/?e=' + encodeURIComponent(encode);
	
	window.open('http://www.drivethere.com.au/?e=' + encodeURIComponent(encode));
}

