﻿var Ctm_IMGBLK = 'images/cpc_black.gif'
var Ctm_IMGERROR = 'images/stock_not.png'
var Ctm_IMGOK = 'images/emblem-default.png'

function ShowImgs(formobj){
    
    var OKImgArray = new Array();
    var indiceOK=0;
       
    //First Name
    if (formobj.fname.value != '')        
    {
        OKImgArray[indiceOK] = 'IMG-fname';
        indiceOK = indiceOK + 1;
    }

    //Last Name
    if (formobj.lname.value != '')        
    {
        OKImgArray[indiceOK] = 'IMG-lname';
        indiceOK = indiceOK + 1;
    }
                
    //Address Information
    if (formobj.email.value != ''){
    
        OKImgArray[indiceOK] = 'IMG-email';
        indiceOK = indiceOK + 1;
    }
        
    //Country
    if (formobj.country.value != '')
    {
        OKImgArray[indiceOK] = 'IMG-Country';
        indiceOK = indiceOK + 1;
    }                
     
    //States             
    if (formobj.country.value != 'US')
    {
        if (formobj.state.value != ''){
                
            OKImgArray[indiceOK] = 'IMG-state';
            indiceOK = indiceOK + 1;
        }
    }
    else
    {
        if (formobj.States.value != ''){
           
            OKImgArray[indiceOK] = 'IMG-statecr';
            indiceOK = indiceOK + 1;
        }
    }
                 
    if (formobj.city.value != ''){
       
        OKImgArray[indiceOK] = 'IMG-city';
        indiceOK = indiceOK + 1;
    }
                 
    if (formobj.zip.value != ''){
    
        OKImgArray[indiceOK] = 'IMG-zip';
        indiceOK = indiceOK + 1;
    }             
    if (formobj.addr1.value != ''){
       
        OKImgArray[indiceOK] = 'IMG-addr1';
        indiceOK = indiceOK + 1;
    }            
        
    //Birthdate
    if (formobj.birthdatemonth.value != '' && formobj.birthdateday.value != '' && formobj.birthdateyear.value != '')
    {
        OKImgArray[indiceOK] = 'IMG-Date';
        indiceOK = indiceOK + 1;
    }            
    //Phones
    if (formobj.Ctrdayphoneph1.value != '' && formobj.Ctrdayphoneph2.value != '' && formobj.Ctrdayphoneph3.value != '')
    {
        OKImgArray[indiceOK] = 'IMG-Ctrdayphone';
        indiceOK = indiceOK + 1;
    }                        
    if (formobj.Ctrevephoneph1.value != '' && formobj.Ctrevephoneph2.value != '' && formobj.Ctrevephoneph3.value != '')
    {
        OKImgArray[indiceOK] = 'IMG-Ctrevephone';
        indiceOK = indiceOK + 1;
    }
    //Password
    if ((formobj.pw.value != '') && (formobj.confirmpw.value != '') && (formobj.pw.value == formobj.confirmpw.value))
    {
        OKImgArray[indiceOK] = 'IMG-confirmpw';
        indiceOK = indiceOK + 1;
    }           

    for(var i = 0, len = OKImgArray.length; i < len; ++i )
    {
         var obj = document.getElementById(OKImgArray[i])
         obj.src = Ctm_IMGOK //'images/cpc_ok.gif'
    }            
    
    return true
}

/***************************************************************************/
/***************************************************************************/

function checkDate() 
{                                                                    
    var myDayStr = document.form1.birthdateday.options[document.form1.birthdateday.selectedIndex].value;
    if (myDayStr == '')
    {
        myDayStr = -1
    }            
    var myMonthStr = document.form1.birthdatemonth.options[document.form1.birthdatemonth.selectedIndex].value;            
    if (myMonthStr == '')
    {
        myMonthStr = -1
    }
    var myYearStr = document.form1.birthdateyear.value;                        
    var Vimg = document.getElementById('IMG-Date')
    Vimg.src = Ctm_IMGBLK //'images/cpc_black.gif'            
    
    if ( myMonthStr == '-1' || myDayStr == '-1' || myYearStr == '' || myYearStr.length < 4) 
    {
        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'
    }
    else
    {
        var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');             
        var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;                
        var myDate = new Date();
       
        myDate.setFullYear( myYearStr, myMonthStr, myDayStr );

        if ( myDate.getMonth() != myMonthStr ) {              
            Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'
        } else {
            Vimg.src = Ctm_IMGOK //'images/cpc_ok.gif'              
        }
    }
}

/***************************************************************************/
/***************************************************************************/

function showImg(total,img)
{
    var Vimg = document.getElementById(img)
    Vimg.src = Ctm_IMGBLK //'images/cpc_black.gif'    	

    if (total == '')
    {
        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'
    }
    else
    {
        Vimg.src = Ctm_IMGOK //'images/cpc_ok.gif'
    }
}

