﻿

function enableTextbox(chkid)
{
var newid=chkid.replace("_chkSel","_txtQuantity");
var hdnischeck=chkid.replace("_chkSel","_hdnIsCheck");

if (document.getElementById(chkid).checked==true)
{
document.getElementById(newid).disabled=false;
document.getElementById(newid).value="1";
}
else
{
document.getElementById(newid).disabled=true;
document.getElementById(newid).value="0";
}
}
function ChkValidEmail(object)
{
    var myRegxp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/

    return myRegxp.test(object);
}

function checkCount(dgGrid)
{
var count=0;
var intIndex = 2;
var intLoop;
var intCount = 0;
var rowCount=document.getElementById("ctl00_ContentPlaceHolder1_hdnRowCount").value;
for (intLoop = intIndex;intLoop < rowCount+intIndex; intLoop++)
    {
        if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_chkSel")!=null)
        {
            if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_chkSel").checked)
            {
                intCount++;		
            }
        }			   				
    }  
    if (intCount!=0)
    {
        document.getElementById("ctl00_ContentPlaceHolder1_lblErrorMsg").innerHTML="";
        return true;
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_lblErrorMsg").innerHTML="You have to choose at least 1 option.";
        location.href="#ctl00_ContentPlaceHolder1_lblErrorMsg";
        return false;
    }
}

