﻿function HideShowTicInfo(isTic)
{
    var show = isTic ? "":"none";
    //DisableValidator(false);
    document.getElementById('TicInfoCompanyName').style.display = show;
    document.getElementById('TicInfoPhone').style.display = show;
    document.getElementById('TicInfoWebsite').style.display = show;
}

function DisableValidator(show)
{
    var companyNameFieldValidator = document.getElementById('ctl00_MainContentPlaceHolder_companyNameFieldValidator');
    var telephoneFieldValidator = document.getElementById('ctl00_MainContentPlaceHolder_telephoneFieldValidator');

    //ValidatorEnable(companyNameFieldValidator, show);
    //ValidatorEnable(telephoneFieldValidator, show);

    var visibility = !show ? "" : "none";
    companyNameFieldValidator.style.display = visibility;
    telephoneFieldValidator.style.display = visibility;
    
    // unvalidate all validators
    Unvalidate("joinnow");
}

function ShowCountryControls()
{
    var countriesDropDownList = document.getElementById('ctl00_MainContentPlaceHolder_countriesDropDownList');
    var enabledCountriesDropDownList = document.getElementById('ctl00_MainContentPlaceHolder_enabledCountriesDropDownList');

    var buyerRadioButton = document.getElementById('ctl00_MainContentPlaceHolder_BuyerRadioButton');
    if (buyerRadioButton.checked)
    {
        HideShowTicInfo(false);
        // 'Buyer' option selected
        countriesDropDownList.style.display = 'block';
        enabledCountriesDropDownList.style.display = 'none';
        return;
    }
    
    var ticCompanyRadioButton = document.getElementById('ctl00_MainContentPlaceHolder_TicCompanyRadioButton');
    if (ticCompanyRadioButton.checked)
    {
        HideShowTicInfo(true);
        
        // 'IT Company' option selected
        countriesDropDownList.style.display = 'none';
        enabledCountriesDropDownList.style.display = 'block';
        
        var defaultCountryName = document.getElementById('ctl00_MainContentPlaceHolder_DefaultCountryName');
        var enabledCountriesListControl = document.getElementById('ctl00_MainContentPlaceHolder_enabledCountriesListControl_countriesDropDownList');
        var showCountryControl = document.getElementById('ctl00_MainContentPlaceHolder_showCountryControl').value;

        if (showCountryControl == 'false')
        {
            enabledCountriesListControl.style.display = 'none';
            defaultCountryName.style.display = 'block';
        }
        else
        {
            enabledCountriesListControl.style.display = 'block';
            defaultCountryName.style.display = 'none';
        }
        return;
    }
}

function ValidateChecked(source, args)
{
    args.IsValid = document.getElementById('ctl00_MainContentPlaceHolder_TermsOfUseCheckBox').checked;
}

function loadTermsText()
{
    var currentLanguageHidden = document.getElementById('ctl00_MainContentPlaceHolder_CurrentLanguageHidden');
    // base language
    var currentLanguage = "en";
    if ((currentLanguageHidden != null) && (currentLanguageHidden.value != ""))
    {
        currentLanguage = currentLanguageHidden.value;
    }

    // define a response handler
    function responseHandler(ajaxRequest)
    {
        var responseText = ajaxRequest.responseText;
        var theDiv = document.getElementById("TermsOfUseTextDiv");
        if (theDiv == null)
            return;
        theDiv.innerHTML = responseText;
        
        // show the PopUp
        showPopUp('TermsOfUsePopUp',500,600);
    }
    
    // 'ticks' used to avoid Cache
    var date = new Date()
    var ticks = date.getTime()
    ajaxSend('get', '/portal/GetFile.aspx', 'action=getText&file=info/TermsOfUse_'+currentLanguage+'.html&null='+ticks, responseHandler);
}

function Unvalidate(myValidationGroup)
{
    // Remove the validator control(s) from display.
    var myValidators = Page_Validators;
    if ((typeof(myValidators) != "undefined") && (myValidators != null))
    {
        for (i=0;i<myValidators.length;i++)
        {
            var myValidator = myValidators[i];
            if (myValidationGroup == null || IsValidationGroupMatch(myValidator, myValidationGroup))
            {
                if (myValidator.style.visibility.length > 0 && myValidator.style.display.length == 0)
                {
                    myValidator.style.visibility = 'hidden';
                }
                else if (myValidator.style.display.length > 0 && myValidator.style.visibility.length == 0)
                {
                    myValidator.style.display = 'none';
                }
            }
        }
    }

    // Remove the validator summary(ies) from display.
    var mySummaries = Page_ValidationSummaries;
    if ((typeof(mySummaries) != "undefined") && (mySummaries != null))
    {
        for(i=0;i<mySummaries.length;i++)
        {
            var mySummary = mySummaries[i];
            if (myValidationGroup == null || IsValidationGroupMatch(mySummary, myValidationGroup))
            {
                mySummary.style.display = 'none';
            }
        }
    }
}