var jsonTree="";var ajaxBaseUrl="http://www.superbreak.com/";var $sf_j=jQuery.noConflict();function ClearOption(divName,text,disabled){$sf_j("#"+divName).attr("disabled",disabled).empty().append("<option value=\"\">"+text+"</option>")}function CreateOption(selectName,value,text){$sf_j("#"+selectName).append("<option value=\""+value+"\">"+text+"</option>")}function Trim(text){if($sf_j.browser.msie&&text.length>15){text=text.substring(0,14)+"..."}return text}function GetLocationTree(type){$sf_j.ajax({type:"GET",url:ajaxBaseUrl+"locations/tree/jsonp",dataType:"jsonp",data:{type:type},success:function(data){PopulateTree(data)}})}function PopulateTree(data){jsonTree=data;$sf_j.each(jsonTree.LocationTree.Location,function(i,item){$sf_j("#topLoc").append("<optgroup label=\""+Trim(item.Name)+"\">");$sf_j.each(item.Location,function(j,topLoc){$sf_j("#topLoc").append("<option value=\""+topLoc.Code+"\">"+Trim(topLoc.Name)+"</option>");if(topLoc.Location!=null&&$sf_j("#topLoc").val()==topLoc.Code){ClearOption("secondLoc",Trim("Choose an optional region"),"");$sf_j.each(topLoc.Location,function(k,secondLoc){CreateOption("secondLoc",secondLoc.Code,Trim(secondLoc.Name))})}});$sf_j("#topLoc").append("</optgroup>")})}$sf_j(function(){ClearOption("secondLoc",Trim("No optional regional choices"),"disabled");ClearOption("thirdLoc",Trim("No optional location choices"),"disabled");GetLocationTree("fts");$sf_j("#topLoc").change(function(){ClearOption("secondLoc",Trim("No optional regional choices"),"disabled");ClearOption("thirdLoc",Trim("No optional location choices"),"disabled");$sf_j.each(jsonTree.LocationTree.Location,function(i,item){$sf_j.each(item.Location,function(j,topLoc){if(topLoc.Code==$sf_j("#topLoc").val()&&topLoc.Location!=null){ClearOption("secondLoc",Trim("Choose an optional region"),"");$sf_j.each(topLoc.Location,function(k,secondLoc){CreateOption("secondLoc",secondLoc.Code,Trim(secondLoc.Name))})}})})});$sf_j("#secondLoc").change(function(){ClearOption("thirdLoc",Trim("No optional location choices"),"disabled");$sf_j.each(jsonTree.LocationTree.Location,function(i,item){$sf_j.each(item.Location,function(j,topLoc){if(topLoc.Code==$sf_j("#topLoc").val()){$sf_j.each(topLoc.Location,function(k,secondLoc){if(secondLoc.Code==$sf_j("#secondLoc").val()&&secondLoc.Location!=null){ClearOption("thirdLoc",Trim("Choose an optional location"),"");$sf_j.each(secondLoc.Location,function(l,thirdLoc){CreateOption("thirdLoc",thirdLoc.Code,Trim(thirdLoc.Name))})}})}})})})});
