﻿//This file contains all of the calls made to the 'ws_lg_Companys' web service and handles the return calls from it
var intCompanyIDInProgress;
var strG_SearchTitle;

    function c_MultipleDelete(){
        var strIDs = '';
        var strAllIDs = '';
        var temp = new Array()
        var strChkBox = '';
        
        //collect the ticked companies
        strAllIDs = document.getElementById("hdnSrchIDs").value;
        //window.alert(strAllIDs);
        temp = strAllIDs.split(',');                
        for (var i=0;i<=temp.length-1;i++)
            {
            if (temp[i].length > 0){
                strChkBox = "chkCID" + temp[i];
                //window.alert("Checking: " + strChkBox);
                //window.alert(document.getElementById(strChkBox).checked);
                if(document.getElementById(strChkBox).checked==true){
                    strIDs += temp[i] + ", ";
                }   
                //window.alert(strSubsLevels);
            }
        }                        

        if (strIDs.length>0){
            var resp= confirm("This will delete all 'ticked' companies.  Are you sure you want to continue?");
            if (resp==true){
                ret = ws_lg_Companies.DeleteMultiple(strIDs, c_OnCompleteMultipleDelete, c_OnErrorGeneric, c_OnTimeoutGeneric);
            }
        }else{
            window.alert("You need to select the companies you wish to delete by ticking the boxes next to each company");
        }
    }
    function c_OnCompleteMultipleDelete(result){
        if (result.length>0){
            window.alert(result);
        }else{
            c_Search();        
        }
    }


    function c_NewCompany(){
        //window.alert();
        ret = ws_lg_Companies.AddNewCompany(c_OnCompleteDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_ShowCompanyDetail(intlg_CompanyID){
        document.getElementById("CompanyDetail").innerHTML = "Loading....";
        ret = ws_lg_Companies.CompanyDetail(intlg_CompanyID, c_OnCompleteDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteDetail(result){
        document.getElementById("CompanyDetail").innerHTML = result;
        window.location="#detail";
    }


    function c_ContactCompany(intCompanyID){
        var strSubject = '';
        var strMessage = '';
        var strEmail = '';
        var boolFail;

        boolFail = false;

        strEmail = document.getElementById("txtEmail").value;
        strSubject  = document.getElementById("txtSubject").value;
        strMessage  = document.getElementById("txtMessage").value;

        if (strEmail.length<1){
            window.alert("Please enter your email address.  The company will need it to contact you.");
            boolFail = true;
        }
        if (strSubject.length<1){
            window.alert("Please enter a subject for your message");
            boolFail = true;
        }
        if (strMessage.length<1){
            window.alert("Please enter a message");
            boolFail = true;
        }
        //collect up the stored search variables and direct to the print form
        if (boolFail == false){
            document.getElementById("sendbutton").style.visibility='hidden';
            document.getElementById("sendinfo").style.visibility='';
            ret = ws_lg_Companies.ContactCompany(intCompanyID, strSubject, strMessage, strEmail, c_OnCompleteContact, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }    
    }
    function c_OnCompleteContact(result){
        //window.alert("This is a test message.  The email has not been sent to the company. It has been sent to Jims email address");
        if (result.length>0){
            window.alert("There may have been a problem sending your message:" + result);
        }else{
            window.alert("Your message has been sent");
        }
        HideTheContact();        
    }
    

    function c_SetAllReady(){
        var resp= confirm("Do you really want to set ALL companies to Ready for Print?");
        if (resp==true){
            document.getElementById("Status").innerHTML = "Working....";
            ret = ws_lg_Companies.SetReadyForPrint(true, c_OnCompleteReady, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteReady(result){
        document.getElementById("Status").innerHTML = result;
    }


    function c_SetAllNotReady(){
        var resp= confirm("Do you really want to set ALL companies to Not Ready for Print?");
        if (resp==true){
            document.getElementById("Status").innerHTML = "Working....";
            ret = ws_lg_Companies.SetReadyForPrint(false, c_OnCompleteNotReady, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteNotReady(result){
        document.getElementById("Status").innerHTML = result;
    }



    function c_Search(){
	    var intID;
        var strName;
        var strDescription;
        var strContactName;
        var strAddress1;
        var strAddress2;
        var strAddress3;
        var strAddress4;
        var intCountryID;
        var strPhone;
        var strPhoneCode;
        var strFax;
        var strFaxCode;
        var strMobile;
        var strEmail;
        var strEmail2;
        var boolWebsite;
        var strURL;
        var strCompanyTypeIDs;
        var strTradeSince;
        var intCountrySearchID;
        var intLGSection;
        var strContacts;
        var strLanguages;
        var strAreasCovered;
        var boolFeatureFilm;
        var boolCommercials;
        var boolIndustryFilm;
        var boolDocumentary;
        var boolMusicVid;
        var boolTV;
        var boolPhotoShoot;
        var julDateCreated;
        var julDateModified;
        var boolLinkMe;
        var strLogoName;
        var strLogo;
        var boolShowReel;
        var boolShowReelOnline;
        var boolPictureLibraryOnline;
        var strDisplayStatus;
        var boolBold;
        var intPriority;
        var boolContactUpdated;
        var strAccountNumber;
        var intUpdatedBy;
        var boolReadyForPrint;
        var intState;
        var strStateLGExport;
        var objCategories;
        var objContacts;
        var objProductions;
        var strPostcode;
        var intCategoryID;
        var strStatus;
        var intStateID;
        var strStartDate;
        var strEndDate;
        var strKeywords; 
        var boolLiveOnly;

        boolLiveOnly = document.getElementById("chksrchLiveOnly").checked;

    	intID = document.getElementById("txtsrchID").value;
        if (intID.length<1){
            intID='j';
        }
        if(isNaN(intID)==true){
            intID = 0;
        }
        strName = document.getElementById("txtsrchName").value;
        //strPostcode = document.getElementById("txtsrchPostcode").value;
        strPostcode = '';
        intCountryID = document.getElementById("cmbSrchCountries").options[document.getElementById("cmbSrchCountries").selectedIndex].value;
        if (intCountryID.length<1){
            intCountryID='j';
        }
        if(isNaN(intCountryID)==true){
            intCountryID = 0;
        }
        strURL = document.getElementById("txtsrchURL").value;
        intCategoryID = document.getElementById("cmbSrchCategories").options[document.getElementById("cmbSrchCategories").selectedIndex].value;
        if (intCategoryID.length<1){
            intCategoryID='j';
        }
        if(isNaN(intCategoryID)==true){
            intCategoryID = 0;
        }
        boolReadyForPrint = document.getElementById("cmbSrchPrintStatus").options[document.getElementById("cmbSrchPrintStatus").selectedIndex].value;
        strContactName = document.getElementById("txtsrchContactName").value;
        strStatus = document.getElementById("cmbSrchStatuses").options[document.getElementById("cmbSrchStatuses").selectedIndex].value;
        strStartDate = document.getElementById("txtsrchStartDate").value;
        strEndDate = document.getElementById("txtsrchEndDate").value;
        intStateID = document.getElementById("cmbSrchStates").options[document.getElementById("cmbSrchStates").selectedIndex].value;
        if (intStateID.length<1){
            intStateID='j';
        }
        if(isNaN(intStateID)==true){
            intStateID = 0;
        }
        strKeywords = document.getElementById("txtsrchKeywords").value;

        /*
        boolFeatureFilm = document.getElementById("chkFeatureFilm").checked;
        boolCommercials = document.getElementById("chkCommercials").checked;
        boolIndustryFilm = document.getElementById("chkIndustryFilm").checked;
        boolDocumentary = document.getElementById("chkDocumentary").checked;
        boolMusicVid = document.getElementById("chkMusicVid").checked;
        boolTV = document.getElementById("chkTV").checked;
        boolPhotoShoot = document.getElementById("chkPhotoShoot").checked;
        */

        document.getElementById("SearchResults").innerHTML = "Loading....";
        document.getElementById("CompanyDetail").innerHTML = "";
        
        //before executing the search, set the hidden form values so that the print functionality works
        document.getElementById("srchID").value = intID;
        document.getElementById("srchName").value = strName;
        document.getElementById("srchPostcode").value = strPostcode;
        document.getElementById("srchCountry").value = intCountryID;
        document.getElementById("srchURL").value = strURL;
        document.getElementById("srchType").value = intCategoryID;
        document.getElementById("srchPrintStatus").value = boolReadyForPrint;
        document.getElementById("srchStatus").value = strStatus;
        document.getElementById("srchContactName").value = strContactName;
        document.getElementById("srchState").value = intStateID ;
        document.getElementById("srchStartDate").value = strStartDate;
        document.getElementById("srchEndDate").value = strEndDate;        
        
        ret = ws_lg_Companies.Search(intID, strName, strPostcode, intCountryID, strURL, intCategoryID, boolReadyForPrint, strStatus, strContactName, strStartDate, strEndDate, intStateID, strKeywords, boolLiveOnly, c_OnCompleteSearch, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteSearch(result){
        document.getElementById("SearchResults").innerHTML = result;
    }


    function c_InitiateSearch(strText, intCountryID, intStateID, intCategoryID){
        //do the advertiser search
        //window.alert("text:" + strText);
        //window.alert("intCountryID:" + intCountryID);
        //window.alert("intStateID:" + intStateID);
        //window.alert("intCategoryID:" + intCategoryID);
        ret = ws_lg_Companies.SearchFromSiteAdvertisers(strText, intCountryID, intStateID, intCategoryID, c_OnCompleteSearchFromSiteAdvertisers, c_OnErrorGeneric, c_OnTimeoutGeneric);
        //do the non advertiser search
        ret = ws_lg_Companies.SearchFromSiteNonAdvertisers(strText, intCountryID, intStateID, intCategoryID, c_OnCompleteSearchFromSiteNonAdvertisers, c_OnErrorGeneric, c_OnTimeoutGeneric);
        
    }
    function c_OnCompleteSearchFromSiteAdvertisers(result){
        //window.alert("here:advertisers");
        //window.alert(result);
        document.getElementById("SearchResultsAdvertisers").innerHTML = result;
    }
    function c_OnCompleteSearchFromSiteNonAdvertisers(result){
        var vVar;
        //window.alert("here:non advertisers");
        //window.alert(result);

        vVar = result.split('|||');
                
        document.getElementById("Title").innerHTML = strG_SearchTitle;
        document.getElementById("Breakdown").innerHTML = vVar[0] + "<br/><br/>";
        document.getElementById("SearchResultsNonAdvertisers").innerHTML = vVar[1];
    }

    function c_InitiateSiteSearch(strText){
        //do the advertiser search
        ret = ws_lg_Companies.SiteSearchAdvertisers(strText, 0, 0, 0, c_OnCompleteSiteSearchFromSiteAdvertisers, c_OnErrorGeneric, c_OnTimeoutGeneric);
        //do the non advertiser search
        ret = ws_lg_Companies.SiteSearchNonAdvertisers(strText, 0, 0, 0, c_OnCompleteSiteSearchFromSiteNonAdvertisers, c_OnErrorGeneric, c_OnTimeoutGeneric);
        
    }
    function c_OnCompleteSiteSearchFromSiteAdvertisers(result){
        document.getElementById("SearchResultsAdvertisers").innerHTML = result;
    }
    function c_OnCompleteSiteSearchFromSiteNonAdvertisers(result){
        var vVar;

        vVar = result.split('||');
                
        document.getElementById("BreakdownCompanies").innerHTML = vVar[0];
        document.getElementById("SearchResultsNonAdvertisers").innerHTML =  vVar[1];
    }


    
   function c_PrintResults(){
	    var intID;
        var strName;
        var strPostcode;
        var strContactName;
        var intCountryID;
        var strURL;
        var intCategoryID;
        var boolReadyForPrint;
        var strStatus;
        var intStateID;
        var strStartDate;
        var strEndDate;

        //collect up the stored search variables and direct to the print form
        intID = document.getElementById("srchID").value;
        strName= document.getElementById("srchName").value;
        strPostcode= document.getElementById("srchPostcode").value;
        intCountryID= document.getElementById("srchCountry").value;
        strURL= document.getElementById("srchURL").value;
        intCategoryID= document.getElementById("srchType").value;
        boolReadyForPrint= document.getElementById("srchPrintStatus").value;
        strStatus= document.getElementById("srchStatus").value;
        strContactName= document.getElementById("srchContactName").value;
        intStateID= document.getElementById("srchState").value;
        strStartDate= document.getElementById("srchStartDate").value;
        strEndDate= document.getElementById("srchEndDate").value;
        
        window.open('print.aspx?mode=cs&id=' + intID + '&name=' + strName + '&postcode=' + strPostcode + '&country=' + intCountryID + '&state=' + intStateID + '&startdate=' + strStartDate + '&enddate=' + strEndDate + '&url=' + strURL + '&type=' + intCategoryID + '&rfp=' + boolReadyForPrint + '&status=' + strStatus + '&contactname=' + strContactName);
   }

    function c_ShowAll(){
        ret = ws_lg_Companies.ShowAll(c_OnCompleteShowAll, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteShowAll(result){
        document.getElementById("SearchResults").innerHTML = result;
    }




    function c_Save(intID){
        var strName;
        var strDescription;
        var strContactName;
        var strAddress1;
        var strAddress2;
        var strAddress3;
        var strAddress4;
        var intStateID;
        var intCountryID;
        var strPhone;
        var strPhoneCode;
        var strFax;
        var strFaxCode;
        var strSkype;
        var strMobile;
        var strEmail;
        var strEmail2;
        var boolWebsite;
        var strURL;
        var strCompanyTypeIDs;
        var strTradeSince;
        var intCountrySearchID;
        var intLGSection;
        var strContacts;
        var strLanguages;
        var strAreasCovered;
        var boolFeatureFilm;
        var boolCommercials;
        var boolIndustryFilm;
        var boolDocumentary;
        var boolMusicVid;
        var boolTV;
        var boolPhotoShoot;
        var julDateCreated;
        var julDateModified;
        var boolLinkMe;
        var strLogoName;
        var strLogo;
        var boolShowReel;
        var boolShowReelOnline;
        var boolPictureLibraryOnline;
        var strDisplayStatus;
        var boolBold;
        var intPriority;
        var boolContactUpdated;
        var strAccountNumber;
        var intUpdatedBy;
        var boolBadDebt;
        var boolReadyForPrint;
        var intState;
        var strStateLGExport;
        var strNotes;

        strName = document.getElementById("txtName").value;
        strDescription = document.getElementById("txtDescription").value;
        strContactName = document.getElementById("txtContactName").value;
        strAddress1 = document.getElementById("txtAddress1").value;
        strAddress2 = document.getElementById("txtAddress2").value;
        strAddress3 = document.getElementById("txtAddress3").value;
        //strAddress4 = document.getElementById("txtAddress4").value;
        intCountryID = document.getElementById("cmbCountry").options[document.getElementById("cmbCountry").selectedIndex].value;
        if (intCountryID.length<1){
            intCountryID='j';
        }
        if(isNaN(intCountryID)==true){
            intCountryID = 0;
        }
        intStateID  = document.getElementById("cmbState").options[document.getElementById("cmbState").selectedIndex].value;
        if (intStateID.length<1){
            intStateID='j';
        }
        if(isNaN(intStateID)==true){
            intStateID = 0;
        }

        strPhone = document.getElementById("txtPhone").value;
        strPhoneCode = document.getElementById("txtPhoneCode").value;
        strFax = document.getElementById("txtFax").value;
        strFaxCode = document.getElementById("txtFaxCode").value;
        strMobile = document.getElementById("txtMobile").value;
        strSkype = document.getElementById("txtSkype").value;
        strEmail = document.getElementById("txtEmail").value;
        strEmail2 = document.getElementById("txtEmail2").value;
        boolWebsite = document.getElementById("chkWebsite").checked;
        strURL = document.getElementById("txtURL").value;
        //strCompanyTypeIDs = document.getElementById("txtCompanyTypeIDs").value;
        strTradeSince = document.getElementById("txtTradeSince").value;
        /*intCountrySearchID = document.getElementById("txtCountrySearchID").value;
        if (intCountrySearchID.length<1){
        intCountrySearchID='j';
        }
        if(isNaN(intCountrySearchID)==true){
        intCountrySearchID = 0;
        }
        */

        intLGSection = document.getElementById("cmbLGSection").options[document.getElementById("cmbLGSection").selectedIndex].value;
        if (intLGSection.length<1){
            intLGSection='j';
        }
        if(isNaN(intLGSection)==true){
            intLGSection = 0;
        }

        //strContacts = document.getElementById("txtContacts").value;
        strLanguages = document.getElementById("txtLanguages").value;
        strAreasCovered = document.getElementById("txtAreasCovered").value;
        boolFeatureFilm = document.getElementById("chkProd~FeatureFilm").checked;
        boolCommercials = document.getElementById("chkProd~Commercials").checked;
        boolIndustryFilm = document.getElementById("chkProd~IndustryFilm").checked;
        boolDocumentary = document.getElementById("chkProd~Documentary").checked;
        boolMusicVid = document.getElementById("chkProd~MusicVideo").checked;
        boolTV = document.getElementById("chkProd~TV").checked;
        boolPhotoShoot = document.getElementById("chkProd~PhotoShoot").checked;
        //boolLinkMe = document.getElementById("chkLinkMe").checked;
        //strLogoName = document.getElementById("txtLogoName").value;
        //strLogo = document.getElementById("chkLogo").checked;
        //boolShowReel = document.getElementById("chkShowReel").checked;
        //boolShowReelOnline = document.getElementById("chkShowReelOnline").checked;
        //boolPictureLibraryOnline = document.getElementById("chkPictureLibraryOnline").checked;
        strDisplayStatus = document.getElementById("cmbStatus").options[document.getElementById("cmbStatus").selectedIndex].value;
        //boolBold = document.getElementById("chkBold").checked;
        //intPriority = document.getElementById("txtPriority").value;
        //if (intPriority.length<1){
        //    intPriority='j';
        //}
        //if(isNaN(intPriority)==true){
        //    intPriority = 0;
        //}
        //boolContactUpdated = document.getElementById("chkContactUpdated").checked;
        //strAccountNumber = document.getElementById("txtAccountNumber").value;

        boolBadDebt = document.getElementById("chkBadDebt").checked;
        boolReadyForPrint = document.getElementById("chkReadyForPrint").checked;
        /*intState = document.getElementById("txtState").value;
        if (intState.length<1){
            intState='j';
        }
        if(isNaN(intState)==true){
            intState = 0;
        }
        */
        //strStateLGExport = document.getElementById("txtStateLGExport").value;
        strNotes  = document.getElementById("txtNotes").value;

        //ret = ws_lg_Companies.Save(intID, strName, strDescription, strContactName, strAddress1, strAddress2, strAddress3, intStateID, intCountryID, strPhone, strPhoneCode, strFax, strFaxCode, strMobile, strEmail, boolWebsite, strURL, strTradeSince, intLGSection, strLanguages, strAreasCovered, boolFeatureFilm, boolCommercials, boolIndustryFilm, boolDocumentary, boolMusicVid, boolTV, boolPhotoShoot, boolLinkMe, strLogoName, strLogo, boolShowReel, boolShowReelOnline, boolPictureLibraryOnline, strDisplayStatus, boolBold, intPriority, boolReadyForPrint, strStateLGExport, strNotes, c_OnCompleteSave, c_OnErrorGeneric, c_OnTimeoutGeneric);
        ret = ws_lg_Companies.Save2(intID, strName, strDescription, strContactName, strAddress1, strAddress2, strAddress3, intStateID, intCountryID, strPhone, strPhoneCode, strFax, strFaxCode, strSkype, strMobile, strEmail, strEmail2, boolWebsite, strURL, strTradeSince, intLGSection, strLanguages, strAreasCovered, boolFeatureFilm, boolCommercials, boolIndustryFilm, boolDocumentary, boolMusicVid, boolTV, boolPhotoShoot, strDisplayStatus, boolBadDebt, boolReadyForPrint, strNotes, c_OnCompleteSave, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_Delete(intID){
        var resp= confirm("Do you really want to delete this Company?");
        if (resp==true){
            ret = ws_lg_Companies.Delete(intID, c_OnCompleteDelete, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteSave(result){
        window.alert("Save complete");
        document.getElementById("CompanyDetail").innerHTML = '';
    }
    function c_OnCompleteDelete(result){
        document.getElementById("CompanyDetail").innerHTML = '';
        c_Search();        
    }



    function c_Save_Listed(intID){
        var strName;
        var strAddress;
        var strTown;
        var strPostcode;
        var intStateID = 'j';
        var intCountryID = 'j';
        var strTelCode;
        var strTelNumber;
        var strFaxCode;
        var strFaxNumber;
        var strMobile;
        var strEmail;

        var intCategoryID = 'j';
        var boolFeatureFilm;
        var boolCommercials;
        var boolIndustryFilm;
        var boolDocumentary;
        var boolMusicVid;
        var boolTV;
        var boolPhotoShoot;
        var strContactPerson;        
        var strLanguages;
        var strAreasCovered;
        var strTradingSince;
        var strURL;
        
        var strRPCompany1;
        var strRPCompany2;
        var strRPCompany3;
        var strRPCompany4;
        var strRPCountry1;
        var strRPCountry2;
        var strRPCountry3;
        var strRPCountry4;
        var strRPProject1;
        var strRPProject2;
        var strRPProject3;
        var strRPProject4;
        var strRPDirector1;
        var strRPDirector2;
        var strRPDirector3;
        var strRPDirector4;
        var strRPContact1;
        var strRPContact2;
        var strRPContact3;
        var strRPContact4;
        var strRPType1;
        var strRPType2;
        var strRPType3;
        var strRPType4;
        
        var vVar;

        strName = document.getElementById("txtName").value;
        strAddress = document.getElementById("txtAddress").value;
        strTown = document.getElementById("txtCity").value;
        strPostcode = document.getElementById("txtPostcode").value;
        intCountryID = document.getElementById("cmbLocation").value;
        vVar = intCountryID.split('~');
        intCountryID = vVar[0];        
        intStateID = vVar[1];        
        strTelCode = document.getElementById("txtPhoneCode").value;
        strTelNumber = document.getElementById("txtPhoneNumber").value;
        strFaxCode = document.getElementById("txtFaxCode").value;
        strFaxNumber = document.getElementById("txtFaxNumber").value;
        strMobile =  document.getElementById("txtMobile").value;
        strEmail = document.getElementById("txtEmail").value;

        intCategoryID = document.getElementById("cmbCompanyType").value;
        boolFeatureFilm = document.getElementById("chkFeatureFilm").checked;
        boolCommercials = document.getElementById("chkTVCommercial").checked;
        boolIndustryFilm = document.getElementById("chkIndustryFilm").checked;
        boolDocumentary = document.getElementById("chkDocumentary").checked;
        boolMusicVid = document.getElementById("chkMusicVideo").checked;
        boolTV = document.getElementById("chkTVProgramme").checked;
        boolPhotoShoot = document.getElementById("chkPhotoShoot").checked;
        strContactName = document.getElementById("txtContact").value;
        strLanguages = document.getElementById("txtLanguages").value;
        strAreasCovered = document.getElementById("txtRegionsCovered").value;
        strTradingSince = document.getElementById("txtTradingSince").value;
        strURL = document.getElementById("txtWebsite").value;

        strRPCompany1 = document.getElementById("txtCompany1").value;
        strRPCompany2 = document.getElementById("txtCompany2").value;
        strRPCompany3 = document.getElementById("txtCompany3").value;
        strRPCompany4 = document.getElementById("txtCompany4").value;
        strRPCountry1 = document.getElementById("txtCountry1").value;
        strRPCountry2 = document.getElementById("txtCountry2").value;
        strRPCountry3 = document.getElementById("txtCountry3").value;
        strRPCountry4 = document.getElementById("txtCountry4").value;
        strRPProject1 = document.getElementById("txtProject1").value;
        strRPProject2 = document.getElementById("txtProject2").value;
        strRPProject3 = document.getElementById("txtProject3").value;
        strRPProject4 = document.getElementById("txtProject4").value;
        strRPDirector1 = document.getElementById("txtDirector1").value;
        strRPDirector2 = document.getElementById("txtDirector2").value;
        strRPDirector3 = document.getElementById("txtDirector3").value;
        strRPDirector4 = document.getElementById("txtDirector4").value;
        strRPContact1 = document.getElementById("txtContact1").value;
        strRPContact2 = document.getElementById("txtContact2").value;
        strRPContact3 = document.getElementById("txtContact3").value;
        strRPContact4 = document.getElementById("txtContact4").value;
        strRPType1 = document.getElementById("cmbType1").value;
        strRPType2 = document.getElementById("cmbType2").value;
        strRPType3 = document.getElementById("cmbType3").value;
        strRPType4 = document.getElementById("cmbType4").value;


        //intID = CheckNumeric(intID);
        //intCountryID = CheckNumeric(intCountryID);
        //intStateID = CheckNumeric(intStateID);
        //intCategoryID = CheckNumeric(intCategoryID);
        if (intCountryID.length<1){
            intCountryID =0;
        }
        if (intStateID.length<1){
            intStateID =0;
        }
        if (intCategoryID.length<1){
            intCategoryID =0;
        }


        /*
        if(isNaN(intCountryID)==true){
            intCountryID = 0;
        }
        if(isNaN(intStateID)==true){
            intStateID = 0;
        }
        if(isNaN(intCategoryID)==true){
            intCategoryID = 0;
        }
        */
        if (strName.length<1){
            window.alert("Please enter your trading name");
        }else if (strTown.length<1){
            window.alert("Please enter your town/city");
        }else if (intCountryID<1){
            window.alert("Please select your location");
        }else if (strEmail.length<1){
            window.alert("Please enter your company email address");
        }else if (intCategoryID<1){
            window.alert("Please select your category type");
        }else if (strContactName.length<1){
            window.alert("Please enter your contact name");
        }else if (strAreasCovered.length<1){
            window.alert("Please enter your regions covered");
        }else{
            document.getElementById("Submit").innerHTML = 'Please wait...this may take up to 30 seconds';
            ret = ws_lg_Companies.SaveListed(intID, intCategoryID, strName, strAddress, strTown, strPostcode, intCountryID, intStateID, strTelCode, strTelNumber, strFaxCode, strFaxNumber, strMobile, strEmail, intCategoryID, boolFeatureFilm, boolCommercials, boolIndustryFilm, boolDocumentary, boolMusicVid, boolTV, boolPhotoShoot, strContactName, strLanguages, strAreasCovered, strTradingSince, strURL, strRPCompany1, strRPCompany2, strRPCompany3, strRPCompany4, strRPCountry1, strRPCountry2, strRPCountry3, strRPCountry4, strRPProject1, strRPProject2, strRPProject3, strRPProject4, strRPDirector1, strRPDirector2, strRPDirector3, strRPDirector4, strRPContact1, strRPContact2, strRPContact3, strRPContact4, strRPType1, strRPType2, strRPType3, strRPType4, c_OnCompleteSaveListed, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteSaveListed(result){
        document.getElementById("Submit").style.left='10px';
        document.getElementById("Submit").innerHTML = 'Thank you. Your listing has been sent.  It may take up to 36 hours before your company is visible on the website.';
    }
    function c_TestID(){
        var intCategoryID='';
        
        intCategoryID = document.getElementById("cmbCompanyType").value;
        //intCategoryID = CheckNumeric(intCategoryID);
        window.alert(intCategoryID);
        ret = ws_lg_Companies.TestID(intCategoryID, c_OnCompleteTestID, c_OnErrorGeneric, c_OnTimeoutGeneric);    
    }
    function c_OnCompleteTestID(result){
        window.alert(result);
    }


    function c_setDeleted(){
        document.getElementById("divDeleted").innerHTML=Date() + '&nbsp;<a onclick=c_setUnDeleted();>[unDelete]</a>';
        document.getElementById("txtDeleted").value=Date();
    }
    function c_setUnDeleted(){
        document.getElementById("divDeleted").innerHTML='&nbsp;<a onclick=c_setDeleted()>[Delete]</a>';
        document.getElementById("txtDeleted").value='';
    }




    function c_Drawlg_CompanyID(intID){
        document.getElementById("CompanyPane").innerHTML = "Working....";
        ret = ws_lg_Companies.Showlg_CompanyID(intID, c_OnCompleteFileID, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteFileID(result){
        document.getElementById("CompanyPane").innerHTML = result;
    }


    function c_ShowCategoryList(intCompanyID){
        intCompanyIDInProgress = intCompanyID;
        ret = ws_lg_Companies.ReturnCompanyCategoryList(intCompanyID, c_OnCompleteCategoryList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteCategoryList(result){
        document.getElementById("CategoryList").innerHTML = result;
    }


    function c_AddCategoryToCompany(intCompanyID){
        //remove the catorory association
        var intCategoryID;
        
        intCategoryID = document.getElementById("cmbAddCategory").options[document.getElementById("cmbAddCategory").selectedIndex].value;
        if (intCategoryID.length > 0){
            intCompanyIDInProgress = intCompanyID;
            ret = ws_lg_Companies.AddCategoryToCompany(intCompanyID, intCategoryID, c_OnCompleteAddCategory, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteAddCategory(result){
        //refresh the list
        ret = ws_lg_Companies.ReturnCompanyCategoriesWeb(intCompanyIDInProgress, c_OnCompleteRefreshCategoryList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }


    function c_removecategory(intCompanyID, intCategoryID){
        //remove the catorory association
        var resp= confirm("Do you really want to remove this type from the company?");
        if (resp==true){
            intCompanyIDInProgress = intCompanyID;
            ret = ws_lg_Companies.RemoveCategoryFromCompany(intCompanyID, intCategoryID, c_OnCompleteRemoveCategory, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteRemoveCategory(result){
        //refresh the list
        ret = ws_lg_Companies.ReturnCompanyCategoriesWeb(intCompanyIDInProgress, c_OnCompleteRefreshCategoryList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteRefreshCategoryList(result){
        //refresh the list
        document.getElementById("CategoryList").innerHTML = '';
        document.getElementById("Categories").innerHTML = result;
    }

    
    function c_RemoveProduction(intID, intCompanyID){
        //remove the catorory association
        var resp= confirm("Do you really want to remove this production from the company?");
        if (resp==true){
            intCompanyIDInProgress = intCompanyID;
            ret = ws_lg_Companies.RemoveProductionFromCompany(intID, c_OnCompleteRemoveProduction, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteRemoveProduction(result){
        //refresh the list
        RefreshCompanyProductionList();
    }
    function RefreshCompanyProductionList(){
        ret = ws_lg_Companies.ReturnCompanyProductionsWeb(intCompanyIDInProgress, c_OnCompleteRefreshProductionList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteRefreshProductionList(result){
        //refresh the list
        document.getElementById("ProductionDetail").innerHTML = '';
        document.getElementById("Productions").innerHTML = result;
    }
    

    function c_AddProduction(intCompanyID){
        //refresh the list
        document.getElementById("ProductionDetail").innerHTML = 'loading';
        intCompanyIDInProgress = intCompanyID; 
        ret = ws_lg_Companies.AddProduction(intCompanyID, c_OnCompleteProductionDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_ProductionDetail(intProductionID){
        document.getElementById("ProductionDetail").innerHTML = 'loading';
        ret = ws_lg_Companies.ProductionDetail(intProductionID, c_OnCompleteProductionDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteProductionDetail(result){
        //refresh the list
        document.getElementById("ProductionDetail").innerHTML = result;
    }
    
    function c_ProductionSave(intID, intCompanyID){
        var strCompany;
        var strCountry;
        var strProject;
        var strDirector;
        var strContact;
        var strType;
           
        if (intCompanyID.length<1){
            intCompanyID=intCompanyIDInProgress
        }
        if(isNaN(intCompanyID)==true){
            intCompanyID = 0;
        }
        intCompanyIDInProgress = intCompanyID;
        
        strCompany = document.getElementById("txtProdCompany").value;
        strCountry = document.getElementById("txtProdCountry").value;
        strProject = document.getElementById("txtProdProject").value;
        strDirector = document.getElementById("txtProdDirector").value;
        strContact = document.getElementById("txtProdContact").value;
        strType = document.getElementById("cmbProdTypes").options[document.getElementById("cmbProdTypes").selectedIndex].value;
        
        ret = ws_lg_Companies.ProductionSave(intID, intCompanyID, strCompany, strCountry, strProject, strDirector, strContact, strType, c_OnCompleteProductionSave, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteProductionSave(result){
        RefreshCompanyProductionList();
        //document.getElementById("ProductionDetail").innerHTML = result;
    }    
    function c_ProductionCancel(intCompanyID){
        intCompanyIDInProgress = intCompanyID;
        RefreshCompanyProductionList();
    }
    
    


    function c_RemoveContact(intID, intCompanyID){
        //remove the catorory association
        var resp= confirm("Do you really want to remove this contact from the company?");
        if (resp==true){
            intCompanyIDInProgress = intCompanyID;
            ret = ws_lg_Companies.RemoveContactFromCompany(intID, c_OnCompleteRemoveContact, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }
    }
    function c_OnCompleteRemoveContact(result){
        //refresh the list
        RefreshCompanyContactList();
    }
    function RefreshCompanyContactList(){
        ret = ws_lg_Companies.ReturnCompanyContactsWeb(intCompanyIDInProgress, c_OnCompleteRefreshContactList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteRefreshContactList(result){
        //refresh the list
        document.getElementById("ContactDetail").innerHTML = '';
        document.getElementById("Contacts").innerHTML = result;
    }

    function c_AddContact(intCompanyID){
        //refresh the list
        document.getElementById("ContactDetail").innerHTML = 'loading';
        intCompanyIDInProgress = intCompanyID; 
        ret = ws_lg_Companies.AddContact(intCompanyID, c_OnCompleteContactDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_ContactDetail(intContactID){
        document.getElementById("ContactDetail").innerHTML = 'loading';
        ret = ws_lg_Companies.ContactDetail(intContactID, c_OnCompleteContactDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteContactDetail(result){
        //refresh the list
        document.getElementById("ContactDetail").innerHTML = result;
    }
    
    function c_ContactSave(intID, intCompanyID){
        var intCompanyID;
        var strTitle;
        var strFirstname;
        var strLastname;
        var strJobTitle;
        var strDirectLine;
        var strMobile;
        var strEmail;
        var intContactStatus;
        var strComment;
        var julCreated;
        var julModified;
        var intCreatedBy;
        var boolBIContact;
        var boolContributor;
        var boolPublishedContact;

        if (intCompanyID.length<1){
            intCompanyID=intCompanyIDInProgress
        }
        if(isNaN(intCompanyID)==true){
            intCompanyID = 0;
        }
        intCompanyIDInProgress = intCompanyID;

        strTitle = document.getElementById("txtContTitle").value;
        strFirstname = document.getElementById("txtContFirstname").value;
        strLastname = document.getElementById("txtContLastname").value;
        strJobTitle = document.getElementById("txtContJobTitle").value;
        strDirectLine = document.getElementById("txtContDirectLine").value;
        strMobile = document.getElementById("txtContMobile").value;
        strEmail = document.getElementById("txtContEmail").value;
        intContactStatus = document.getElementById("cmbContStatus").options[document.getElementById("cmbContStatus").selectedIndex].value;
        if (intContactStatus.length<1){
            intContactStatus='j';
        }
        if(isNaN(intContactStatus)==true){
            intContactStatus = 0;
        }
        strComment = document.getElementById("txtContComment").value;
        boolBIContact =  document.getElementById("chkContBIContact").checked;
        boolContributor =  document.getElementById("chkContContributor").checked;
        boolPublishedContact =  document.getElementById("chkContPublishedContact").checked;
        //window.alert(boolBIContact);
        ret = ws_lg_Companies.ContactSave(intID, intCompanyID, strTitle, strFirstname, strLastname, strJobTitle, strDirectLine, strMobile, strEmail, intContactStatus, strComment, boolBIContact, boolContributor, boolPublishedContact, c_OnCompleteContactSave, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteContactSave(result){
        RefreshCompanyContactList();
        document.getElementById("ContactDetail").innerHTML = result;
    }    
    function c_ContactCancel(intCompanyID){
        intCompanyIDInProgress = intCompanyID;
        RefreshCompanyContactList();    
    }
    


    function c_AddAdvert(intCompanyID){
        //refresh the list
        document.getElementById("AdvertDetail").innerHTML = 'loading';
        intCompanyIDInProgress = intCompanyID; 
        ret = ws_lg_Companies.AddAdvert(intCompanyID, c_OnCompleteAdvertDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_AdvertDetail(intContactID){
        document.getElementById("AdvertDetail").innerHTML = 'loading';
        ret = ws_lg_Companies.AdvertDetail(intContactID, c_OnCompleteAdvertDetail, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteAdvertDetail(result){
        //refresh the list
        document.getElementById("AdvertDetail").innerHTML = result;
        c_ShowAdvertControls();
    }
    function c_SaveAd(intID, intCompanyID){
        var strURL = '';
        var boolLive;
        var strStartDate;
        var strEndDate;
        var strSupText = '';
        var intCountryID = '';
        var intCategoryID = '';
        var strSelected;
        var strImagePathLocal = '';
        var strImagePathLive = '';
        var strPosition = '';
        
        intCompanyIDInProgress = intCompanyID;
        boolLive = document.getElementById("chkAdLive").checked;
        strStartDate = document.getElementById("txtAdStartDate").value;
        strEndDate = document.getElementById("txtAdEndDate").value;
        
        intCountryID = CheckNumeric(intCountryID);
        intCategoryID = CheckNumeric(intCategoryID);
        
        strSelected= document.getElementById("cmbAdTypes").options[document.getElementById("cmbAdTypes").selectedIndex].value;
        if (strSelected == 'Logo'){
            //set the image path fields
            
        }else if (strSelected == 'Supplementary Text'){
            strSupText = document.getElementById("txtAdSupplementary").value;
        }else if (strSelected == 'Book Supplementary Text'){
            strSupText = document.getElementById("txtAdBookSupplementary").value;
        }else if (strSelected == 'Priority Listing'){

        }else if (strSelected == 'URL Link'){
            strURL = document.getElementById("txtAdURL").value;
        }else if (strSelected == 'Bold'){

        }        
        
        /*
        window.alert("id:" + intID);
        window.alert("selected:" + strSelected);
        window.alert("companyid:" + intCompanyID );
        window.alert("URL:" + strURL);
        window.alert("ImageLocal:" + strImagePathLocal );
        window.alert("Imagelive:" + strImagePathLive);
        window.alert("Sup:" + strSupText);
        window.alert("start:" + strStartDate);
        window.alert("end:" + strEndDate);
        window.alert("pos:" + strPosition);
        window.alert("Cat:" + intCategoryID);
        window.alert("Country:" + intCountryID);
        window.alert("live:" + boolLive);
        */
        ret = ws_lg_Companies.AdvertSave(intID, strSelected, intCompanyID, strURL, strImagePathLocal, strImagePathLive, strSupText, strStartDate, strEndDate, strPosition, intCountryID, intCategoryID, boolLive, c_OnCompleteSaveAd, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_OnCompleteSaveAd(result){
        if (result.length>0){
            window.alert(result);
        }
        RefreshCompanyAdvertList();
    }
    function RefreshCompanyAdvertList(){
        ret = ws_lg_Companies.RefreshCompanyAdverts(intCompanyIDInProgress, c_OnCompleteRefreshAdvertList, c_OnErrorGeneric, c_OnTimeoutGeneric);
    }
    function c_CancelAd(intCompanyID){
        intCompanyIDInProgress = intCompanyID;
        RefreshCompanyAdvertList();
    }
    
    function c_OnCompleteRefreshAdvertList(result){
        //refresh the list
        document.getElementById("AdvertDetail").innerHTML = '';
        document.getElementById("Adverts").innerHTML = result;
    }
    function c_RemoveAdvert(intID, intCompanyID){
        //remove the catorory association
        var resp= confirm("Do you really want to remove this advert from the company?");
        if (resp==true){
            intCompanyIDInProgress = intCompanyID;
            ret = ws_lg_Companies.RemoveAdvertFromCompany(intID, RefreshCompanyAdvertList, c_OnErrorGeneric, c_OnTimeoutGeneric);
        }    
    }

    function c_ShowAdvertControls(){
        var strSelected;
        //hide everything first
        document.getElementById("AdLogo").style.display='none';
        document.getElementById("AdSup").style.display='none';
        document.getElementById("AdPriority").style.display='none';
        document.getElementById("AdURL").style.display='none';
        document.getElementById("AdBold").style.display='none';
        document.getElementById("AdBookBold").style.display='none';
        document.getElementById("AdDetailImage").style.display='none';
        document.getElementById("AdBookLogo").style.display='none';
        document.getElementById("AdBookSup").style.display='none';
        
        strSelected= document.getElementById("cmbAdTypes").options[document.getElementById("cmbAdTypes").selectedIndex].value;
        if (strSelected == 'Logo'){
            document.getElementById("AdLogo").style.display='';
        }else if (strSelected == 'Book Logo'){
            document.getElementById("AdBookLogo").style.display='';        
        }else if (strSelected == 'Supplementary Text'){
            document.getElementById("AdSup").style.display='';        
        }else if (strSelected == 'Book Supplementary Text'){
            document.getElementById("AdBookSup").style.display='';        
        }else if (strSelected == 'Priority Listing'){
            document.getElementById("AdPriority").style.display='';        
        }else if (strSelected == 'URL Link'){
            document.getElementById("AdURL").style.display='';        
        }else if (strSelected == 'Bold'){
            document.getElementById("AdBold").style.display='';        
        }else if (strSelected == 'Book Bold'){
            document.getElementById("AdBookBold").style.display='';        
        }else if (strSelected == 'Detail Image'){
            document.getElementById("AdDetailImage").style.display='';        
        }
    }

    function CheckNumeric(input){
        var intOutput;
        intOutput= '';
        intOutput = new String(input);
        if (intOutput.length<1){
            intOutput='j';
        }
        if(isNaN(intOutput)==true){
            intOutput = 0;
        }
        return intOutput;
    }

    function c_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 c_OnTimeoutGeneric(result){
        window.alert("There was a time-out in the lg_Company web service: " + result);
    }    
