﻿// JScript File
// Created 2007-04-12

var CTL = ""

function CardNum(e,cnumitm,cNxt){
	key = getkey(e);
    if (key==null || key==0 || key==8 || key==9 || key==13 || key==27 || key==20 || key==45 || key==16 || key==17 || key==46 || key==144){return true;}
    else if ( key>=33 && key<=40 ){return true;}
    else{
    	cardn = cnumitm.value;
    	if (cardn == null){return cardn;}
        if (cardn.length==4 && cardn.indexOf("-") != 3){cardn = cardn + "-";cnumitm.value = cardn;}
		if (cardn.length==5){if (cardn.indexOf("-",3) != 4){startstr = cardn.substr(0,4);endstr = cardn.substr(4,1);cardn = startstr + "-" + endstr;}}
        cnumitm.value = cardn;
        cnumitm.focus();
		if (cardn.length==19){cNxt.focus();}
        else{
        	if (cardn.length==4 && cardn.indexOf("-") != 3){cardn = cardn + "-";}
        	if (cardn.length==5){if (cardn.indexOf("-",3) != 4){startstr = cardn.substr(0,4);endstr = cardn.substr(4,1);cardn = startstr + "-" + endstr;}}
			if (cardn.length==9 && cardn.indexOf("-",7) != 8){cardn = cardn + "-";}
			if (cardn.length==10){if (cardn.indexOf("-",7) != 9){startstr = cardn.substr(0,9);endstr = cardn.substr(9,1);cardn = startstr + "-" + endstr;}}
			if (cardn.length==14 && cardn.indexOf("-",12) != 13){cardn = cardn + "-";}
       		if (cardn.length==15){if (cardn.indexOf("-",12) != 14){startstr = cardn.substr(0,14);endstr = cardn.substr(14,1);cardn = startstr + "-" + endstr;}}
	   		cnumitm.value = cardn;
	   		cnumitm.focus();
	   		}
       	}

}

function CheckLen(val,maxlen){ 
if (val==null) return 0
if (val.length>=maxlen) {return 1;}else{return 0;}
}

function getkey(e){
    if (window.event){return window.event.keyCode;}
    else if (e){return e.which;}
    else{return null;}
}
function checkkey(e, goodkeys){
    var key, keychar;
    key = getkey(e);
    if (key == null){return true;}
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    goodkeys = goodkeys.toLowerCase();
    if (goodkeys.indexOf(keychar) != -1){return true;}
    if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
    {return true;}
    alert ("Invalid key pressed - only numbers are allowed");
    return false;
}

function SelectCard(crd){
			if (crd==1) document.getElementById(CTL + 'card_VI').checked=true
			if (crd==2) document.getElementById(CTL + 'card_MC').checked=true
			if (crd==3) document.getElementById(CTL + 'card_BC').checked=true
		}
function open_TC(){TC = window.open('/MyTravelclub/Members/TCMembership.htm','win','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=Yes,resizable=No,width=570,height=350');}




// ****************************************************  MEMBERSHIP PLANS ***************************************************************
function SetPlanCode(PlanCode){
    document.getElementById(CTL + 'HF1').value=PlanCode
}
function SelectPlan(itmIndex,pType,pCode){
    var pInd = 0
    SetPlanType(pType)
    if (pType=='W') {pType='WEB';pInd=0}
    if (pType=='S') {pType='STANDARD';pInd=1}
    if (pType=='P') {pType='PHOTO';pInd=2}
    
    document.getElementById(CTL + 'chkMemType_' + pInd).checked=true
    document.getElementById(CTL + 'cbo' + pType).value=pCode
    SetPlanCode(pCode)
}

function SetPlanType(pType){
    if (pType=='W') pType='WEB'
    if (pType=='S') pType='STANDARD'
    if (pType=='P') pType='PHOTO'
    
    document.getElementById(CTL + 'cboWEB').style.display='none'
    document.getElementById(CTL + 'cboSTANDARD').style.display='none'
    document.getElementById(CTL + 'cboPHOTO').style.display='none'
    
    document.getElementById(CTL + 'cbo' + pType).style.display=''
    SetPlanCode(document.getElementById(CTL + 'cbo' + pType).value)
   
}
