﻿var previewLocation = "";
function PageLoad() {
    var drpCountry = document.getElementById('drpCountry');
    var countryID = document.getElementById('drpCountry').value;
    fillLocations();
    ShowPreview();

}
function GetLocations() {
    var hiddenLocationField = document.getElementById('hdnSelectedLocations');
    var hiddenLocationFieldTemp = document.getElementById('hdnSelectedLocationsTemp');
    hiddenLocationFieldTemp.value = hiddenLocationField.value;
    PopulateLocations();

}
function CancelLocationSelect() {
    var hiddenLocationFieldTemp = document.getElementById('hdnSelectedLocationsTemp');
    hiddenLocationFieldTemp.value = "";
    return ClosePopUp('divSelectLocations');
}
function SaveLocationSelect() {

    var hiddenLocationField = document.getElementById('hdnSelectedLocations');
    var hiddenLocationFieldTemp = document.getElementById('hdnSelectedLocationsTemp');
    hiddenLocationField.value = hiddenLocationFieldTemp.value;
    hiddenLocationFieldTemp.value = "";
    UpdateSelectedfFullLocationField();
    return ClosePopUp('divSelectLocations');
}
function PopulateLocations() {
    var hiddenLocationFieldTemp = document.getElementById('hdnSelectedLocationsTemp');
    ShowLocations();
    var countryID = document.getElementById('drpCountry').value;
    var stateID = document.getElementById('drpState').value;
    var tbl = document.getElementById('tblLocations');
    var xPath = "";
    var locationDetails = new Array();
    if (stateID == 0) {
        xPath = "LocationList/Country[@Id=" + countryID + "]/State";
        var states = GetNodeList(xPath);
        for (var i = 0; i < states.length; i++) {
            xPath = "LocationList/Country[@Id=" + countryID + "]/State[@Id=" + states[i].attributes[0].value + "]/Location";
            var locations = GetNodeList(xPath);
            for (var j = 0; j < locations.length; j++) {
                locationDetails.push(locations[j].attributes[1].value + "|" + locations[j].attributes[0].value);

            }
            

        }
    }
    else
    {
        xPath = "LocationList/Country[@Id=" + countryID + "]/State[@Id=" + stateID + "]/Location";
        var locations = GetNodeList(xPath);
        for (var j = 0; j < locations.length; j++) {
            locationDetails.push(locations[j].attributes[1].value + "|" + locations[j].attributes[0].value);
        }
    }
    locationDetails.sort();
    var htmlString = "<table><tr>";
    for (var i = 0; i < locationDetails.length; i++) {
        if (i % 3 == 0 && i != 0) {
            htmlString += "</tr><tr>";
        }
        var loc = locationDetails[i].split("|");
        var id = loc[1];
        var text = loc[0];
        var locationText = text + "_" + id;
        
        var isSelected = false; ;
        if (hiddenLocationFieldTemp.value.indexOf(locationText + "|") > -1) {
            isSelected = true;
            var opt = document.createElement('option');
//            opt.value = id;
//            opt.text = locationText;
//            document.getElementById('lstLocations').options.add(opt);
        }        
        htmlString += "<td>";
        htmlString += "<input type=\"checkbox\" class=\"chkbox\" text=\"" + text + "\" id=\"chkLoc_" + id + "\" value=\"" + id + "\" onclick=\"CheckLocation(this)\" name=\"location\" ";
        if (isSelected) {
            htmlString += "checked = \"checked\"";
        }
        htmlString += ">";
        htmlString += "<label id=\"lbl_" + id + "\" for=\"chkLoc_" + id + "\">" + text + "</label>";
        htmlString += "</td>";
        
    }
    htmlString += "</tr></table>";
    document.getElementById('pLocations').innerHTML = htmlString;
    //for(var  i = 0; i < lo
}
function SortFunction(a, b) {
    a = a.substring(a.lastIndexOf('|') + 1);
    b = b.substring(b.lastIndexOf('|') + 1);
}
function CheckLocation(chk) {
    var compID = chk.id;
    var suffix = compID.substring(compID.lastIndexOf('_') + 1);
    var lbl = document.getElementById("lbl_" + suffix);
    var locationText = chk.getAttribute('text');
    var locationID = chk.value;
    var hiddenLocationField = document.getElementById('hdnSelectedLocationsTemp');
    
    var selectedLocation = locationText + "_" + locationID;
    var opt = document.createElement('option');
    opt.value = locationID;
    opt.text = locationText;
    if (chk.checked) {
        hiddenLocationField.value += selectedLocation + "|";
        var selectedLocations = document.getElementById('lblSelectedLocs').innerHTML;
        document.getElementById('lstLocations').options.add(opt);
    }
    else {
        hiddenLocationField.value = hiddenLocationField.value.replace(selectedLocation + "|", "");
        var lstLocations = document.getElementById('lstLocations');
        for (var i = lstLocations.options.length - 1; i >= 0; i--) {
            if (lstLocations[i].value == locationID) {
                lstLocations.remove(i);
            }
        }
    }
    UpdateSelectedLocationField();
    //alert(hiddenLocationField.value);
}
function UpdateSelectedLocationList() {
    var lstLocations = document.getElementById('lstLocations');
    var hiddenLocationField = document.getElementById('hdnSelectedLocations');
    var selectedLocations = hiddenLocationField.value;
    var locationDetails = selectedLocations.split('|');
    var flg = false;
    ClearAllDropDownItems(lstLocations);
    for (var i = 0; i < locationDetails.length; i++) {
        if (locationDetails[i] != "") {
            var loc = locationDetails[i].split('_');
            var locText = loc[0];
            var locID = loc[1];
            var opt = document.createElement('option');
            opt.value = locID;
            opt.text = locText;
            document.getElementById('lstLocations').options.add(opt);
            
        }
    }
}
function UpdateSelectedLocationField() {
    var lblSelectedLocationField = document.getElementById('lblSelectedLocs');
    var hiddenLocationField = document.getElementById('hdnSelectedLocationsTemp');
    var selectedLocations = hiddenLocationField.value;
    if (selectedLocations.indexOf('|') > -1) {
        var locationDetails = selectedLocations.split('|');
        var flg = false;
        for (var i = 0; i < locationDetails.length; i++) {
            if (locationDetails[i] != "") {
                var loc = locationDetails[i].split('_');
                var locText = loc[0];
                if (i == 3) {
                    flg = true;
                    break;
                }
                if (i == 0) {
                    lblSelectedLocationField.innerHTML = locText;
                }
                else if (locText != "") {
                    lblSelectedLocationField.innerHTML += ", " + locText;
                }
            }

        }
        if (flg) {
            lblSelectedLocationField.innerHTML += "..";
        }
    }
    else {
        lblSelectedLocationField.innerHTML = "";
    }
}
function UpdateSelectedfFullLocationField() {
    var txtArea = document.getElementById('txtAreaLocations');
    txtArea.style.display = "";
    var hiddenLocationField = document.getElementById('hdnSelectedLocations');
    var selectedLocations = hiddenLocationField.value;
    previewLocation = "";
    if (selectedLocations.indexOf('|') > -1) {
        var locationDetails = selectedLocations.split('|');
        var flg = false;
        for (var i = 0; i < locationDetails.length; i++) {
            if (locationDetails[i] != "") {
                var loc = locationDetails[i].split('_');
                var locText = loc[0];

                if (i == 0) {
                    previewLocation = Trim(locText);
                    txtArea.value = Trim(locText);
                }
                else if (locText != "") {
                    txtArea.value += ", " + Trim(locText);
                }
            }

        }
    }
    else {
        txtArea.value = "";
    }
    RenderPreview(txtArea);
//    var jobLocDestn = document.getElementById('spnLocation');
//    if (Trim(previewLocation) != "") {
//        
//        jobLocDestn.innerHTML = ", " + previewLocation;
//    }
//    else {
//        jobLocDestn.innerHTML = "&nbsp;";
//        
//    }
    
}
function RemoveOption() {
    var lstLocations = document.getElementById('lstLocations');
    var hiddenLocationField = document.getElementById('hdnSelectedLocationsTemp');
    var selectedLocation = "";
    for (var i = lstLocations.options.length - 1; i >= 0; i--) {
        if (lstLocations[i].selected) {
            selectedLocation = lstLocations[i].text + "_" + lstLocations[i].value; ;
            hiddenLocationField.value = hiddenLocationField.value.replace(selectedLocation + "|", "");
            lstLocations.remove(i);
        }
    }
}
function ShowEditPane() {
    document.getElementById('divEditLocations').style.display = "";
    document.getElementById('divLocations').style.display = "none";
    document.getElementById('pSelectState').style.display = "none";
    document.getElementById('pLocEditLnks').style.display = "none";
    document.getElementById('pLocationCtrls').style.display = "none";
    document.getElementById('pLocEditCtrls').style.display = "";
    
}
function ShowLocations() {
    document.getElementById('divEditLocations').style.display = "none";
    document.getElementById('divLocations').style.display = "";
    document.getElementById('pSelectState').style.display = "";
    document.getElementById('pLocEditLnks').style.display = "";
    document.getElementById('pLocationCtrls').style.display = "";
    document.getElementById('pLocEditCtrls').style.display = "none";
}
function ShowLocationStates() {

    document.getElementById('drpState').setAttribute("DialogueElement", "1");
    document.getElementById('lstLocations').setAttribute("DialogueElement", "1");
    document.getElementById('drpState').length = 0;
    SetDimmerDivProperties("Background Color", "black");
    ShowPopUpWindow('divSelectLocations');
    document.getElementById('divSelectLocations').style.display = "";
    
    var countryID = document.getElementById('drpCountry').value;
    var xPath = "LocationList/Country[@Id=" + countryID + "]/State";
    var states = GetNodeList(xPath);
    var dropState = document.getElementById('drpState');
    clearDropDown(dropState);
    var opt = document.createElement('option');
    opt.value = "0";
    opt.text = "---All Locations---";
    opt.selected = true;
    dropState.options.add(opt);
    for (var i = 0; i < states.length; i++) {
        opt = document.createElement('option');
        opt.value = states[i].attributes[0].value;
        opt.text = states[i].attributes[1].value;
        dropState.options.add(opt);
    }
    GetLocations();
}
function GetValue(xpath, attrName) {
    var value = "";
    var xmlData = new XML(null);
    var locations = document.getElementById("hdnCountryLocations").value;
    xmlData.loadXML(locations);
    value = xmlData.getNodeAttributeValue(xpath, attrName);
    return value;
}
function GetNodeList(xpath) {
    var value = "";
    var xmlData = new XML(null);
    var locations = document.getElementById("hdnCountryLocations").value;
    xmlData.loadXML(locations);
    value = xmlData.getNodes(xpath);
    return value;
}
function ClearLocationHiddenField() {
    document.getElementById('hdnSelectedLocations').value = "";
}

