function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function galleryWindow(URL){
		gWin = window.open(URL,'GalleryWin',
		'width=396,height=450,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}
function galleryWindow2(URL){
		gWin2 = window.open(URL,'GalleryWin2',
		'width=516,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}
function termWindow(URL){
		tWin2 = window.open(URL,'tWin2',
		'width=500,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}

function requestWin(URL){
		rWin = window.open(URL,'reqWin',
		'width=550,height=350,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}

function printWin(URL){
		pWin = window.open(URL,'printWin',
		'width=580,height=450,toolbar=1,directories=0,menubar=1,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}
function letternumber(e)
{
var key;
var keychar;
if (window.event)
 key = window.event.keyCode;
else if (e)
 key = e.which;
else
 return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || 
 (key==9) || (key==13) || (key==27) )
 return true;
// alphas and numbers
else if ((("-0123456789").indexOf(keychar) > -1))
 return true;
else
 return false;
}

function formatTel(t) {
if (t.length == 10){
if (t == ''){
	NEWt = ''
	return NEWt
} 
else {
if (t.match(/[(|)|-]/g)) return t
 t = t.substr(0,3)+"-"+t.substr(3,3)+"-"+t.substr(6,4)
  return t
}
}
else {return t}
}
function verifyCheck(){
	var continueSubmit = 1
	for (i=0;i<document.psForm.chk.length;i++) {
        if (document.psForm.chk[i].checked==false) {
           continueSubmit = 0}}
	if(continueSubmit==0){
		alert('Please agree and check all the boxes to proceed or contact us for sales & support.')
		return false;}
}
 function validateFocus (form,field,value,msg){
    alert(msg)
	field.focus()
 }		
 
 function callajax(url, pageElement, callMessage, errorMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseajax(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
  }

function responseajax(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) 
         {
         	output = req.responseText;     
         	document.getElementById(pageElement).innerHTML = output;           
         } 
      else 
         {
         	document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
         }
      }
  }
  
function trim(s)
        {
            // Remove leading spaces and carriage returns
            
            while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
            {
              s = s.substring(1,s.length);
            }

            // Remove trailing spaces and carriage returns

            while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
            {
              s = s.substring(0,s.length-1);
            }
            return s;
        }  
        
function chknumber(ex)
{
	var nav4 = window.Event ? true : false;
	
	if(nav4)
	{
		
		if ( ( ex.which < 48 || ex.which > 57 ) && ex.which != 8 && ex.which != 13  && ex.which != 0 ) 
	    return  false;
	}
	else
	{
		 
		 if(ex.keyCode)
		 {
		 	
			if ( (ex.keyCode < 48 || ex.keyCode > 57) && ex.keyCode!=8 && ex.keyCode!= 13 &&  ex.keyCode!= 0 ) 
		        return  false;
		 }
		 else
		 {
		 	if ( (ex.button < 48 || ex.button > 57) && ex.button!=8 && ex.button != 13 && ex.button!= 0) 
		        return  false;
		 }	        
	}
  
}  

function emailCheck(emailStr)
   {
       var emailPat=/^(.+)@(.+)$/
       var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
       var validChars="\[^\\s" + specialChars + "\]"
       var quotedUser="(\"[^\"]*\")"
       var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
       var atom=validChars + '+'
       var word="(" + atom + "|" + quotedUser + ")"
       var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
       var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
       var matchArray=emailStr.match(emailPat)
       if(emailStr=="")
       { return true}
       if (matchArray==null) {
           alert("Email address seems incorrect (check @ and .'s)")
           return false
       }
       var user=matchArray[1]
       var domain=matchArray[2]
       if (user.match(userPat)==null) {
            alert("The username doesn't seem to be valid.")
           return false
       }
       var IPArray=domain.match(ipDomainPat)
       if (IPArray!=null) {
             for (var i=1;i<=4;i++){
                   if (IPArray[i]>255)     {
                       alert("Destination IP address is invalid!")
                   return false
                               }
                       }
                   return true 
               }

       var domainArray=domain.match(domainPat)
       if (domainArray==null) {
           alert("The domain name doesn't seem to be valid.")
           return false
       }
       var atomPat=new RegExp(atom,"g")
       var domArr=domain.match(atomPat)
       var len=domArr.length
       if (domArr[domArr.length-1].length<2 ||
           domArr[domArr.length-1].length>7) {
          alert("The address must end in a valid domain, or two letter country.")
          return false
       }
       if (len<2) {
          var errStr="This address is missing a hostname!"
          alert(errStr)
          return false
       }
       return true;
   }
   
function mod10( cardNumber )
  { // LUHN Formula for validation of credit card numbers.
    var ar = new Array( cardNumber.length );
    var i = 0,sum = 0;


        for( i = 0; i < cardNumber.length; ++i ) {
            ar[i] = parseInt(cardNumber.charAt(i));
        }
        for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
            ar[i] *= 2;                          // every second digit starting with the right most (check digit)
            if( ar[i] > 9 ) ar[i]-=9;            // will be doubled, and summed with the skipped digits.
        }                                        // if the double digit is > 9, ADD those individual digits together


            for( i = 0; i < ar.length; ++i ) {
                sum += ar[i];                        // if the sum is divisible by 10 mod10 succeeds
            }
            return (((sum%10)==0)?true:false);
    }


 function expired( month, year )
    {
            var now = new Date();                           // this function is designed to be Y2K compliant.
            var expiresIn = new Date(year,month,0,0,0);     // create an expired on date object with valid thru expiration date
            expiresIn.setMonth(expiresIn.getMonth()+1);     // adjust the month, to first day, hour, minute & second of expired month
            if( now.getTime() < expiresIn.getTime() ) return false;
            return true;                                    // then we get the miliseconds, and do a long integer comparison
    }


function validateCard(cardNumber,cardType,cardMonth,cardYear) 
	{

            if( cardNumber.length == 0 ) {                      //most of these checks are self explanitory
                alert("Please enter a valid card number.");
                return false;
            }

            for( var i = 0; i < cardNumber.length; ++i ) {      // make sure the number is all digits.. (by design)
                var c = cardNumber.charAt(i);


                    if( c < '0' || c > '9' ) {
                        alert("Please enter a valid card number. Use only digits. do not use spaces or hyphens.");
                        return false;
                    }
                }
                var length = cardNumber.length;         //perform card specific length and prefix tests




                    switch( cardType ) 
                    {
                        case 'Mastercard':


                                if( length != 16 ) {
                                    alert("Please enter a valid MasterCard number.");
                                    return;
                                }
                                var prefix = parseInt( cardNumber.substring(0,2));


                                    if( prefix < 51 || prefix > 55) {
                                        alert("Please enter a valid MasterCard Card number.");
                                        return;
                                    }
                                    break;
                        case 'Visa':


                                if( length != 16 && length != 13 ) {
                                    alert("Please enter a valid Visa Card number.");
                                    return;
                                }
                                var prefix = parseInt( cardNumber.substring(0,1));


                                    if( prefix != 4 ) {
                                        alert("Please enter a valid Visa Card number.");
                                        return;
                                    }
                                    break;
                        case 'American Express':            
		                        if( length != 15 ) 
	                              {
	                    				alert("Please enter a valid American Express Card number.");
	                    				return;
	                    			}
                    			   var prefix = parseInt( cardNumber.substring(0,2));

                        			if( prefix != 34 && prefix != 37 ) {
                        				alert("Please enter a valid American Express Card number.");
                        				return;
                        			}
		                break;   
		                case 'Discover':         
		                			if( length != 16 ) 
		                		       {
                            				alert("Please enter a valid Discover Card number.");
                            				return;
                            			}
                            			var prefix = parseInt( cardNumber.substring(0,4));


                                			if( prefix != 6011 ) {
                                				alert("Please enter a valid Discover Card number.");
                                				return;
                                			}
                           break;         
                    }
                    if( !mod10( cardNumber ) ) {        // run the check digit algorithm
                        alert("Sorry! this is not a valid credit card number.");
                        return false;
                    }
                    if( expired( cardMonth, cardYear ) ) {                          // check if entered date is already expired.
                        alert("Sorry! The expiration date you have entered would make this card invalid.");
                        return false;
                    }

                    return true; // at this point card has not been proven to be invalid
}

function popup(href, w, h, r, s ) {
    win=window.open(href,'send','width='+w+', height='+h+', scrollbars='+s+', location=0, menubar=0, status=0, toolbar=0, addressbar=0, resizable='+r);
    win.moveTo(screen.width/2-(w/2),screen.height/2-(h/2));
    win.focus();
}
   
