﻿// JScript File

function LocationsStart()
{
  
	glbEvents = new EventList();
	glbEvents.add(document, 'click', Modal_OnBlur);
	glbXmlRequest = new AkimanXmlHTTP(document.getElementById("loading"), objDebug);
	glbContentEvents = new EventList();
	glbContent = document.getElementById("Content");
	glbNavigation = document.getElementById("Navigation");
	glbHeader = document.getElementById("Header");
//	glbLoading = document.getElementById("loading");
	
	var objDebug = null;
	if(DEBUG) {
		objDebug = document.getElementById("debug");
		objDebug.style.display = "";
		if(document.getElementById("jsEval")) {
			document.getElementById("jsEval").style.display = "";
		}
	}

	glbHeader.innerHTML = TransformXML("<show />","locations.xsl");
	
	var oText=document.getElementById("strSearch");
	//oText.focus();

	
}
function ShowLocations() {
	
	var soapData = SoapDataBuilder("ShowLocations", parseForm('LocationsForm'));
	glbListCacheXml = AjaxRequest("Locations.asmx", soapData, "locations.xsl");
	glbHeader.innerHTML = TransformXML("<show />","locations.xsl");
	
	//glbListCachePage = 1;
	//glbIsSearchResult = false;
	
//	alert("glbIsSearchResult:" + glbIsSearchResult);
}
function ShowLocation(pId) {
    var addinfo=document.getElementById("add"+pId);
    if(addinfo.style.display == "none")
        addinfo.style.display = ""
    else
        addinfo.style.display = "none"
}
function SetSelected(Venue,VenueId)
{
    var SelectedVenue=document.getElementById("SelectedVenue");
    SelectedVenue.value=Venue;
    var SelectedVenueId=document.getElementById("SelectedVenueId");
    SelectedVenueId.value=VenueId;
    //var radio=document.getElementById("rad"+VenueId);
    //alert(radio.value);
}
function SelectLocation()
{
//    var SelectedVenue=document.getElementById("SelectedVenue");
//    var SelectedVenueId=document.getElementById("SelectedVenueId");
//    var strVenueRow = opener.document.getElementById("strVenueRow");
//    strVenueRow.style.display="";
//    var strVenue = opener.document.getElementById("strVenue");
//    strVenue.value=SelectedVenue.value;
//    this.close();

    //changed by citytech on 18th Jan 08
    //------------------------------------------------------------------------------------------------------

   
    var Flag=0;
    var SelectedVenue=document.getElementById("SelectedVenue");
    var SelectedVenueId=document.getElementById("SelectedVenueId");
    
    var strVenueRow = window.parent.document.getElementById("strVenueRow");
    strVenueRow.style.display="none";
    var strVenue = window.parent.document.getElementById("strVenueSelect");
    
    //creating a new option and select the new option as default option
    var NewOption=window.parent.document.createElement('option');
    NewOption.text=SelectedVenue.value;
    NewOption.value=SelectedVenueId.value;
    //the new option only add to the dropdown if it is not already exists
    for (i=0;i<strVenue.length;i++)
    {
        if(strVenue.options[i].text==SelectedVenue.value)
        {
            Flag=1;
            break;    
        }
    }
    
    if(Flag==0)
    {
        try
        {
           //strVenue.add(NewOption,strVenue.length-1);   // standards compliant
           strVenue.options.add(NewOption,strVenue.length-1);   // standards compliant
           strVenue.selectedIndex=strVenue.length-2;
        }
        catch(ex)
        {
            strVenue.add(NewOption);                    // IE only
            strVenue.selectedIndex=strVenue.length-2;
        }   
     }
     else
     {
        //select that already added option
        strVenue.selectedIndex=i;
     }
    
    this.close();   
   
    var Temp = window.parent.document.getElementById('ol');
    if(Temp)Temp.style.display="none";
    var Temp1=window.parent.document.getElementById('mbox')
    if(Temp1)Temp1.style.display="none";
    
    
    //------------------------------------------------------------------------------------------------------
}

