﻿var map=null;var cb=null;var mapBounds=new GLatLngBounds();var rigMarkers=[];var rigNums=[];var gb=null;function load(element){if(GBrowserIsCompatible()){map=new GMap2(document.getElementById(element));map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.setCenter(new GLatLng(0, 0), 0);GetRigs();if (location.search.substring(1) != null)gb=location.search.substring(1);
}}var ib=false;function InitXmlHttp(){try{ib = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{ib=new ActiveXObject("Microsoft.XMLHTTP");}catch (E){ib = false;}}if(!ib && typeof XMLHttpRequest!='undefined'){ib=new XMLHttpRequest();}try{ib.onreadystatechange=SearchHandler;}catch(e){alert("An error has occured !");}}function LocateRig(jb){var kb=false;for(var i=0; i<rigMarkers.length;i++)
{var lb=rigMarkers[i].getTitle();if (lb != ""){if (jb == lb){map.setCenter(rigMarkers[i].getPoint(), 13);kb=true;}}}if(!kb){document.getElementById('messageText').value="No rig found !";document.getElementById('messageText').visible=true;}}function SearchRig(){if (document.getElementById('messageText').value!="")document.getElementById('messageText').value="";if(cb !=null)map.removeOverlay(cb);
var mb = null;if (document.getElementById('searchText').value!=""){mb = document.getElementById('searchText').value;}else{var nb=document.getElementById('selectText').selectedIndex;mb = document.getElementById('selectText')[nb].value;}var kb=false;for(var i=0;i<rigMarkers.length;i++){var lb=rigMarkers[i].getTitle();if (lb!=""){if(mb==lb&&!rigMarkers[i].isHidden()){
map.setCenter(rigMarkers[i].getPoint(), 13);kb = true;}}}if (kb==false){document.getElementById('messageText').value="No rig found !";document.getElementById('messageText').visible = true;}}function SearchHandler(){if(ib.readyState==4){try{eval(ib.responseText);if(location.search.substring(1)!=null){gb=location.search.substring(1);var ob=gb.substring(gb.indexOf("=")+1, gb.length); 
if (ob!= null&&ob!="")LocateRig(ob);}}catch(pb){alert("An error has occured !");}}}function FilterRigs(){InitXmlHttp();var qb=document.getElementById('selectType').selectedIndex;var rb=document.getElementById('selectType')[qb].value;var sb=document.getElementById('selectDepth').selectedIndex;var tb=document.getElementById('selectDepth')[sb].value;var ub="GoogleHandler.ashx?funct=FilterRigs("+rb+","+tb+")";
ib.open("GET",ub,true);ib.send(null);}function GetRigs(){InitXmlHttp();var ub="GoogleHandler.ashx?funct=GetRigs";ib.open("GET",ub,true);ib.send(null);}var icon=new GIcon();icon.image = "http://www.trinidaddrilling.com/Images/rig2.png";icon.iconSize=new GSize(21, 21);icon.iconAnchor=new GPoint(9,21);icon.infoWindowAnchor=new GPoint(9,2);function AddOptions(){document.getElementById('selectText').length=0;for(var i=0;i<rigMarkers.length;i++)
{if (!rigMarkers[i].isHidden()){var wb=rigMarkers[i].getTitle();if (wb!=""){try{var xb=document.getElementById('selectText');var option=document.createElement("OPTION");option.innerHTML=wb;option.value=wb;xb.appendChild(option);}catch(yb){alert("An error has occured !");}}}}}function CreateRadius(){if(document.getElementById('Radio1').checked==true){if(ValidateDLS())CreateDLSRadius();else alert("Please enter valid township(1-126) and range(1-36) values");
}else if (document.getElementById('Radio2').checked == true){if(ValidateNTS())CreateNTSRadius();else alert("Please enter a valid unit(1-100) value");}}function ValidateDLS(){var zb=new RegExp("[0-9]");if ((document.getElementById('townshipText').value=="")||(document.getElementById('rangeText').value=="")||(document.getElementById('townshipText').value<1)||(document.getElementById('townshipText').value>126)||(document.getElementById('rangeText').value<1)||
(document.getElementById('rangeText').value>36)||(!zb.test(document.getElementById('rangeText').value))||(!zb.test(document.getElementById('townshipText').value)))return false;else return true;}function ValidateNTS(){var zb=new RegExp("[0-9]");if((document.getElementById('unitText').value=="")||(document.getElementById('unitText').value<1)||(document.getElementById('unitText').value>100)||(!zb.test(document.getElementById('unitText').value))) 
return false;else return true;}function CreateDLSRadius(){try{var $b=document.getElementById('lsdSelect').selectedIndex;var _b=document.getElementById('lsdSelect')[$b].value;var ac=document.getElementById('sectionSelect').selectedIndex;var bc=document.getElementById('sectionSelect')[ac].value;var cc=document.getElementById('townshipText').value;var dc=document.getElementById('rangeText').value;var ec=document.getElementById('meridianSelect').selectedIndex;
var fc=document.getElementById('meridianSelect')[ec].value;var gc=document.getElementById('radiusSelect').selectedIndex;var hc=document.getElementById('radiusSelect')[gc].value;InitXmlHttp();var ub="GoogleHandler.ashx?funct=DLSConvert("+_b+","+bc+","+cc+","+dc+","+fc+","+hc+")" ;ib.open("GET",ub,true);ib.send(null);}catch(yb){alert("An error has occured !");}}function CreateNTSRadius(){try{var ic=document.getElementById('quarterSelect').selectedIndex;
var jc=document.getElementById('quarterSelect')[ic].value;var kc=document.getElementById('unitText').value;var lc=document.getElementById('blockSelect').selectedIndex;var mc=document.getElementById('blockSelect')[lc].value;var nc=document.getElementById('mapSheetSelect').selectedIndex;var oc=document.getElementById('mapSheetSelect')[nc].value;var pc=document.getElementById('subdivisionSelect').selectedIndex;var qc=document.getElementById('subdivisionSelect')[pc].value;
var rc=document.getElementById('mapUnitSelect').selectedIndex;var sc=document.getElementById('mapUnitSelect')[rc].value;var gc=document.getElementById('radiusSelect').selectedIndex;var hc=document.getElementById('radiusSelect')[gc].value;InitXmlHttp();var ub="GoogleHandler.ashx?funct=NTSConvert("+jc+","+kc+","+mc+","+oc+","+qc+","+sc+","+hc+")";ib.open("GET",ub,true);ib.send(null);}catch(yb){alert("An error has occured !");
}}function drawCircle(uc,vc,hc){if (cb!=null){map.removeOverlay(cb);}var wc=new GLatLngBounds();map.setCenter(new GLatLng(uc,vc),0);var xc=6371;var yc=(uc * Math.PI)/180;var zc=(vc * Math.PI)/180;var d=parseFloat(hc)/xc;var $c=new Array();for(x=0;x<= 360;x++){_c=x*Math.PI/180;var ad=Math.asin(Math.sin(yc)*Math.cos(d)+Math.cos(yc)*Math.sin(d)*Math.cos(_c));var bd=((zc+Math.atan2(Math.sin(_c)*Math.sin(d)*Math.cos(yc),Math.cos(d)-Math.sin(yc)*Math.sin(ad)))*180)/Math.PI;
ad=(ad*180)/Math.PI;var cd=new GLatLng(ad,bd);$c.push(cd);wc.extend(cd);}map.setZoom(map.getBoundsZoomLevel(wc)-1);cb=new GPolygon($c,"#339999",5,0.1,"#848484",0.25);map.addOverlay(cb);}function RedirectToDetails(dd){try{opener.location.href="/Rigs/CanadianRigDetails.aspx?ID="+dd;opener.focus();dd=null;}catch(pb){alert("An error has occured !");}}
