/***************************************************************************
Last Updated: Feb. 25, 2002
***************************************************************************/

/***************************************************************************
                         Javascript Client-side functions
***************************************************************************/
function Trim(theText)
  {
  if (theText.length=="") return "";
  while (theText.charAt(0) == " ") theText = theText.substr(1);
  while (theText.charAt(theText.length - 1) == " ") theText = theText.substr(0, theText.length - 1);
  return theText;
  }
//-->

function Moveup(box) {
for(var i = 0; i < box.options.length; i++) {
if (box.options[i].selected && box.options[i] != "" && box.options[i] != box.options[0]) {
var tmpval = box.options[i].value;
var tmpval2 = box.options[i].text;
box.options[i].value = box.options[i - 1].value;
box.options[i].text = box.options[i - 1].text
box.options[i-1].value = tmpval;
box.options[i-1].text = tmpval2;
      }
   }
}

function Movedown(boxdown) {
for(var i = 0; i < boxdown.options.length; i++) {
if (boxdown.options[i].selected && boxdown.options[i] != "" && boxdown.options[i+1] != boxdown.options[boxdown.options.length]) {
var tmpval = boxdown.options[i].value;
var tmpval2 = boxdown.options[i].text;
boxdown.options[i].value = boxdown.options[i+1].value;
boxdown.options[i].text = boxdown.options[i+1].text
boxdown.options[i+1].value = tmpval;
boxdown.options[i+1].text = tmpval2;
      }
   }
}

function MoveSelItem(fbox, tbox) {

	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;


	for (i = 0; i < tbox.options.length; i++) {   
	arrLookup[tbox.options[i].text] = tbox.options[i].value;
	arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
	arrLookup[fbox.options[i].text] = fbox.options[i].value;
	if (fbox.options[i].selected && fbox.options[i].value != "" && fbox.options[i].text.indexOf('n/a') == -1) {
	arrTbox[tLength] = fbox.options[i].text;
	tLength++;
	}
	else {
	arrFbox[fLength] = fbox.options[i].text;
	fLength++;
	   }
	}
	
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var x;
	for(x = 0; x < arrFbox.length; x++) {
	var no = new Option();
	no.value = arrLookup[arrFbox[x]];
	no.text = arrFbox[x];
	if (no.text.indexOf('n/a') != -1)  no.style.color='#C0C0C0';
	fbox[x] = no;
	}
	for(x = 0; x < arrTbox.length; x++) {
	var no = new Option();
	no.value = arrLookup[arrTbox[x]];
	no.text = arrTbox[x];
	if (no.text.indexOf('n/a') != -1)  no.style.color='#C0C0C0';
	//no.style.color='blue';
	tbox[x] = no;
	   }
	   
}

function selectAll(theForm){
                        
  frmlen = document[theForm].elements.length;
  var i=0;
      for( i=0; i < frmlen; i++)
      {      
                  if (document[theForm].elements[i].name.indexOf('attend') > 0 || document[theForm].elements[i].name.indexOf('active') > 0)
              {         
                      var ctrllen = document[theForm].elements[i].length; 
                      var n = 0;
					  for(n = 0; n < ctrllen; n++){
						 document[theForm].elements[i].options[n].selected='selected';
						 }  
     
              }                                
      }
}


function MoveSelectedTo(boxFrom,boxTo)
{
	
	var oFrom = boxFrom;
	var oTo = boxTo;
	var newElem = document.createElement("OPTION")

   newElem.text = oFrom.options[oFrom.selectedIndex].text;
   newElem.value = oFrom.options[oFrom.selectedIndex].value;
   if (newElem.text.indexOf('n/a') == -1){
	oTo.options.add(newElem);
	oFrom.options[oFrom.selectedIndex] = null;
	}
   else {
     alert("You can not move this item.");
   }

}


function MoveAllSelectedTo_OLD(boxFrom,boxTo)
{
	
	var oFrom = boxFrom;
	var oTo = boxTo;
	var i = 0;
	var listLength = oFrom.length;
	
for(i = 0; i < listLength; i++){
    if (oFrom.options[i].selected){
        var newElem = document.createElement("OPTION");
		newElem.text = oFrom.options[i].text;
		newElem.value = oFrom.options[i].value;
		oTo.options.add(newElem);
		//oFrom.options[i] = null;
		//oFrom.options[oFrom.selectedIndex] = null;
		}
   }
   
var arrList = new Array();
var a = 0;
for(i = 0; i < listLength; i++){
    
    if (oFrom.options[i].selected){
        //alert(oFrom.options[i].value);
		   arrList[a] = oFrom.options[i].value;
		   a++;
		}
    }

        
//var arrlen = arrList.length;
//alert('arrlen==='+arrlen);
//var n = 0;
//for(n = 0; n < arrlen; n++){
    //oFrom.options[oFrom.selectedIndex] = null;
    //alert(n+'==='+arrList[n]);
    //oFrom.options[arrList[n]] = null;
    
    //var c = 0;
    //for(c = 0; c < listLength; c++){
        //if (arrList[n]=oFrom.options[c].value){
           //oFrom.options[c] = null;
           //alert(n+'==='+arrList[n]+'==='+oFrom.options[c].value+'==='+c);
          //}
        //}
   //}
//alert(listLength);

}


function checkLength(theForm,elName,fullName,elLen){
   var tempobj=document[theForm].elements[elName];
   if (tempobj.value.length > elLen) {
       alert("The form field '" + fullName + "'" + " contains " + tempobj.value.length + " characters. It is limited to " + elLen + " characters only!");
       return false;
       }
       return true;
}

function actionConfirm(message){
if (confirm(message)){
   return true;
   }
return false;
}        
          


function checkInfoNU() { 
  if (document.appform.partner_company_name.value == "")
  {
    alert("Please enter your company name.");
    return false;
  }
  else if (document.appform.company_address1.value == "")
  { 
    alert("Please enter your company address."); 
    return false;
  }
  else if (document.appform.company_city.value == "")
  { 
    alert("Please enter the name of the city your company is located."); 
    return false;
  }
   //else if (document.appform.company_state.value == "NS")
  //{
    //alert("Please select the state your company is located.");
    //return false;
  //}
  else if (document.appform.company_zip.value == "")
  {
    alert("Please enter the zip code.");
    return false;    
  }
  else if (document.appform.company_country.value == "NS")
  {
    alert("Please select the country your company is located.");
    return false;
  }
  else if (document.appform.company_phone.value == "")
  {
    alert("Please enter your company phone.");
    return false;
  }
  else if (document.appform.company_email.value == "")
  {
    alert("Please enter your email address.");
    return false;
  }
  else if (document.appform.company_email.value.indexOf('@') == -1 || document.appform.company_email.value.indexOf('.') == -1)
  {
    alert("Your email address is not formatted correctly. Please check it and try again.");
    return false;
  }
  else if (document.appform.company_phone.value != "")
   {
		var checkStr = document.appform.company_phone.value;
		var checkOK = "0123456789().-+";
		for (var i = 0;  i < checkStr.length;  i++)
		  {
			if (checkOK.indexOf(checkStr.charAt(i)) < 0) 
			  {
			  alert("The character  " + checkStr.charAt(i) + "  is not allowed in Phone - field. Please enter valid phone number.");
			   return false;
			  }
		  }
	}
  


  else { return true; }
}