function AddLocation(){
    var AddNewBlock = document.getElementById("NewLocation");
    AddNewBlock.style.display="";
    var SearchBlock = document.getElementById("LocationsList");
    SearchBlock.style.display="none";
    glbHeader.style.display="none";
}
function Back(){
    var AddNewBlock = document.getElementById("NewLocation");
    AddNewBlock.style.display="none";
    var SearchBlock = document.getElementById("LocationsList");
    SearchBlock.style.display="";
    glbHeader.style.display="";
}
function Submit(){
    if(ValidForm("LocationsListForm")) {
		/*var	params = CustomParamBuilder(
			"strVenue", document.getElementById("strVenue").value, 
			"strAddress", document.getElementById("strAddress").value,
			"strSuburb", document.getElementById("strSuburb").value,
			"lngPostCode", document.getElementById("lngPostCode").value,
			"sarSportsPlayed", document.getElementById("sarSportsPlayed").value,
			"sarAlternateNames", document.getElementById("sarAlternateNames").value);
			
		var soapData = SoapDataBuilder("SaveLocation", params);
		*/
		var soapData=SoapDataBuilder("SaveLocation",parseForm('LocationsListForm'));
		var LocationId=AjaxRequest("Locations.asmx", soapData);
		var SelectedVenue=document.getElementById("strVenue").value;
        var SelectedVenueId=0;
        
        //changed by citytech on 18th Jan 08
        //------------------------------------------------------------------------------------------------------
        var Flag=0;
        
        var strVenueRow = window.parent.document.getElementById("strVenueRow");
        strVenueRow.style.display="none";
        var strVenue = window.parent.document.getElementById("strVenueSelect");
    
        //creating a new option and select the new option as default option
        var NewOption=window.parent.document.createElement('option');
        NewOption.text=SelectedVenue;
        NewOption.value=SelectedVenueId;
        //the new option only add to the dropdown if it is not already exists
        for (i=0;i<strVenue.length;i++)
        {
            if(strVenue.options[i].text==SelectedVenue.value)
            {
                Flag=1;
                break;    
            }
    }
    
    if(Flag==0)
    {
        try
        {
           strVenue.options.add(NewOption,strVenue.length-1);   // standards compliant
           strVenue.selectedIndex=strVenue.length-2;
        }
        catch(ex)
        {
            //  strVenue.add(NewOption);                    // IE only
            strVenue.selectedIndex=strVenue.length-2;
        }   
     }
     else
     {
        //select that already added option
        strVenue.selectedIndex=i;
     }
    
    this.close(); 
   
       var Temp = window.parent.document.getElementById('ol');
    if(Temp)Temp.style.display="none";
    var Temp1=window.parent.document.getElementById('mbox')
    if(Temp1)Temp1.style.display="none";
//         var strVenueRow = opener.document.getElementById("strVenueRow");
//         strVenueRow.style.display="";
//         var strVenue = opener.document.getElementById("strVenue");
//         strVenue.value=SelectedVenue;
//         this.close();
	}
  //------------------------------------------------------------------------------------------------------
}
function ApproveLocations(){
UpdateNavigation("ApproveLocations()");
var soapData = SoapDataBuilder("NotApprovedLocations", parseForm('LocationsForm'));
glbListCacheXml = AjaxRequest("Locations.asmx", soapData, "locations.xsl");

}
function ApproveLocation()
{
    var soapData = SoapDataBuilder("ApproveLocations", parseForm('LocationsListForm'));
    AjaxRequest("Locations.asmx", soapData);
    soapData = SoapDataBuilder("NotApprovedLocations", parseForm('LocationsForm'));
    glbListCacheXml = AjaxRequest("Locations.asmx", soapData, "locations.xsl");
}
function DeleteLocation(LocationId,LocationName){
	var	params = CustomParamBuilder("lngLocationId", LocationId);
    var soapData = SoapDataBuilder("DeleteLocation", params);
    var GlbListCacheXml=AjaxRequest("Locations.asmx", soapData);
   if (GlbListCacheXml.indexOf('<IncidentList')!=-1)
   {
        var obj = document.getElementById("SearchBox");
        obj.value=LocationName;
        Search('Incident');
    }
    else
    {
        ApproveLocations();
    }
}