function fillLocations() {
   
    var locations = document.getElementById("hdnCountryLocations").value;
    if(locations.indexOf("<Country Id=\""+document.getElementById('drpCountry').value + "\">") > -1)
    {
        document.getElementById('txtLocation').value = "";
        document.getElementById('lnkAddLoc').style.display = '';
        document.getElementById('txtLocation').style.display = 'none';
        if (document.getElementById('hdnSelectedLocations').value != "") {
            UpdateSelectedfFullLocationField();
            document.getElementById('hdnSelectedLocationsTemp').value = document.getElementById('hdnSelectedLocations').value;
            UpdateSelectedLocationField();
            UpdateSelectedLocationList();
        }
        else {
            var lstLocations = document.getElementById('lstLocations');
            ClearAllDropDownItems(lstLocations);
        }
        
    }
    else{
        document.getElementById('lnkAddLoc').style.display = 'none';
        document.getElementById('txtLocation').style.display = '';
        document.getElementById('hdnSelectedLocations').value = "";
        document.getElementById('txtAreaLocations').style.display = "none";
    }
}
function clearDropDown(dropDown) {
    if (dropDown) {
        var count = dropDown.length;
        if (count > 1) {
            for (var i = count; i >= 0; i--) {
                dropDown.remove(i);
            }
        }
    }
}
function ClearAllDropDownItems(dropDown) {
    if (dropDown) {
        var count = dropDown.length;
        for (var i = count; i >= 0; i--) {
            dropDown.remove(i);
        }
        
    }
}