/***************************************************************************/
/***************************************************************************/

function countrystates(currentcountry){
        
    if (currentcountry == "US"){
        document.getElementById('subUS').style.display='';
        document.getElementById('subNotUs').style.display='none';
        document.form1.state.value = 'US'
    }
    else {                
        document.getElementById('subUS').style.display='none';
        document.getElementById('subNotUs').style.display='';
        document.form1.state.value = ''
    }
}

/***************************************************************************/
/***************************************************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
    var returnval=emailfilter.test(e.value)
    if (returnval==false){
        alert("Please enter a valid email address.")
        e.select()
        return returnval
    }
    else {
        document.form1.submit;
    }
}

/***************************************************************************/
/***************************************************************************/

function CreatePhoneBox()
{
    var formobj = document.form1 
    if (formobj.PHCtrdayphone.value != '')
    {
        formobj.Ctrdayphoneph1.value = formobj.PHCtrdayphone.value.substring(0,3)
        formobj.Ctrdayphoneph2.value = formobj.PHCtrdayphone.value.substring(3,6)
        formobj.Ctrdayphoneph3.value = formobj.PHCtrdayphone.value.substring(6,11)
    }
    if (formobj.PHCtrevephone.value != '')
    {
        formobj.Ctrevephoneph1.value = formobj.PHCtrevephone.value.substring(0,3)
        formobj.Ctrevephoneph2.value = formobj.PHCtrevephone.value.substring(3,6)
        formobj.Ctrevephoneph3.value = formobj.PHCtrevephone.value.substring(6,11)
    }
}

/***************************************************************************/
/***************************************************************************/

function ageprompt(){
    PhoneDay = document.form1.PHCtrdayphone.value
    VEmail = document.form1.email.value
    Vaddr = document.form1.addr1.value + ' ' + document.form1.addr2.value
    Vaddr1= document.form1.addr1.value
    htmlClientName = document.form1.fname.value + ' ' + document.form1.lname.value    
    Vctr = document.form1.country.value
    Vctrname = document.form1.country.options[document.form1.country.selectedIndex].text;
    
    if (Vctr == 'US')
    {
        VCA = document.form1.States.value + ' ' + document.form1.zip.value
    }
    else
    {
        VCA = document.form1.state.value + ' ' + document.form1.zip.value
    }
    
    
    //htmlAddress = Vaddr + "<br>" + Vaddr1 + "<br>" + VCA + "<br>" + Vctr
    htmlAddress = Vaddr + "<br>" + VCA + "<br>" + Vctr + " - " + Vctrname
    
    agewindow=dhtmlmodal.open('agebox', 'div', 'modalalertdiv', '', 'center=true;width=730px,height=485px,left=200px,top=50px,resize=0,scrolling=0')

    document.getElementById('lblphone').innerHTML = PhoneDay
    document.getElementById('lblmail').innerHTML = VEmail
    document.getElementById('lblAddr').innerHTML = htmlAddress
    document.getElementById('Lblcheckname').innerHTML = htmlClientName
}        

/***************************************************************************/
/***************************************************************************/