function validatePlayerRegistrationForm()
{
try
{
var str="";
var count=0;
var intIndex = 2;
var intLoop;
var intCount = 0;
var dgGrid="dgTournamentOption";
var rowCount=document.getElementById("ctl00_ContentPlaceHolder1_hdnRowCount").value;

document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').className = "noerrorTextBox";
document.getElementById('ctl00_ContentPlaceHolder1_txtLastName').className = "noerrorTextBox";
document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "noerrorTextBox";

if (rowCount>0)
{
    for (intLoop = intIndex;intLoop < rowCount+intIndex; intLoop++)
    {
        if (document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub"))
        {
            document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").className = "noerrorTextBox";
            document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtLastNamesub").className = "noerrorTextBox";
            document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "noerrorTextBox";
        }
    }
}
str="";
count=0;
intIndex = 2;
intLoop;
intCount = 0;


    if (document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').value.replace(/^\s+|\s+$/,'')=="")
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').className = "errorTextBox";
        count++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_txtLastName').value.replace(/^\s+|\s+$/,'')=="")
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtLastName').className = "errorTextBox";
        count++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').value.replace(/^\s+|\s+$/,'')=="")
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "errorTextBox";
        count++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').value.replace(/^\s+|\s+$/,'')!= "")
    {
      
        if(!ChkValidEmail(document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").value))
        {                 
            document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "errorTextBox";
            count++;
        }  
    }   
    if (rowCount>0)
    {
        for (intLoop = intIndex;intLoop < rowCount+intIndex; intLoop++)
        {
            if (document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub"))
            {
                if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").value.replace(/^\s+|\s+$/,'')=="")
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").className = "errorTextBox";
                    count++;
                }
                if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtLastNamesub").value.replace(/^\s+|\s+$/,'')=="")
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtLastNamesub").className = "errorTextBox";
                    count++;
                }
                if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value.replace(/^\s+|\s+$/,'')=="")
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "errorTextBox";
                    count++;
                }
                if (document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value.replace(/^\s+|\s+$/,'')!= "")
                {
                    if(!ChkValidEmail(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value))
                    {                 
                        document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "errorTextBox";
                        count++;
                    }  
                }   
             }  
        }
    }
    if (count==0)
    {
        document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="";
        ShowConfirmation();
        return false;
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="Red border indicates mandatory field(s) and also check email format.";
        location.href="#ctl00_ContentPlaceHolder1_lblErr";
        return false;
    }
    return false;
}
catch(ex){
document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="error while saving.";
location.href="#ctl00_ContentPlaceHolder1_lblErr";
return false;}  
}



function validatesponsorRegistrationForm()
{
try
{
    var str="";
    var count=0;
    var intIndex = 2;
    var intLoop;
    var intCount = 0;
    var dgGrid="dgTournamentOption";
    var rowCount=document.getElementById("ctl00_ContentPlaceHolder1_hdnRowCount").value;

    document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').className = "noerrorTextBox";
    document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "noerrorTextBox";
    document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').className = "noerrorTextBox";
    document.getElementById('ctl00_ContentPlaceHolder1_txtCompany').className = "noerrorTextBox";
    if (rowCount>0)
    {
        for (intLoop = intIndex;intLoop < FormatNumber(rowCount+intIndex) && intLoop != FormatNumber(rowCount+intIndex) ; intLoop++)
        {
            if (document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub"))
            {
                document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").className = "noerrorTextBox";
                document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "noerrorTextBox";
                document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtPhonesub").className = "noerrorTextBox";
                document.getElementById("ctl00_ContentPlaceHolder1_" + "dgTournamentOption" + "_ctl" +  FormatNumber(intLoop) + "_txtCompanysub").className = "noerrorTextBox";
            }
        }
    }
    str="";
    count=0;
    intIndex = 2;
    intLoop;
    intCount = 0;
    rowCount=document.getElementById("ctl00_ContentPlaceHolder1_hdnRowCount").value;


        if (document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').value.replace(/^\s+|\s+$/,'')=="")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').className = "errorTextBox";
            count++;
        }
        if (document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').value.replace(/^\s+|\s+$/,'')=="")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "errorTextBox";
            count++;
        }
        if (document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').value.replace(/^\s+|\s+$/,'')!= "")
        {
            if(!ChkValidEmail(document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").value))
            {                 
                document.getElementById('ctl00_ContentPlaceHolder1_txtEmail').className = "errorTextBox";
                count++;
            }  
        }
        if (document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').value.replace(/^\s+|\s+$/,'')=="")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_txtPhone').className = "errorTextBox";
            count++;
        }
        if (document.getElementById('ctl00_ContentPlaceHolder1_txtCompany').value.replace(/^\s+|\s+$/,'')=="")
        {
            document.getElementById('ctl00_ContentPlaceHolder1_txtCompany').className = "errorTextBox";
            count++;
        }
        if (rowCount>0)
        {
            for (intLoop = intIndex;intLoop < rowCount+intIndex ; intLoop++)
            {
                if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub"))
                {
                    if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").value.replace(/^\s+|\s+$/,'')=="")
                    {
                        document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtFirstNamesub").className = "errorTextBox";
                        count++;
                    }
                    if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value.replace(/^\s+|\s+$/,'')=="")
                    {
                        document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "errorTextBox";
                        count++;
                    }
                    if (document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value.replace(/^\s+|\s+$/,'')!= "")
                    {
                        if(!ChkValidEmail(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").value))
                        {                 
                            document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtEmailsub").className = "errorTextBox";
                            count++;
                        }  
                    }
                    if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtPhonesub").value.replace(/^\s+|\s+$/,'')=="")
                    {
                        document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtPhonesub").className = "errorTextBox";
                        count++;
                    }
                    if(document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtCompanysub").value.replace(/^\s+|\s+$/,'')=="")
                    {
                        document.getElementById("ctl00_ContentPlaceHolder1_" + dgGrid + "_ctl" +  FormatNumber(intLoop) + "_txtCompanysub").className = "errorTextBox";
                        count++;
                    }
                }    
            }
        }
        if (count==0)
        {
            document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="";
            ShowConfirmation();
            return false;
        }
        else
        {
            document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="Red border indicates mandatory field(s) and also check email format.";
            location.href="#ctl00_ContentPlaceHolder1_lblErr";
            return false;
        }
        return false;
}
catch(ex){alert(ex);
document.getElementById("ctl00_ContentPlaceHolder1_lblErr").innerHTML="error while saving.";
location.href="#ctl00_ContentPlaceHolder1_lblErr";
return false;}    
}

function FormatNumber(intI)
{
    var str = intI + "";
    if(str.length == 1)
        return "0" + str;
    else
        return str;
}

function AllowNumeric2(event)
 {
  
    var keyval=window.event?window.event.keyCode:event.which;

    if ( (!( (((keyval >= 48) && (keyval <= 57))||(keyval ==46)) ))) 
       {
            if(!window.XMLHttpRequest)
            {                                        
                window.event.keyCode = null;                
            }
            else if(navigator.userAgent.toLowerCase().indexOf("msie") > -1)
            {
                window.event.keyCode = null;
            }
            else
            {
                if (!((keyval == 0) || (keyval <= 8))) 
                {
                        event.preventDefault();
                }
            }                                        
      }                           
}   


function checkpaymentType(chkvalue)
{
    if(chkvalue=="credit")
    {
        document.getElementById("ctl00_ContentPlaceHolder1_chkCredit").checked=true;
        document.getElementById("ctl00_ContentPlaceHolder1_chkCheck").checked=false;
        document.getElementById("ctl00_ContentPlaceHolder1_divcredit").style.display="";
        document.getElementById("ctl00_ContentPlaceHolder1_divcheck").style.display="none";
    }
    else if(chkvalue=="check")
    {
        document.getElementById("ctl00_ContentPlaceHolder1_chkCredit").checked=false;
        document.getElementById("ctl00_ContentPlaceHolder1_chkCheck").checked=true;
        document.getElementById("ctl00_ContentPlaceHolder1_divcredit").style.display="none";
        document.getElementById("ctl00_ContentPlaceHolder1_divcheck").style.display="";
    }

return false;
}

function ShowConfirmation()
{    
    var pnlConfirmation = document.getElementById('searcharea');   
             
    //pnlConfirmation.style.display = "";       
    var width =  530;//700;
    var height =  140;//550;
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    {
        height = 180;
    }
    pnlConfirmation.style.top = ((screen.availHeight - height)/2 + getScrollTop() - 170) + "px";
    pnlConfirmation.style.left = ((screen.availWidth - width)/2 + document.documentElement.scrollLeft) + "px";
    ShowBlocker();
    PopEx(pnlConfirmation, parseInt("0" + pnlConfirmation.style.left, 10) + "A", parseInt("0" + pnlConfirmation.style.top, 10) + "A", width, height, 50, "");
    return false;
}

function HideConfirmation()
{
    var pnlConfirmation = document.getElementById('searcharea');
    HideBlocker();                
    Revert(pnlConfirmation, 50, "");
    setTimeout("document.getElementById('searcharea').style.display='none'", 300)
    //resetMakeAnOfferForm();
    return false;
}
