
/* FROM HERE DOWN GOES INTO A .js INCLUDE  */

// Added DOM detection for Opera which doesn't handle the length property of
// an array of form elements.
isDOM = document.getElementById ? 1:0; 
    
function stripSpaces(x) {
    while (x.substring(0,1) == ' ') x = x.substring(1);
    return x;
}

function empty(x) { if (x.length > 0) return false; else return true; }
    
function chkForChecked (f,fld,msg) {
    
    var frm = f ;
    var e ;
    var j = 0 ; // This is so that we know which RADIO/CHECKBOX element to return to.
    
    if(isDOM) {
    // Added the DOM part for Opera which seems to choke on the length
    // property of an array of elements.    
        e = document.getElementsByTagName('INPUT'); // returns a Node List
        
        for (var i=0; i<=e.length-1; ++i){
        
            if(e[i].name == fld) {
                if(j==0)j=i;
                if ( e[i].checked ) return true;  // one is checked after all!
            }
        }
        
    }else{
    
        e = f.elements[fld] ; // returns an array of elements
        
        for( var i=0; i < e.length; ++i ) { 
	    	if ( e[i].checked ) 
	    	{ 
	    	    return true;  // one is checked after all! 
	    	    break; 
	    	} 
	    }
    }
    
    alert( msg );
    e[j].focus() ;
    return false; 
}

function chkForNonblank (f,fld,msg) {

    var frm = f ;
    var e = f.elements[fld]
    
    if ( ! empty(stripSpaces(e.value))  ) return true; 
    alert( msg );
    e.focus() ;
    return false;
}

function chkForCC (f,fld,msg) {

     var frm = f ;
     var e = f.elements[fld]
     var s
     for (var b = 0; b < e.length; b++)
      if (e[b].checked)
        s = e[b].value;
 var r = f.elements['cardtype_ni'].selectedIndex
if(s == 1 && r !==0) return true;
if(s > 1 && r == 0) return true;
if(s > 1 && r > 0) return true;
    alert( msg );
    return false;
}



function chkForNumber (f,fld,msg) {

     var frm = f ;
     var e = f.elements[fld]
     var s
     for (var b = 0; b < e.length; b++)
      if (e[b].checked)
        s = e[b].value;
 var r = f.elements['x_Card_Num2_ni'].value
 
if(s == 1 && ! r == '') return true;
if(s > 1) return true;
    alert( msg );
    return false;
}


function chkForIsSelected (f,fld,msg) {

    var frm = f ;
    var e = f.elements[fld]
    
    if ( ! e.selectedIndex == 0 ) return true; 
    alert( msg );
    e.focus() ;
    return false;
}

function chkIfAnyChecked(f,fld,msg){
    var frm= f;
    var e=f.elements[fld]
    var choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < f.e.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (f.e[counter].checked)
choice = true; 
}

if (!choice)
{
// If there were no selections made display an alert box 
    alert( msg );
    e.focus();
    return (false);
}
return (true);
}


function chkForIsChecked (f,fld,msg) {

    var frm = f ;
    var e = f.elements[fld]
    
    if ( ! e.checked == false ) return true; 
    alert( msg );
    e.focus() ;
    return false;
}

function chkNumeric (f,fld,msg) {

    var frm = f ;
    var e = f.elements[fld]
    
    if ( !isNaN(parseInt(e.value)) ) return true; 
    alert( msg );
    e.focus() ;
    return false;
}

function chkforState(f,fld,msg) {
     var frm = f ;
    var e = f.elements[fld]
    var r = f.country.elements[country].selectedIndex
    if ((r == 'USA' || r == 'Canada' || r == 'Australia') && e.selectedIndex > 0 ) return true; 
    alert( msg );
    e.focus() ;
    return false;
}

function validate(f)	
{ 
    
    for( var i=0; i < fieldsToCheck.length; ++i ) 
    { 
	    if (! fieldsToCheck[i][1](f,fieldsToCheck[i][0],fieldsToCheck[i][2]) ) {
	        return false ;
	    }
    }
    
 
}



/* END .js INCLUDE  */