function RenderValidTill() {
    var validTill = "";
    if (Trim(document.getElementById('txtStartDate').value) != "") {
        var activeFrom = new Date(document.getElementById('txtStartDate').value);
        validTill = new Date(activeFrom);
        validTill.setDate(parseInt(activeFrom.getDate()) + 30);
        validTill = constructDate(validTill.getDate(), validTill.getMonth(), validTill.getFullYear())
        validTill += "&nbsp;";
        var hntValidTill = "<a href='javascript:void(0)' onblur='HideToolTip();' class='newBrownAnchor' onfocus='DisplayToolTipCreateJob(this);' id='lnkValidTill'>(?)</a>";
        validTill += hntValidTill;
    }
    HideToolTip();
    
    document.getElementById('lblValidTill').innerHTML = validTill;
}

function ValidatePages(currentDate,comp) {
    var pageValid = true;
    pageValid = ValidateControl(document.getElementById('txtCompanyName'), document.getElementById('lblErrorCompanyName'), "Please enter company name", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtCompanyContact'), document.getElementById('lblErrorCompanyContact'), "Please enter company contact", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtEmailResume'), document.getElementById('lblErrorEmailResume'), "Please enter email address", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtJobTitle'), document.getElementById('lblErrorJobTitle'), "Please enter job title", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('drpExperienceFrom'), document.getElementById('lblErrorExperience'), "Please select experience from", "dropdown") && pageValid;
    if (document.getElementById('drpExperienceFrom').selectedIndex > 0) {
        pageValid = ValidateControl(document.getElementById('drpExperienceTo'), document.getElementById('lblErrorExperience'), "Please select experience to", "dropdown") && pageValid;
    }
    pageValid = ValidateControl(document.getElementById('drpCountry'), document.getElementById('lblErrorCountry'), "Please select country", "dropdown") && pageValid;

    if (document.getElementById('txtLocation').style.display == "none") {
        pageValid = ValidateControl(document.getElementById('txtAreaLocations'), document.getElementById('lblErrorLocation'), "Please select atleast a location", "text") && pageValid;
    }
    else {
        pageValid = ValidateControl(document.getElementById('txtLocation'), document.getElementById('lblErrorLocation'), "Please enter location", "text") && pageValid;
    }
    
    pageValid = ValidateControl(document.getElementById('drpCategory'), document.getElementById('lblErrorJobCategory'), "Please select a job category", "dropdown") && pageValid;
    pageValid = ValidateControl(document.getElementById('ddlRole'), document.getElementById('lblErrorRole'), "Please select a role", "dropdown") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtEducation'), document.getElementById('lblEducationError'), "Please enter education", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtStartDate'), document.getElementById('lblErrorValidDate'), "Please select start date", "text") && pageValid;
    pageValid = ValidateControl(document.getElementById('txtShortDescription'), document.getElementById('lblErrorShortDescription'), "Please enter short description", "text") && pageValid;
    var jobDescriptionComp = document.getElementById('RTEJobDescription').contentWindow.document.getElementsByTagName('body')[0];
    pageValid = ValidateControl(jobDescriptionComp, document.getElementById('lblErrorJobDescription'), "Please enter job description", 'richtext') && pageValid;
    if (pageValid) {
        pageValid = updateRTE('RTEJobDescription', 3500, false) && pageValid;
        if (!pageValid) {
            ShowErrorMsg(document.getElementById('lblErrorJobDescription'), "Please limit Description to "+(parseInt(4000) - 500)+"  characters.");
        }
    }
    var aboutCompComp = document.getElementById('RTEAboutCompany').contentWindow.document.getElementsByTagName('body')[0];

    var validAbtComp = ValidateControl(aboutCompComp, document.getElementById('lblErrorAboutComp'), "Please enter company details", 'richtext') && pageValid;
    if (validAbtComp) {
        validAbtComp = updateRTE('RTEAboutCompany', 3500, false);
        if (!validAbtComp) {
            ShowErrorMsg(document.getElementById('lblErrorAboutComp'), "Please limit Description to " + (parseInt(4000) - 500) + "  characters.");
            pageValid = false;
        }
    }
    else {
        pageValid = false;
    }
   
    var advancedValidations = true && pageValid;
    if (Trim(document.getElementById('txtEmailResume').value) != "") {
        var emailValid = emailCheck(document.getElementById('txtEmailResume').value)
        advancedValidations = emailValid && advancedValidations;
        if (!emailValid) {
            ShowErrorMsg(document.getElementById('lblErrorEmailResume'), "Please enter a valid email address");
        }
        else {
            HideErrorMsg(document.getElementById('lblErrorEmailResume'));
        }

    }
    if (document.getElementById('drpExperienceFrom').selectedIndex != 0 && document.getElementById('drpExperienceTo').selectedIndex != 0) {
        var expFrom = document.getElementById('drpExperienceFrom').selectedIndex;
        var expTo = document.getElementById('drpExperienceTo').selectedIndex;
        if (expTo < expFrom) {
            advancedValidations = false;
            ShowErrorMsg(document.getElementById('lblErrorExperience'), "Please select a valid experience range");
        }
        else {
            advancedValidations = true && advancedValidations;
            HideErrorMsg(document.getElementById('lblErrorExperience'))
        }
    }
    var fromDate = document.getElementById('txtStartDate').value;
    if (fromDate != "") {
        fromDate = new Date(document.getElementById('txtStartDate').value);
        var dateDiff = (fromDate.getTime() - new Date(currentDate).getTime()) / 86400000;
        var jobStatus = document.getElementById('hdnJobStatus').value;
        if (dateDiff < 0 && jobStatus == "NA") {
            advancedValidations = false;
            ShowErrorMsg(document.getElementById('lblErrorValidDate'), "Start date should not be a previous day");
        }

    }
    if (Trim(document.getElementById('txtSalaryFrom').value) != "") {
        if (isDecimal(document.getElementById('txtSalaryFrom').value)) {
            HideErrorMsg(document.getElementById('lblErrorSalary'));
            var salary = document.getElementById('txtSalaryFrom').value.split('.');
            var decimalPart = salary[0];
            var fractionalPart = salary[1];
            var noErr = true;
            if (decimalPart != null) {
                if (decimalPart.length > 10) {
                    ShowErrorMsg(document.getElementById('lblErrorSalary'), "Decimal Part should not exceed of length 10");
                    noErr = false;
                }
                else {
                    HideErrorMsg(document.getElementById('lblErrorSalary'));
                }
            }
            if (fractionalPart != null && noErr) {
                if (fractionalPart.length > 2) {
                    ShowErrorMsg(document.getElementById('lblErrorSalary'), "Decimal Part should not exceed of length 2");
                    noErr = false;
                }
                else {
                    HideErrorMsg(document.getElementById('lblErrorSalary'));
                }
            }

            advancedValidations = true && noErr && advancedValidations;

        }
        else {
            ShowErrorMsg(document.getElementById('lblErrorSalary'), "Please enter a valid salary");
            advancedValidations = false && advancedValidations;

        }


    }
    if (Trim(document.getElementById('txtSalaryTo').value) != "" && advancedValidations) {
        if (isDecimal(document.getElementById('txtSalaryTo').value)) {
            HideErrorMsg(document.getElementById('lblErrorSalary'));
            var salary = document.getElementById('txtSalaryTo').value.split('.');
            var decimalPart = salary[0];
            var fractionalPart = salary[1];
            var noErr = true;
            if (decimalPart != null) {
                if (decimalPart.length > 10) {
                    ShowErrorMsg(document.getElementById('lblErrorSalary'), "Decimal Part should not exceed of length 10");
                    noErr = false;
                }
                else {
                    HideErrorMsg(document.getElementById('lblErrorSalary'));
                }
            }
            if (fractionalPart != null && noErr) {
                if (fractionalPart.length > 2) {
                    ShowErrorMsg(document.getElementById('lblErrorSalary'), "Decimal Part should not exceed of length 2");
                    noErr = false;
                }
                else {
                    HideErrorMsg(document.getElementById('lblErrorSalary'));
                }
            }
            advancedValidations = true && noErr && advancedValidations;
        }
        else {
            ShowErrorMsg(document.getElementById('lblErrorSalary'), "Please enter a valid salary");
            advancedValidations = false && advancedValidations;
        }


    }
    if (!advancedValidations) {
        ShowErrorMsg(document.getElementById('lblError'), "You have not filled-in some of the mandatory fields required for your job post. Please verify.");

    }
    if (comp.id == "btnPreviewJob") {
        if (advancedValidations) {
            advancedValidations = false;
            CreateCordiantConfirm("Jobs Preview", "Your Job Posting will be implicitly saved on Preview. <br/>Are you sure you want to continue?", "ReturnToPage()");
        }
        
    }
    return advancedValidations;
}
function ReturnToPage() {
    __doPostBack("btnPreviewJob", "Click");
    
}