function CheckCboHd(){

    var formobj = document.form1;
    var err = 0;
    var err1 = 0;
    var err2 = 0;
    var ImgArray = new Array();
    var OKImgArray = new Array();
    var indice=0;
    var indiceOK=0;
    
    //check account disable
    document.form1.hdbtnchk.value = 2
    
    //General Information
    if (formobj.btnchk.value == 'check'){
    
        if (formobj.login.value == ''){
            ImgArray[indice] = 'IMG-login';
            indice = indice + 1;
            err = 1;
        }
        else
        {
            OKImgArray[indiceOK] = 'IMG-login';
            indiceOK = indiceOK + 1;
        }                
    }
    else
    {
        var GElblAcc = document.getElementById('lblAcc')                
        if (GElblAcc.innerHTML == ''){
            ImgArray[indice] = 'IMG-login';
            indice = indice + 1;
            err = 1;
        }                
    }
    if (formobj.fname.value == ''){
        ImgArray[indice] = 'IMG-fname';
        indice = indice + 1;
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-fname';
        indiceOK = indiceOK + 1;
    }
    
    if (formobj.lname.value == ''){
        ImgArray[indice] = 'IMG-lname';
        indice = indice + 1;
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-lname';
        indiceOK = indiceOK + 1;
    }    
                
    //Address Information
    if (formobj.email.value == ''){
       ImgArray[indice] = 'IMG-email';
       indice = indice + 1;
       err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-email';
        indiceOK = indiceOK + 1;
    }
        
    //Country
    if (formobj.country.value == '')
    {
        ImgArray[indice] = 'IMG-Country'
        indice = indice + 1
        //var Vimg = document.getElementById('IMG-Country');
        //Vimg.src = 'images/cpc_error.gif';
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-Country';
        indiceOK = indiceOK + 1;
    }                
     
    //States             
    if (formobj.country.value != 'US')
    {
        if (formobj.state.value == ''){
           ImgArray[indice] = 'IMG-state';
           indice = indice + 1;
           err = 1;
        } 
        else
        {
            OKImgArray[indiceOK] = 'IMG-state';
            indiceOK = indiceOK + 1;
        }
    }
    else
    {
        if (formobj.States.value == ''){
           ImgArray[indice] = 'IMG-statecr';
           indice = indice + 1;
           err = 1;
        }
        else
        {
            OKImgArray[indiceOK] = 'IMG-statecr';
            indiceOK = indiceOK + 1;
        }
    }
                 
    if (formobj.city.value == ''){
       ImgArray[indice] = 'IMG-city';
       indice = indice + 1;
       err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-city';
        indiceOK = indiceOK + 1;
    }
                 
    if (formobj.zip.value == ''){
       ImgArray[indice] = 'IMG-zip';
       indice = indice + 1;
       err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-zip';
        indiceOK = indiceOK + 1;
    }             
    if (formobj.addr1.value == ''){
       ImgArray[indice] = 'IMG-addr1';
       indice = indice + 1;
       err = 1;
    } 
    else
    {
        OKImgArray[indiceOK] = 'IMG-addr1';
        indiceOK = indiceOK + 1;
    }            
        
    //Birthdate
    if (formobj.birthdatemonth.value == '' || formobj.birthdateday.value == '' || formobj.birthdateyear.value == '')
    {
        ImgArray[indice] = 'IMG-Date'
        indice = indice + 1
        //var Vimg = document.getElementById('IMG-Date');
        //Vimg.src = 'images/cpc_error.gif';
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-Date';
        indiceOK = indiceOK + 1;
    }            
    //Phones
    if (formobj.Ctrdayphoneph1.value == '' || formobj.Ctrdayphoneph2.value == '' || formobj.Ctrdayphoneph3.value == '')
    {
        ImgArray[indice] = 'IMG-Ctrdayphone'
        indice = indice + 1                
        //var Vimg = document.getElementById('IMG-Ctrdayphone');
        //Vimg.src = 'images/cpc_error.gif';
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-Ctrdayphone';
        indiceOK = indiceOK + 1;
    }                        
    if (formobj.Ctrevephoneph1.value == '' || formobj.Ctrevephoneph2.value == '' || formobj.Ctrevephoneph3.value == '')
    {
        ImgArray[indice] = 'IMG-Ctrevephone'
        indice = indice + 1                
        //var Vimg = document.getElementById('IMG-Ctrevephone');
        //Vimg.src = 'images/cpc_error.gif';
        err = 1;
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-Ctrevephone';
        indiceOK = indiceOK + 1;
    }
    //Password
    if ((formobj.pw.value == '') || (formobj.confirmpw.value == ''))
    {
        ImgArray[indice] = 'IMG-confirmpw';
        indice = indice + 1;
        err = 1;                
    }
    else
    {
        OKImgArray[indiceOK] = 'IMG-confirmpw';
        indiceOK = indiceOK + 1;
    }           
    if (formobj.pw.value != formobj.confirmpw.value)
    {
        ImgArray[indice] = 'IMG-confirmpw';
        indice = indice + 1;
        err1 = 1;
    }
    if (formobj.pw.value.length < 6)
    {
        ImgArray[indice] = 'IMG-confirmpw';
        indice = indice + 1;
        err2 = 1;    
    }

    if (err == 1){
        //alert(document.form1.PHCtrevephone.value)
        //alert(document.form1.PHCtrdayphone.value)                
        alert('Some fields are required. Please check')
        for(var i = 0, len = OKImgArray.length; i < len; ++i )
        {
            var obj = document.getElementById(OKImgArray[i])
            obj.src = Ctm_IMGOK //'images/cpc_ok.gif'
        }                            
        for(var i = 0, len = ImgArray.length; i < len; ++i )
        {
            var obj = document.getElementById(ImgArray[i])
            obj.src = Ctm_IMGERROR //'images/cpc_error.gif'
        }
        return false
    }
    else
    {
        if (err1 == 1){
            alert('Password and Confirmation Password are diferents. Please check')
            var obj = document.getElementById('IMG-confirmpw')
            obj.src = Ctm_IMGERROR //'images/cpc_error.gif'                    
        }
        else
        {
            if (err2 == 1){
                alert('Password is very short, you must have at least 6 characters')
                var obj = document.getElementById('IMG-confirmpw')
                obj.src = Ctm_IMGERROR //'images/cpc_error.gif'                                
            }
            else
            {
                for(var i = 0, len = OKImgArray.length; i < len; ++i )
                {
                    var obj = document.getElementById(OKImgArray[i])
                    obj.src = Ctm_IMGOK //'images/cpc_ok.gif'
                }            
                ageprompt()
            }
        }
    }
    return true
}

