// Orderform_mil_only.js
// Javascript to support YAKbite Military Order processing:
//	- confirms email address


// get the first parameter (between the "=" and "&")
function delineate(str)
{
  theleft = str.indexOf("=") + 1;
  theright = str.lastIndexOf("&");
  // if there are no delimiters - there are no parameters.
  if (theright < theleft)
	return(""); // return a null string for no params condition
  return(str.substring(theleft, theright));
}

// get the second parameter (between the "+" and the end of the string)
function delineate2(str)
{
  point = str.lastIndexOf("=");
  return(str.substring(point+1,str.length));
}

function SetOrgPromo() {
// get local variables set for picking off parameters in the URL.
var locate = window.location;
document.Military.SCRATCH.value = locate;
var rawParms = document.Military.SCRATCH.value;

// get the first parm - the ORG code
document.Military.ORG.value = delineate(rawParms);

// if there's not an ORG code skip it. 
if (document.Military.ORG.value == "")
	return;

// get the second parm - the PROMO code
document.Military.PROMO.value = delineate2(rawParms);

// Now tag the order form 
document.Military.DESCRIPTION.value += "\nORG=";
document.Military.DESCRIPTION.value += document.Military.ORG.value;
document.Military.DESCRIPTION.value += ";PROMO=";
document.Military.DESCRIPTION.value += document.Military.PROMO.value;
document.Military.DESCRIPTION.value += ";";
}

function VerifyEmail(){

if (document.Military.EMAIL.value != document.Military.EMAIL1.value)
	{
	alert("Your email addresses do not match. Please enter registration email address.");
	document.forms[0].EMAIL.focus();
	return;
	}
}

function Check_US_service(){
var i = document.Military.SERVICEBRANCH.selectedIndex; 
if (eval( i < 1))
	{
	// focus on Branch of Service
	alert("Please select a Branch of Service.");
	document.forms[0].SERVICEBRANCH.focus();
	return;
	}
// Now, make sure SERVICEBRANCH has a value!
var temp_state = document.Military.SERVICEBRANCH.options[i].text;
//alert("SERVICEBRANCH = {" + temp_state + "};index= "+ i );
document.Military.SERVICEBRANCH.value = temp_state;
}
function setACTIVE(memberStatus)
{
	document.Military.ACTIVE.value = memberStatus; 
}
function setIM(tIM)
{
	document.Military.IM.value = document.Military.IM.value + ";" + tIM; 
}
function noIM(tIM)
{
if (eval(document.Military.NOIM.checked) && (document.Military.IM.value != ""))
	{
	alert("You've selected a valid IM and None.\n Please re-enter your selection.");
	document.Military.IM.value = "";
	document.Military.AIM.checked = false;
	document.Military.MSN.checked = false;
	document.Military.ICQ.checked = false;
	document.Military.YAHOO.checked = false;
	document.Military.JABBER.checked = false;
	document.Military.GAIM.checked = false;
	document.Military.NOIM.checked = false;
	document.forms[0].AIM.focus(); 
	return;
	}
document.Military.IM.value = "none"; 
}
function VerifyForm(x)
{

// Add the ORG & PROMO TAGS to the order
SetOrgPromo(); // get the data


// check for netYAK marketing info permission
document.Military.NETYAKMKTG.value="none";
if (eval(document.Military.NETYAKMKTG.checked))
{
	document.Military.NETYAKMKTG.value="netyakmktg";
}
//displayVariables();
}