function isDecimal(val) {
    if (Trim(val) == "") {
        return true;
    }
    if (parseFloat(val) == 0) {
        return true;
    }
    //return /^\d+(\.\d+)?$/.test(val) Checking for .0ddd values also..;-)
    return ((/^\.\d+?$/.test(val)) || (/^\d+(\.\d+)?$/.test(val)));
}




function RenderPreview(comp) {

    var contentComp = "";
    switch (comp.id) {
        case "txtJobTitle": contentComp = "spnJobTitle";
            break;
        case "txtShortDescription": contentComp = "spnJobShortDescription";
            break;
        case "txtLocation": 
        case "txtAreaLocations": 
            contentComp = "spnLocation";
            break;

    }
    if (contentComp != "") {
        var contentCompObj = document.getElementById(contentComp);
        if (contentCompObj != null) {
            contentCompObj.innerHTML = comp.value;
            ShowPreview();
        }
    }
}
function isMaxLength(obj, maxLength) {
    if (obj.value.length > maxLength) {
        obj.value = obj.value.substring(0, maxLength);
    }
}
function ShowPreview() {
    var isAllEmpty = true;
    var jobTitleSource = document.getElementById("txtJobTitle");
    var jobTitleDestn = document.getElementById("spnJobTitle");
    var jobLocSource = document.getElementById('txtLocation');
    var isTextArea = false;
    if(jobLocSource.style.display == "none")
    {
        isTextArea = true;
        jobLocSource = document.getElementById('txtAreaLocations');
    }
    var jobDescSource = document.getElementById("txtShortDescription");
    var jobDescDestn = document.getElementById("spnJobShortDescription");
    var jobLocDestn = document.getElementById('spnLocation');
    if (Trim(jobTitleSource.value) != "") {
        jobTitleDestn.innerHTML = jobTitleSource.value;  
         isAllEmpty = false;
    }
    else {
        jobTitleDestn.innerHTML = "&nbsp;";

    }
    if (Trim(jobDescSource.value) != "") {
        jobDescDestn.innerHTML = ": " + jobDescSource.value;  
         isAllEmpty = false;
    }
    else {
        jobDescDestn.innerHTML = "&nbsp;";

    }
    
     if (Trim(jobLocSource.value) != "") {
        if(isTextArea)
        {
            jobLocDestn.innerHTML = ", " + previewLocation;  
        }
        else{
            jobLocDestn.innerHTML = ", " + jobLocSource.value;  
        }
        isAllEmpty = false;
    }
    else {
        jobLocDestn.innerHTML = "&nbsp;";

    }
   
    
    if (document.getElementById("divJobDescPreview").style.display == "none") {
        document.getElementById("divJobDescPreview").style.display = "";
        document.getElementById("lnkShowPreview").style.display = "none";
    }
    if ( isAllEmpty )
    {
        jobTitleDestn.innerHTML = "HR Manager: ";
        jobDescDestn.innerHTML = "Responsible for HR operations, IR, Statutory Compliance, Legal Functions, ";
        jobLocDestn.innerHTML = "Chennai";
    }
}

