﻿// JScript File

function createRequestObject()
{		
	var request_obj ;
	var browser = navigator.appName ;

	if (browser == "Microsoft Internet Explorer")
	{
	 request_obj = new ActiveXObject("Microsoft.XMLHttp");
	 } 
	else
	{
	request_obj = new XMLHttpRequest();
	 }
	
	 return request_obj
 }
 var http1 = createRequestObject();
 var http2 = createRequestObject();
 var httpmap = createRequestObject();
 
 function handledatabind1()
{
		if (http1.readyState==1)
		{
		document.getElementById('divload').innerHTML = "Loading...";
		}
		if (http1.readyState==4)
		{
		var response =  http1.responseText;
		document.getElementById('divmiddle').innerHTML = response;
		document.getElementById('divload').innerHTML ="";
		}
}
 function handledatabind_coursesearch()
{
		if (http1.readyState==1)
		{
		document.getElementById('divload').innerHTML = "Loading...";
		}
		if (http1.readyState==4)
		{
		   
		    var response =  http1.responseText;
		    document.getElementById('divmiddle').innerHTML = response;
		    document.getElementById('divload').innerHTML ="";
		   // fnloadcoursesearchmap();
		}
}
function handledatabind2()
{
		if (http2.readyState==1)
		{
		    
		}
		if (http2.readyState==4)
		{
		    var response =  http2.responseText;
		    document.getElementById('divtags').innerHTML = response;
		   
		}
}
	
function Course_Submit()
{
     //alert("ok" + document.form1.txtcoursename.value);
    if(document.form1.txtcoursename.value == "")
    {
        alert("Enter Course Name");
        document.form1.txtcoursename.focus();
        return false
    }
    var coursename = Trim(document.form1.txtcoursename.value);
    coursename = coursename.toLowerCase();
    if((coursename.length) < 4)
    {
        alert("Invalid Course Name");
        document.form1.txtcoursename.focus();
        return false
    }
    if(coursename == "the" || coursename == "and" || coursename == "golf" || coursename == "golf course" || coursename == "club" || coursename == "course" || coursename == "country" || coursename == "at")
    {
        alert("Invalid Course Name");
        document.form1.txtcoursename.focus();
        return false
    }
    var srch = document.form1.txtcoursename.value;
    var vmaptype="1";
    /*if(document.getElementById("rdbtngoogle").checked)
    {
        vmaptype="1";
    }else if(document.getElementById("rdbtnyahoo").checked)
    {
        vmaptype="2";
    
    }
    */
    if(check_words(srch))
    {   
        http1.open('get','coursesearch.php?srchtxt=' + srch + '&maptype='+vmaptype);
	    http1.onreadystatechange = handledatabind1;
	    http1.send(null);
    }
    else
    {
        alert("Invalid Course Name");
        document.form1.txtcoursename.focus();
        return false
    }
}
function CourseSearch_Submit()
{
    
    if(document.form1.txtscoursename.value == "")
    {
        alert("Enter Course Name");
        document.form1.txtscoursename.focus();
        return false
    }
    var coursename = Trim(document.form1.txtscoursename.value);
    coursename = coursename.toLowerCase();
    if((coursename.length) < 4)
    {
        alert("Invalid Course Name");
        document.form1.txtcoursename.focus();
        return false
    }
    if(coursename == "the" || coursename == "and" || coursename == "golf" || coursename == "golf course" || coursename == "club" || coursename == "course" || coursename == "country" || coursename == "at")
    {
        alert("Invalid Course Name");
        document.form1.txtscoursename.focus();
        return false
    }
    var srch = document.form1.txtscoursename.value;
    var vmaptype="1";
    /*if(document.getElementById("rdbtngoogle").checked)
    {
        vmaptype="1";
    }else if(document.getElementById("rdbtnyahoo").checked)
    {
        vmaptype="2";
    
    }
    */
    if(check_words(srch))
    {   
        location.href = 'coursesearch.php?srchtxt=' + srch;
    }
    else
    {
        alert("Invalid Course Name");
        document.form1.txtscoursename.focus();
        return false
    }
    document.form1.txtscoursename.value="";
}

