function SearchEnter(textboxName, buttonName) 
{
	//var textbox = document.getElementById(textboxName);
	var searchButton = document.getElementById(buttonName);
	if (eval(searchButton)){
		if (event.keyCode && event.keyCode == 13){ 
			event.cancel = true;
			event.returnValue = false;
			searchButton.click();
		}
	}
}

function CheckSearchTerm(targetId){
	var obj = document.getElementById(targetId);
	if(obj){
		var txt = obj.value;
		if (txt.length < 3){
			alert("You must enter at least 3 characters to search.");
			return false;
		}
		if (txt=='Search this site'){
			alert("Please enter a search term.");
			return false;
		}
	}
}

function WarningRememberMe(targetID) 
{   
    var cbRememberMe = document.getElementById(targetID);
    if (cbRememberMe.checked)
    {
        var message = "If you tick this box you will no longer need to login\nwhen visiting THE EDGE website.\n\n";
        message += "Disable this feature any time by logging out of the website.\n\nDon't use this option unless you are the only person\nwho has access to this computer.\n\n";
        message += "WARNING: If you decide to use this option you will be responsible for\nthe actions of anyone who uses your login.";                
        var confirmMessage = window.confirm(message);
        if (confirmMessage)
            cbRememberMe.checked = true;
        else
            cbRememberMe.checked = false;
    }
}

function ValidateAddress(source, args)
{    
    document.getElementById("htmlMsg").innerHTML = '';    
    if (document.getElementById("ctl00_plcMain_chkByPost").checked)
    {
        if (document.getElementById("ctl00_plcMain_txtStreet").value == "" || document.getElementById("ctl00_plcMain_ddlCountry").value == "")
            args.IsValid = false;
    }
}

function ValidateCountry(source, args)
{
    var iSelectedIndex = document.getElementById("ctl00_plcGeneral_ddlCountry").selectedIndex;
    var sSelectedText = document.getElementById("ctl00_plcGeneral_ddlCountry").options[iSelectedIndex].text;
    if (sSelectedText == '')
        args.IsValid = false;
}

function ValidateRegion(source, args)
{
    var ddlRegion = document.getElementById("ctl00_plcGeneral_ddlRegion");
    var iSelectedIndex = ddlRegion.selectedIndex;
    var sSelectedText = ddlRegion.options[iSelectedIndex].text;
    var iOptionCount = ddlRegion.options.length;
    if (iOptionCount > 1 && sSelectedText == '')
        args.IsValid = false;
}

function CheckPasswordsMatch(source, args)
{
    var txtPwd = document.getElementById("ctl00_plcMain_txtPwd");
    var txtConfirmPwd = document.getElementById("ctl00_plcMain_txtConfirmPwd");

    if (txtPwd.value.toLowerCase() != txtConfirmPwd.value.toLowerCase())
    {
        args.IsValid = false;
    }
}

function ValidateAddressGeneral(source, args)
{
    if (document.getElementById("ctl00_plcGeneral_chkByPost").checked)
    {
        if (document.getElementById("ctl00_plcGeneral_txtStreet").value == "" || document.getElementById("ctl00_plcGeneral_ddlCountry").value == "")
            args.IsValid = false;
    }
}

function ValidatePaymentAddress(source, args)
{    
    document.getElementById("htmlMsg").innerHTML = '';    
    if (document.getElementById("ctl00_plcMain_ddlShipping").value != '-1')
    {
        if (document.getElementById("ctl00_plcMain_txtStreetAddress").value == "" || document.getElementById("ctl00_plcMain_txtCity").value == "" || document.getElementById("ctl00_plcMain_ddlRegion").value == "" || document.getElementById("ctl00_plcMain_ddlCountry").value == "")
            args.IsValid = false;
    }
}
   
function ValidateExpiryDateSel(source, args)
{
    var ddlExpiryYear = document.getElementById('ctl00_plcMain_ddlExpiryYear');
    var ddlExpiryMonth = document.getElementById('ctl00_plcMain_ddlExpiryMonth');
    
    var dtNow = new Date();
    
    var iExpiryMonths = parseInt(ddlExpiryYear.value, 10) * 12 + parseInt(ddlExpiryMonth.value, 10);
    var iNowMonths = dtNow.getFullYear() * 12 + (parseInt(dtNow.getMonth(), 10) + 1);
    
    if (iExpiryMonths < iNowMonths)
    {
        args.IsValid = false;
    }         
}       
    
function OpenSYOSModalWin(id) 
{
    var redirectURL="";
    if (window.showModalDialog) 
    {
        redirectURL = window.showModalDialog("/purchase/syos.aspx?perf="+id,"SYOS","dialogWidth:1003px;dialogHeight:1020px");
        if (redirectURL!="" && redirectURL!=null)
            window.location.href=redirectURL;  
    }
    else 
    {
        redirectURL = window.open('/purchase/syos.aspx?perf='+id,'SYOS','height=1020,width=1003,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,modal=yes');              
        redirectURL.focus();
        return false;
    }
} 

function OpenSYOSModalWinGetDate()
{
    if (document.getElementById("ctl00_plcRight_ddlDates"))
    {
        if(document.getElementById("ctl00_plcRight_ddlDates").value != "")
        {
            if (document.getElementById("ctl00_plcRight_rbnSOYS").checked)
                OpenSYOSModalWin(document.getElementById("ctl00_plcRight_ddlDates").value);
        }
        else
            document.getElementById("htmlMsg").innerHTML = 'Allocation exhausted. Please select another performance.';
    }
}