/***************************************************************************/
/***************************************************************************/

function changeName(valorbtn,valorbtnhd)
{
    document.form1.btnchk.value = valorbtn
    document.form1.hdbtnchk.value = valorbtnhd
    if (valorbtn == 'modify'){
        document.form1.btnchk.disabled=false
    }
    else
    {
        if (document.form1.login.value == '')
            document.form1.btnchk.disabled=true
    }
}

/***************************************************************************/
/***************************************************************************/

function formCheck(formobj){
    
    // Enter name of mandatory fields
    var fieldRequired = Array("login", "pw", "confirmpw", "fname", "lname", "email", "PHCtrdayphone", "PHCtrevephone", "birthdatemonth", "birthdateday", "birthdateyear", "addr1", "city", "country");
    // Enter field description to appear in the dialog box
    var fieldDescription = Array("Account Name", "Password", "Confirm Password", "First Name", "Last Name", "E-mail", "Daytime Phone", "Evening Phone", "Birthdate Month", "Birthdate Day", "Birthdate Year", "Address Line 1", "City", "Country");
    // dialog message
    var alertMsg = "Please complete the following fields:\n";
	
    var l_Msg = alertMsg.length;
    var err = 0
	
    for (var i = 0; i < fieldRequired.length; i++){
        var obj = formobj.elements[fieldRequired[i]];
        if (obj){
            
            switch(obj.type){
            case "hidden":
            
                if (obj.value == "" || obj.value == null)
                {                    
                    switch(fieldRequired[i]){
                    case "PHCtrdayphone":
                        var Vimg = document.getElementById('IMG-Ctrdayphone')
                        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'                                                        
                        err = 1
                        break;
                    case "PHCtrevephone":
                        var Vimg = document.getElementById('IMG-Ctrevephone')
                        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'                            
                        err = 1
                        break;
                    }
                }
                break;
                
            case "select-one":
                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                    	                        
                    switch(fieldRequired[i]){
                    case "birthdatemonth":
                        var Vimg = document.getElementById('IMG-Date')
                        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'
                        err = 1
                        break;
                    case "birthdateday":
                        var Vimg = document.getElementById('IMG-Date')
                        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'               
                        err = 1
                        break;
                    case "country":
                        var Vimg = document.getElementById('IMG-Country')
                        Vimg.src = Ctm_IMGERROR //'images/cpc_error.gif'                            
                        err = 1
                        break;                                                                
                    }
                                                
                }
                break;
            case "select-multiple":
                if (obj.selectedIndex == -1){
                    err = 1
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "text":
            case "textarea":
                if (obj.value == "" || obj.value == null){
                    err = 1
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            default:
            }
            if (obj.type == undefined){
                var blnchecked = false;
                for (var j = 0; j < obj.length; j++){
                    if (obj[j].checked){
                        blnchecked = true;
                    }
                }
                if (!blnchecked){
                    err = 1
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
            }
        }
    }

    //if (alertMsg.length == l_Msg){
    if (err == 0){
        return true;
        //return checkmail(document.form1.email);
    }else{
        //alert(alertMsg);
        alert('Some fields are required. Please check');
        return false;
    }
}

/***************************************************************************/
/***************************************************************************/

function Acciones(id,form)
{            
    //Make Deposit and Play on-line
    form.submit();
}

/***************************************************************************/
/***************************************************************************/

function OpenVerifyEmail(){
	w = 400;
	h = 300;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open('Verification_email.aspx?email='+document.form2.emailforverification.value,'EmailVerification','menubar=no,width='+w+',height='+h+',top='+wint+',left='+winl+'toolbar=no,scrollbars=no');
}
function OpenInstructions()
{
	w = 400;
	h = 500;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open('WhitoutConf_Instructions.aspx','Information','menubar=no,width='+w+',height='+h+',top='+wint+',left='+winl+'toolbar=no,scrollbars=no');        
}

function SPANIMG(){
    var img = document.getElementById("spimg");
    img.innerHTML = ('<center><font size="2" color="white">Checking Account. Please Wait... </font><img src="images/working_animated.gif"></center>')
}

function SPANIMGP(){
    var img = document.getElementById("SPpross");
    img.innerHTML = ('<img src="images/working_animated.gif"> Processing. &nbsp&nbsp&nbsp<br>Please Wait...')
}

function HideMenu(valor){
    var mnu = document.getElementById("Tbl_Mnu");    
    if (valor == 1)
    {
        mnu.style.display='';
    }
    else
    {
        mnu.style.display='none';
    }    
}