function FormatDecimal(obj) {
    if (Trim(obj.value) == "") {
        obj.value = "0.00";
    }
    else {
        if (isDecimal(obj.value)) {
            if (obj.value.indexOf('.') < 0) {
                obj.value = obj.value + ".00";
            }
        }
    }
}

function ConfirmClose() {
    CreateCordiantConfirm("Unsaved changes will be lost.", "All unsaved changes will be lost. <br/>Are you sure you want to continue?", "RedirectToPostings()");
}

function RedirectToPostings() {
    var redirectPage = document.getElementById('hdnPage').value;
    location.href = redirectPage;

}

/* XML Parser*/
// XML
//
function XML(xmlDom) {
    this.isIE = window.ActiveXObject;

    if (xmlDom != null) {
        this.xmlDom = xmlDom;
    }
};

//


// load XML from string
XML.prototype.loadXML = function(xmlString) {
    // create XML dom
    if (this.isIE) {

        this.xmlDom = new ActiveXObject("Msxml2.DOMDocument");
        this.xmlDom.async = false;
        this.xmlDom.loadXML(xmlString);
    }
    else {
        var parser = new DOMParser();
        this.xmlDom = parser.parseFromString(xmlString, 'text/xml');
    }
};

//
// getNode
// get a single node from the XML DOM using the XPath
XML.prototype.getNode = function(xpath) {
    var result;

    if (this.isIE) {
        result = this.xmlDom.selectSingleNode(xpath);
    } else {
        var evaluator = new XPathEvaluator();

        result = evaluator.evaluate(xpath, this.xmlDom, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    }
    return result;
};

//

// getNodes
// get a single node from the XML DOM using the XPath
XML.prototype.getNodes = function(xpath) {
    var result;

    if (this.isIE) {
        result = this.xmlDom.selectNodes(xpath);
    } else {
        var evaluator = new XPathEvaluator();
        var oResult;
        oResult = evaluator.evaluate(xpath, this.xmlDom, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
        result = new Array;

        if (oResult != null) {
            var oElement = oResult.iterateNext();
            while (oElement) {
                result.push(oElement);
                oElement = oResult.iterateNext();
            }
        }

    }
    return result;
};

//

// getNodeAttributeValue
// get a specific node attribute value in the XML DOM
XML.prototype.getNodeAttributeValue = function(xpath, attributeName) {
    var value;
    xpath = xpath + "/@" + attributeName;

    value = this.getNodeValue(xpath);
  

    return value;
};

//     getNodeAttributeValue
/* XML Parser*/

//Added for logo uploads 
function closePopUp(popup) {
    CloseWindow(popup);
}
function ShowLogoPopUp() {
    SetDimmerDivProperties("Sliding Style", "BOTTOM_SCROLL_CENTER");
    SetDimmerDivProperties("Background Color", "black");
    ShowPopUpWindow("divUploadLogo");
    document.getElementById("divUploadLogo").style.display = "";
}
function CheckPhotoExists() {
    ScrollToPosition();
    if (document.getElementById('imgPreviewImage').src.indexOf('trans.gif') > 0) {
        document.getElementById('pAddCompanyLogo').style.display = '';
        document.getElementById('pEditCompanyLogo').style.display = 'none';
        
    }
    else {
        document.getElementById('pAddCompanyLogo').style.display = 'none';
        document.getElementById('pEditCompanyLogo').style.display = '';

    }
    
   
}
function deletePhoto() {
    document.getElementById('imgPreviewImage').src = document.getElementById('hdnBlankImage').value;
    document.getElementById('hdnImageSource').value = "";
    document.getElementById('pAddCompanyLogo').style.display = '';
    document.getElementById('pEditCompanyLogo').style.display = 'none';
}


function validateSave() {

    if (Trim(document.getElementById('txtCompanyLogo').value) == "") {
        CreateCordiantAlert("Jobs", "Please upload a logo. ", "txtCompanyLogo");
        document.getElementById('txtCompanyLogo').focus();
        return false;

    }
    if (!Checkfiles()) {
        CreateCordiantAlert("Jobs", "Please upload a valid file.(Only  GIF, JPEG, PNG , JPG , BMP or TIF files allowed)");
        return false;

    }
    UpdateRichTexts();
    return true;
}
function UpdateRichTexts() {
    updateRTE('RTEAboutCompany', 4000, false);
    updateRTE('RTEJobDescription', 4000, false);
}
function Checkfiles() {
    var fup = document.getElementById('txtCompanyLogo');
    var fileName = fup.value;
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
    ext = ext.toUpperCase();
    if (ext == "GIF" || ext == "JPEG" || ext == "PNG" || ext == "JPG" || ext == "TIF" || ext == "BMP") {
        return true;
    }
    else {

        fup.focus();
        return false;
    }
}

   function GetCoordinates()
   {
      var scrollX, scrollY;
      
      if (document.all)
      {
         if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
         else
            scrollX = document.documentElement.scrollLeft;
               
         if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
         else
            scrollY = document.documentElement.scrollTop;
      }   
      else
      {
         scrollX = window.pageXOffset;
         scrollY = window.pageYOffset;
      }
   
      document.getElementById('xCoordHolder').value = scrollX;
      document.getElementById('yCoordHolder').value = scrollY;
   }
   
   function ScrollToPosition()
   {
      var x = document.getElementById('xCoordHolder').value;
      var y = document.getElementById('yCoordHolder').value;
      window.scrollTo(x, y);
   }
   