function check_words(wrds)
{
    var wrdresult = false;
    var wrdsplit = wrds.split(" ");
    var leng = (parseInt(wrdsplit.length));
    for(var i=0; i<leng; i++)
    {
        var w1 = wrdsplit[i];
        if(w1 == "the" || w1 == "and" || w1 == "golf" || w1 == "golf course" || w1 == "club" || w1 == "course" || w1 == "country" || w1 == "at")
        {
            wrdresult = false;
            
        }
        else
        {
            wrdresult = true;
            return wrdresult;
        }
    }
    return wrdresult;
}

function Course_Map(cid)
{
    var vmaptype="1";    
    if(document.getElementById("rdbtngoogle").checked)
    {
        vmaptype="1";        
    }else if(document.getElementById("rdbtnyahoo").checked)
    {
        vmaptype="2";        
    }
    else if(document.getElementById("rdbtnVE").checked)
    {
        vmaptype="3";
    }
	vmaptype = 1;
	location.href = 'CourseMap.php?srid=' + cid + '&cpg=1&maptype='+vmaptype;
	/*httpmap.open('get','CourseMap.php?srid=' + cid + '&cpg=1&maptype='+vmaptype);
	httpmap.onreadystatechange = handledatabindmap;
	httpmap.send(null); */
	
}

function handledatabindmap()
{
	if (httpmap.readyState==1)
	{
	    document.getElementById('divload').innerHTML = "Loading...";
	}
	if (httpmap.readyState==4)
	{
	    var response =  httpmap.responseText;
	    document.getElementById('divmiddle').innerHTML = response;
	    document.getElementById('divload').innerHTML ="";
	    try
	    {
	        fnloadvirtualearthmapchk();
	    }catch(ex1)
	    {
	        
	    }    
	    try
	    {
	        fnloadmap();
	        
	    }catch(ex)
	    {
	        
	    }   
	    
	}
}

function course_map_back()
{
    var cid = document.form1.hidlistid.value;
    var cpg = document.form1.lbl_curr_page_num.value;
    var cre = document.form1.intCurrIndex.value;
    httpmap.open('get','CourseMap.php?srid=' + cid + '&cpg=' + cpg + '&back=1&cre=' + cre +'&vmaptype=1');
	httpmap.onreadystatechange = handledatabindmap;
	httpmap.send(null);
}

function course_map_next()
{
    var cid = document.form1.hidlistid.value;
    var cpg = document.form1.lbl_curr_page_num.value;
    var cre = document.form1.intCurrIndex.value;
    httpmap.open('get','CourseMap.php?srid=' + cid + '&cpg=' + cpg + '&next=1&cre=' + cre +'&vmaptype=1');
	httpmap.onreadystatechange = handledatabindmap;
	httpmap.send(null);
}

function Contact_Submit()
{
    if(document.form1.txtname.value == "")
    {
        alert("Enter Name");
        document.form1.txtname.focus();
        return false
    }
    else if(document.form1.txtemail.value == "")
    {
        alert("Enter Email");
        document.form1.txtemail.focus();
        return false
    }
    else if(isValidEmail(document.form1.txtemail.value) == false) 
	{
		alert('Invalid Email');
		document.form1.txtemail.focus();
		return false
	} 
    var name = document.form1.txtname.value;
	var topindex = document.form1.ddltopic.selectedIndex;
	var topic = document.form1.ddltopic.options[topindex].text;
    var email = document.form1.txtemail.value;
    var company = document.form1.txtcompany.value;
    var message = document.form1.txtmessage.value;
	 
    http1.open('get','Contact.php?subm=1&nam=' + name +'&eml=' + email + '&comp=' + company + '&mssg=' + message + '&topc=' + topic + '');
	http1.onreadystatechange = handledatabind1;
	http1.send(null);
}


