/***************************************************************************
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';
//return;
	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 selectAll2(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)
		  //added to check master list on the left
		  if (document[theForm].elements[i].name.indexOf('attend') > 0 || document[theForm].elements[i].name.indexOf('active') > 0 || document[theForm].elements[i].name.indexOf('master') > 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(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);
		}
   }

}


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.company_name.value == "")
  {
    alert("Please enter your Company Name.");
    document.appform.company_name.focus();
    return false;
  }
  else if (document.appform.company_contact.value == "")
  { 
    alert("Please enter your Company Contact."); 
    document.appform.company_contact.focus();
    return false;
  }
  else if (document.appform.company_address1.value == "")
  { 
    alert("Please enter your Company Address."); 
    document.appform.company_address1.focus();
    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_region[0].checked){

 	if (document.appform.company_country.value == "NS")
  	{
    		alert("Please select the country your company is located.");
		document.appform.company_country.focus();
    		return false;
  	}

	if (document.appform.company_city.value == "" || document.appform.company_city.value == "Enter City")
 	{ 
  		alert("Please enter the name of the city your company is located.");
		document.appform.company_city.focus(); 
   		return false;
  	}
  }
  else if (document.appform.company_country.value == "NS")
  {
	alert("Please select the country your company is located.");
	document.appform.company_country.focus();
    	return false;
  }
  else if (document.appform.company_phone1.value == "")
  {
    alert("Please enter your Company Phone.");
    document.appform.company_phone1.focus();
    return false;
  }
  else if (document.appform.company_email.value == "")
  {
    alert("Please enter your Email Address.");
    document.appform.company_email.focus();
    return false;
  }
  else if (document.appform.company_description.value == "")
  {
    alert("Please enter your Company Profile.");
    document.appform.company_description.focus();
    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.");
    document.appform.company_email.focus();
    return false;
  }
  else if (document.appform.company_phone1.value != "")
   {
		var checkStr = document.appform.company_phone1.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.");
			document.appform.company_phone1.focus();	
			   return false;
			  }
		  }
	}
  


  else {return true;}
}

function deselectAll(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='';
						 }  
     
              }                                
      }
}

// search Drop-Down box with Text input by Drop-Down
// text
function HandleItByText(txt, option){

	var i;
	var a= "";
	a = txt.value;
	a = a.toUpperCase();
	if (a.length == 0){
		option.selectedIndex = -1;
		return;
	}
	var b = "";
	for (i=0; i<option.length; i++){
		b= option[i].text;
		b= b.toUpperCase();
		if (b.substr(0, a.length) == a) {
			option.selectedIndex = i;
			return;
		}
	}
}

// search Drop-Down box with Value input by Drop-Down
// text
function HandleItByValue(txt, option){

	var i;
	var a= "";
	a = txt.value;
	a = a.toUpperCase();
	if (a.length == 0){
		option.selectedIndex = -1;
		return;
	}
	var b = "";
	for (i=0; i<option.length; i++){
		b= option[i].value;
		b= b.toUpperCase();
		if (b.substr(0, a.length) == a) {
			option.selectedIndex = i;
			return;
		}
	}
}



function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

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;
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)

	//also strip Newline character
	//var strMultipleLineText=obj.value;
  	//var strSingleLineText = strMultipleLineText.replace(
	// Replace out the new line character.
	//new RegExp( "\\n", "g" ), 
	 
	// Put in ... so we can see a visual representation of where
	// the new line characters were replaced out.
	//"" 
	//);

	//obj.value=strSingleLineText;
}

function stripNewline(){
  //var strMultipleLineText=document.appform.company_description.value;
  //var strSingleLineText = strMultipleLineText.replace(
	// Replace out the new line character.
	///new RegExp( "\\n", "g" ), 
	 
	// Put in ... so we can see a visual representation of where
	// the new line characters were replaced out.
	//" " 
	///);
 
	// Alert the new single-line text value.

var strSingleLineText='';
t =  document.appform.company_description.value;
lines = t.split('\n'); 
var i=0;
for( i=0; i < lines.length; i++)
{
	//alert(lines[i]);
	strSingleLineText=strSingleLineText+lines[i];
}
//alert(strSingleLineText);
	document.appform.company_description.value='';
	document.appform.company_description.value=strSingleLineText;
	//alert(document.appform.company_description.value);

}