﻿// JScript File
var intCurrentLOTW;

    function low_GetCurrent(){
        ret = ws_LocationOfWeeks.GetCurrentLOTW(low_onCompleteGetCurrent, low_OnErrorGeneric, low_OnTimeoutGeneric);    
    }
    function low_onCompleteGetCurrent(result){
        document.getElementById("LocationOfTheWeek").innerHTML = result;
    }

    function low_NewLocationOfWeek(){
        //window.alert();
        ret = ws_LocationOfWeeks.AddNewLocationOfWeek(low_OnCompleteDetail, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_ShowLocationOfWeekDetail(intLocationOfWeekID){
        intCurrentLOTW = intLocationOfWeekID;
        document.getElementById("LocationOfWeekDetail").innerHTML = "Loading....";
        ret = ws_LocationOfWeeks.LocationOfWeekDetail(intLocationOfWeekID, low_OnCompleteDetail, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_OnCompleteDetail(result){
        document.getElementById("LocationOfWeekDetail").innerHTML = result;
    }



    function low_Search(){
	    var intID;
        var strName;
        var strInfo;
        var intCountryID;
        var intStateID;
        var boolLive;

	    intID = document.getElementById("txtsrchID").value;
        if (intID.length<1){
            intID='j';
        }
        if(isNaN(intID)==true){
            intID = 0;
        }
	    intCountryID = document.getElementById("cmbsrchCountries").value;
        if (intCountryID.length<1){
            intCountryID='j';
        }
        if(isNaN(intCountryID)==true){
            intCountryID = 0;
        }
	    intStateID = document.getElementById("cmbsrchStates").value;
        if (intStateID.length<1){
            intStateID='j';
        }
        if(isNaN(intStateID)==true){
            intStateID = 0;
        }

        strName = document.getElementById("txtsrchName").value;
        strInfo = document.getElementById("txtsrchInfo").value;
        boolLive = document.getElementById("chksrchLive").checked;

        document.getElementById("SearchResults").innerHTML = "Loading....";
        document.getElementById("LocationOfWeekDetail").innerHTML = "";
        ret = ws_LocationOfWeeks.Search(intID, strName, strInfo, intCountryID, intStateID, boolLive, low_OnCompleteSearch, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_OnCompleteSearch(result){
        document.getElementById("SearchResults").innerHTML = result;
    }

    
   

    function low_ShowAll(){
        ret = ws_LocationOfWeeks.ShowAll(low_OnCompleteShowAll, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_OnCompleteShowAll(result){
        document.getElementById("SearchResults").innerHTML = result;
    }




    function low_Save(intID){
        var strName;
        var strInfo;
        var strURL;
        var intCountryID;
        var intStateID;
        var boolLive;
        
	    intCountryID = document.getElementById("cmbCountries").value;
        if (intCountryID.length<1){
            intCountryID='j';
        }
        if(isNaN(intCountryID)==true){
            intCountryID = 0;
        }
	    intStateID = document.getElementById("cmbStates").value;
        if (intStateID.length<1){
            intStateID='j';
        }
        if(isNaN(intStateID)==true){
            intStateID = 0;
        }

        strName = document.getElementById("txtName").value;
        strInfo = document.getElementById("txtInfo").value;
        strURL = document.getElementById("txtURL").value;
        boolLive = document.getElementById("chkLive").checked;

        ret = ws_LocationOfWeeks.Save(intID, strName, strInfo, strURL, intCountryID, intStateID, boolLive, low_OnCompleteSave, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_Delete(intID){
        var resp= confirm("Do you really want to delete this Location of the Week?");
        if (resp==true){
            ret = ws_LocationOfWeeks.Delete(intID, low_OnCompleteDelete, low_OnErrorGeneric, low_OnTimeoutGeneric);
        }
    }
    function low_OnCompleteDelete(result){
        low_Search();
    }
    function low_OnCompleteSave(result){
        window.alert("Save complete");
        low_Search();
    }


    function low_RefreshImageList(intID){
        ret = ws_LocationOfWeeks.RefreshImageList(intID, low_OnCompleteRefreshImageList, low_OnErrorGeneric, low_OnTimeoutGeneric);
    }
    function low_OnCompleteRefreshImageList(result){
        document.getElementById("LOTWImageList").innerHTML = result;
        if (result=='There are no images.  Use the upload button below to add an image to this location of the week'){
            window.alert("There are no images for this location of the week.  Please use the upload new image button to add a new image");
        }
    }

    
    function lotw_RemoveImage(intID){
        var resp= confirm("Do you really want to delete this image?");
        if (resp==true){
            ret = ws_LocationOfWeeks.RemoveImage(intID, low_RefreshImageList(intCurrentLOTW), low_OnErrorGeneric, low_OnTimeoutGeneric);    
        }
    }
    

    function low_OnErrorGeneric(error){
        var stackTrace = error.get_stackTrace();
        var message = error.get_message();
        var statusCode = error.get_statusCode();
        var exceptionType = error.get_exceptionType();
        var timedout = error.get_timedOut();
        var strMessage;
       
        // Display the error.    
        //strMessage = "Stack Trace: " +  stackTrace + "    ||    Service Error: " + message + "    ||    Status Code: " + statusCode + "    ||    Exception Type: " + exceptionType + "    ||    Timedout: " + timedout;
        strMessage = "Message: " +  message;
        window.alert("Error:" + strMessage);
    }
    
    function low_OnTimeoutGeneric(result){
        window.alert("There was a time-out in the lg_LocationOfWeek web service: " + result);
    }    