function Contact_Clear()
{
    document.form1.txtname.value = "";
    document.form1.ddltopic.selectedIndex = "0";
    document.form1.txtemail.value = "";
    document.form1.txtcompany.value = "";
    document.form1.txtmessage.value = "";
    document.form1.txtname.focus();
}

function isValidEmail(val)
{
 var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
 if (!val.match(re))
	{
		return false;
	} 
 else 
	{
		return true;
	}
}

function fnloadmap()
{
  var lat1,long1;
  var d= document.form1;
                          
  lat1 = d.hidlat1.value;
  long1 = d.hidlong1.value;
  
  var zoomlvl = d.hidzoom.value;
  zoomlvl = parseInt(zoomlvl);
  
  if(zoomlvl == 1)
  {
    zoomlvl = -1;
  }
  else if(zoomlvl == 2)
  {
    zoomlvl = -2;
  }
  //zoomlvl = parseInt(zoomlvl - 4);
  
  var map = new GMap(document.getElementById("map"));
  map.removeMapType(G_NORMAL_MAP);
  map.removeMapType(G_HYBRID_MAP);
  var givenmaptypes = map.getMapTypes();
  map.setMapType(givenmaptypes[1]);
  
  map.centerAndZoom(new GPoint(long1,lat1), zoomlvl); 
  map.disableDragging();
}

function IsNumber(strString)
{
       var strValidChars = "0123456789-";
       var strChar;
       var blnResult = true;

       for (i = 0; i < strString.length && blnResult == true; i++)
          {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
             blnResult = false;
             }
          }
       return blnResult;
}
 
function replaceCharacters(orgstring) 
{
    var s = "" + orgstring + "";
    var p;
    p = s.split(",");
    var latx;
    latx = p[0].split("(");
    var longx;
    longx = p[1].split("(");
    var lx = longx[0].split(")");
    var xy = latx[2] + "," + lx[0];
    return xy;
}


function fn_submitdata()
{
     if(document.form1.txtname.value == "")
        {
            alert("Enter Name");
            document.form1.txtname.focus();
            return false
        }
        if(document.form1.txtaddress.value == "")
        {
            alert("Enter Address");
            document.form1.txtaddress.focus();
            return false
        }
        if(document.form1.txtemailaddr.value == "")
        {
            alert("Enter Email");
            document.form1.txtemailaddr.focus();
            return false
        }
        if(isValidEmail(document.form1.txtemailaddr.value) == false)
        {   
            alert("Invalid Email");
            document.form1.txtemailaddr.focus();
            return false
        }
        if(document.form1.hidcount.value == "0")
        {
            alert("Select atleast one Location to Enter");
            document.form1.txtaddress.focus();
            return false
        }
        
        var name = document.form1.txtname.value;
        var address = document.form1.txtaddress.value;
        var status = document.form1.txtstatus.value;
        var ph = document.form1.txtphone.value;
        var eml = document.form1.txtemailaddr.value;
        var cnt = document.form1.hidcount.value;
        var lati = document.form1.hidlatitudes.value;
        var longi = document.form1.hidlongitudes.value;
        var parv = document.form1.hidpar.value;
        var holen = document.form1.hidholeno.value;
        
        
        http1.open('get','CourseMapping.php?subm=1&nam=' + name +'&addr=' + address + '&stat=' + status + '&phone=' + ph + '&email=' + eml + '&lati=' + lati + '&longi=' + longi + '&par=' + parv + '&hol=' + holen + '&count=' + cnt + '');
	    http1.onreadystatechange = handledatabind1;
	    http1.send(null);
}

function fnrequestcourse()
{   
    win = window.open('mailto:support@viewti.com','emailWindow');
    if (win && win.open &&!win.closed) win.close();
     

    return false;
}