function displayVariables()
{
alert("NAME = " + document.Military.NAME.value +
	"\nSERVICEBRANCH = " + document.Military.SERVICEBRANCH.value +
	"\nACTIVE = " + document.Military.ACTIVE.value +
	"\nIM = " + document.Military.IM.value +
	"\nEMAIL = " + document.Military.EMAIL.value +
	"\nEMAIL1 = " + document.Military.EMAIL1.value +
	"\nORG = " + document.Military.ORG.value +
	"\nPROMO = " + document.Military.PROMO.value 
	);

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function YY_checkform() { //v2.0
  var args = YY_checkform.arguments; var myDot=true; myV=''; var myErr='';var addErr=false;
  if (document.all){eval("args[0]=args[0].replace(/.layers/gi, '.all');");}
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){
      var myReq=true; args[i+1]=args[i+1].substring(1);
    }else{myReq=false}
    var myObj = eval(args[0]+'.'+args[i])
    if (myObj.type=='text'){
      if (myReq&&myObj.value.length==0){addErr=true}
      myV=myObj.value
      if ((myV.length>0)&&(args[i+2]==1)){ //vonbis
      if (isNaN(parseInt(myV))||eval(myV)<eval(args[i+1].substring(0,args[i+1].indexOf('_')/1))||eval(myV) > eval(args[i+1].substring(args[i+1].indexOf('_')+1)/1)
||myV.length < args[i+1].substring(0,args[i+1].indexOf('_')/1).length ){addErr=true}
      }
      if ((myV.length>0)&&(args[i+2]==2)){ //e-mail
        if (myV.lastIndexOf('.')<myV.lastIndexOf('@')||myV.lastIndexOf('.')==-1||myV.lastIndexOf('@')==-1){addErr=true}
      }
      if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myD=''; myM=''; myY=''; myYY=0; myDot=true;
        for(var j=0;j<args[i+1].length;j++){
          if(args[i+1].charAt(j)=='D')myD=myD.concat(myObj.value.charAt(j));
          if(args[i+1].charAt(j)=='M')myM=myM.concat(myObj.value.charAt(j));
          if(args[i+1].charAt(j)=='Y'){myY=myY.concat(myObj.value.charAt(j)); myYY++}
          if(args[i+1].charAt(j)=='-'&&myObj.value.charAt(j)!='-')myDot=false;
          if(args[i+1].charAt(j)=='.'&&myObj.value.charAt(j)!='.')myDot=false;
          if(args[i+1].charAt(j)=='/'&&myObj.value.charAt(j)!='/')myDot=false;
        }
        if(myD/1<1||myD/1>31||myM/1<1||myM/1>12||myY.length!=myYY)myDot=false;
        if(!myDot){addErr=true}
       }
      if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myH=''; myM=''; myDot=true;
        for(var j=0;j<args[i+1].length;j++){
          if ((args[i+1])=="HH:MM"){
            if(args[i+1].charAt(j)=='H')myH=myH.concat(myObj.value.charAt(j));
            if(args[i+1].charAt(j)=='M')myM=myM.concat(myObj.value.charAt(j));
          }else{
            if(args[i+1].charAt(j)=='h')myH=myH.concat(myObj.value.charAt(j));
            if(args[i+1].charAt(j)=='m')myM=myM.concat(myObj.value.charAt(j));
          }
          if(args[i+1].charAt(j)==':'&&myObj.value.charAt(j)!=':')myDot=false;
        }
        if ((args[i+1])=="hh:mm"){
          if(myH/1<0||myH/1>12||myM/1<0||myM/1>59)myDot=false;
        }else{
          if(myH/1<0||myH/1>23||myM/1<0||myM/1>59)myDot=false;
        }
        if(!myDot){addErr=true}
      }
      if ((myV.length>0)&&(args[i+2]==5)){ // check this 2
        if (!eval(args[0]+'.'+args[i+1]+'.checked')){addErr=true}
      }
    }
    if (myObj.type=='radio'){
      if (args[i+2]==1&&myObj.checked&&eval(args[0]+'.'+args[i+1]+'.value.length')/1==0){addErr=true}
      if (args[i+2]==2){
        myDot=false;
        myV=eval(args[0]+'.'+args[i].substring(0,args[i].lastIndexOf('[')))
        for(var j=0;j<myV.length;j++){myDot=myDot||myV[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    }
    if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked&&eval(args[0]+'.'+args[i+1]+'.value.length')/1==0){addErr=true}
    }
    if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&eval(args[0]+'.'+args[i]+'.selectedIndex')/1==0){addErr=true}
    }
    if (myObj.type=='textarea'){
      myV = eval(args[0]+'.'+args[i]+'.value');
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='')
}