function fnloadvirtualearthmapchk()
{
     //alert("test" + document.getElementById("hidlatitude13").value);
     GetVEMap();
     return false;
}
function GetVEMap()
{
    //alert("test");
    VEmap1 = new VEMap('VEmap1');
    VEmap1.LoadMap();
    var latidisp,longdisp;
    latidisp = document.form1.hidlatitude1.value;
    longdisp = document.form1.hidlongitude1.value;
    var latLong01 = new VELatLong(latidisp, longdisp);
    VEmap1.SetCenterAndZoom(latLong01, 10);	
    VEmap1.SetMapStyle(VEMapStyle.Birdseye); 
    
    VEmap2 = new VEMap('VEmap2');
    VEmap2.LoadMap();
    var latidisp2,longdisp2;
    latidisp2 = document.form1.hidlatitude2.value;
    longdisp2 = document.form1.hidlongitude2.value;
    var latLong02 = new VELatLong(latidisp2, longdisp2);
    VEmap2.SetCenterAndZoom(latLong02, 10);	
    VEmap2.SetMapStyle(VEMapStyle.Birdseye); 
    
    VEmap3 = new VEMap('VEmap3');
    VEmap3.LoadMap();
    var latidisp3,longdisp3;
    latidisp3 = document.form1.hidlatitude3.value;
    longdisp3 = document.form1.hidlongitude3.value;
    var latLong03 = new VELatLong(latidisp3, longdisp3);
    VEmap3.SetCenterAndZoom(latLong03, 10);	
    VEmap3.SetMapStyle(VEMapStyle.Birdseye);
    
    VEmap4 = new VEMap('VEmap4');
    VEmap4.LoadMap();
    var latidisp4,longdisp4;
    latidisp4 = document.form1.hidlatitude4.value;
    longdisp4 = document.form1.hidlongitude4.value;
    var latLong04 = new VELatLong(latidisp4, longdisp4);
    VEmap4.SetCenterAndZoom(latLong04, 10);	
    VEmap4.SetMapStyle(VEMapStyle.Birdseye);
    
    VEmap5 = new VEMap('VEmap5');
    VEmap5.LoadMap();
    var latidisp5,longdisp5;
    latidisp5 = document.form1.hidlatitude5.value;
    longdisp5 = document.form1.hidlongitude5.value;
    var latLong05 = new VELatLong(latidisp5, longdisp5);
    VEmap5.SetCenterAndZoom(latLong05, 10);	
    VEmap5.SetMapStyle(VEMapStyle.Birdseye);
    
    VEmap6 = new VEMap('VEmap6');
    VEmap6.LoadMap();
    var latidisp6,longdisp6;
    latidisp6 = document.form1.hidlatitude6.value;
    longdisp6 = document.form1.hidlongitude6.value;
    var latLong06 = new VELatLong(latidisp6, longdisp6);
    VEmap6.SetCenterAndZoom(latLong06, 10);	
    VEmap6.SetMapStyle(VEMapStyle.Birdseye);
    
    VEmap7 = new VEMap('VEmap7');
    VEmap7.LoadMap();
    var latidisp7,longdisp7;
    latidisp7 = document.form1.hidlatitude7.value;
    longdisp7 = document.form1.hidlongitude7.value;
    var latLong07 = new VELatLong(latidisp7, longdisp7);
    VEmap7.SetCenterAndZoom(latLong07, 10);	
    VEmap7.SetMapStyle(VEMapStyle.Aerial);
    
    VEmap8 = new VEMap('VEmap8');
    VEmap8.LoadMap();
    var latidisp8,longdisp8;
    latidisp8 = document.form1.hidlatitude8.value;
    longdisp8 = document.form1.hidlongitude8.value;
    var latLong08 = new VELatLong(latidisp8, longdisp8);
    VEmap8.SetCenterAndZoom(latLong08, 10);	
    VEmap8.SetMapStyle(VEMapStyle.Aerial);
    
    VEmap9 = new VEMap('VEmap9');
    VEmap9.LoadMap();
    var latidisp9,longdisp9;
    latidisp9 = document.form1.hidlatitude9.value;
    longdisp9 = document.form1.hidlongitude9.value;
    var latLong09 = new VELatLong(latidisp9, longdisp9);
    VEmap9.SetCenterAndZoom(latLong09, 10);	
    VEmap9.SetMapStyle(VEMapStyle.Aerial);
     
    VEmap10 = new VEMap('VEmap10');
    VEmap10.LoadMap();
    var latidisp10,longdisp10;
    latidisp10 = document.form1.hidlatitude10.value;
    longdisp10 = document.form1.hidlongitude10.value;
    var latLong010 = new VELatLong(latidisp10, longdisp10);
    VEmap10.SetCenterAndZoom(latLong010, 10);	
    
    VEmap11 = new VEMap('VEmap11');
    VEmap11.LoadMap();
    var latidisp11,longdisp11;
    latidisp11 = document.form1.hidlatitude11.value;
    longdisp11 = document.form1.hidlongitude11.value;
    var latLong011 = new VELatLong(latidisp11, longdisp11);
    VEmap11.SetCenterAndZoom(latLong011, 11);	
    
    VEmap12 = new VEMap('VEmap12');
    VEmap12.LoadMap();
    var latidisp12,longdisp12;
    latidisp12 = document.form1.hidlatitude12.value;
    longdisp12 = document.form1.hidlongitude12.value;
    var latLong012 = new VELatLong(latidisp12, longdisp12);
    VEmap12.SetCenterAndZoom(latLong012, 12);	
    
    VEmap13 = new VEMap('VEmap13');
    VEmap13.LoadMap();
    var latidisp13,longdisp13;
    latidisp13 = document.form1.hidlatitude13.value;
    longdisp13 = document.form1.hidlongitude13.value;
    var latLong013 = new VELatLong(latidisp13, longdisp13);
    VEmap13.SetCenterAndZoom(latLong013, 13);	
    
    VEmap14 = new VEMap('VEmap14');
    VEmap14.LoadMap();
    var latidisp14,longdisp14;
    latidisp14 = document.form1.hidlatitude14.value;
    longdisp14 = document.form1.hidlongitude14.value;
    var latLong014 = new VELatLong(latidisp14, longdisp14);
    VEmap14.SetCenterAndZoom(latLong014, 14);	
    
    VEmap15 = new VEMap('VEmap15');
    VEmap15.LoadMap();
    var latidisp15,longdisp15;
    latidisp15 = document.form1.hidlatitude15.value;
    longdisp15 = document.form1.hidlongitude15.value;
    var latLong015 = new VELatLong(latidisp15, longdisp15);
    VEmap15.SetCenterAndZoom(latLong015, 15);	
    
    VEmap16 = new VEMap('VEmap16');
    VEmap16.LoadMap();
    var latidisp16,longdisp16;
    latidisp16 = document.form1.hidlatitude16.value;
    longdisp16 = document.form1.hidlongitude16.value;
    var latLong016 = new VELatLong(latidisp16, longdisp16);
    VEmap16.SetCenterAndZoom(latLong016, 16);	
    
    VEmap17 = new VEMap('VEmap17');
    VEmap17.LoadMap();
    var latidisp17,longdisp17;
    latidisp17 = document.form1.hidlatitude17.value;
    longdisp17 = document.form1.hidlongitude17.value;
    var latLong017 = new VELatLong(latidisp17, longdisp17);
    VEmap17.SetCenterAndZoom(latLong017, 17);	
    
    VEmap18 = new VEMap('VEmap18');
    VEmap18.LoadMap();
    var latidisp18,longdisp18;
    latidisp18 = document.form1.hidlatitude18.value;
    longdisp18 = document.form1.hidlongitude18.value;
    var latLong018 = new VELatLong(latidisp18, longdisp18);
    VEmap18.SetCenterAndZoom(latLong018, 18);	

}