// Highlight error fields
function show_errors(){
	if( input_error.length > 1 ){
		for(i=1;i<input_error.length;i++){
			// Highlight error elements
			cC(input_error[i],'errorField');
		}
	}
}

// Clean version of displayElement for use directly
// If im (image) id is supplied then the expand/contract icons will swap
function expand(p,s,im){
	e = gE(p);
	if(!s || s=='') s=(e.style.display=='') ? -1:1;
	dE(e,s);
	if(im){
		if(s==1) sI(im,'i_expand'); else sI(im,'i_contract');
	}
}

// popup windows...
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, menubar, scrollbars, status, resizable,args){
	if(!menubar) menubar='yes';
	if(!scrollbars) scrollbars='no';
	if(!status) status='yes';
	if(!resizable) resizable='yes';
	if(popUpWin) if(!popUpWin.closed) popUpWin.close();
	
	popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status='+status+',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable+',copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	
	if( args ){
		popUpWin.target_args = args;
	}
}


// Grab the data from the hidden frame for the debug
// f = frame grabbing from; o = object name to grab from;
function debugConsole(o){
	e = gE(o);
	debug_code = e.innerHTML;
	debugLaunch();
}

function debugLaunch(){
	cw = "debugWindow";
	debugWindow = open(root_path+'debug.php',cw,'toolbar=no,location=no,status=yes,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=450,height=600,left=10,top=10');
}

function Preload()
{ 
  var args = Preload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

function numberRemaining(f1,f2,n) {
	var m = gE(f1);
	var l = gE(f2);
	var e = gE('numleft');
	
	if (m.value.length > n){
		m.value = m.value.substring(0,(n));
		m.blur();
		m.focus();
		rc = false;
	} else {
		rc = true;
	}
	
	var num = n - m.value.length;
	e.innerHTML = '<strong>'+ num +' / '+ n +'</strong> Characters Left';
	//l.value = n - m.value.length;
	return rc;
}

function numCheckBoxSelected(f1,maxNum,otherSectionCount) {
	var e = gE(f1);
	var counter = 0;	

	el= (typeof(e.length)!='undefined') ? e.length : 0;

	if(el){
		for (i=0;i<el;i++)
		{ 
			if( e[i].checked == true ) 
				counter++;
		}
	}
	if(otherSectionCount) counter = counter + otherSectionCount;
	if( counter > maxNum ) {
		if ( otherSectionCount > 0 ) alert('You have selections in another section (briefings or semiars) that\n have caused your selection to be over the max number of '+maxNum+' allowed.\n Please deselect those first.');
		else alert('You can only have a maximum of '+maxNum+' selected, please deselect one');
		return false; // alert('counter: '+counter);
	}
	else return true;
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function check_format(a, b, c){
	var fLength = b.value;
	if(c != undefined) { var cLength = c.value; }
	
	if (!IsNumeric(b.value)) 
	{ 
		alert('Please enter only numbers in the phone number fields') 
		b.focus(); 
		return false; 
	} 
	if( a == 'pre' ){
		if(fLength.length !=0 && fLength.length < 2){
			b.value = '0'+ b.value;
		}
	}
	
	if( a == 'full' ){
		if((fLength.length !=0 && fLength.length < 8) || (fLength.length ==0 && cLength.length == 2) ){
			alert('You must enter 8 digits for your phone number');
			b.focus(); 
			return false; 
		}
		if( (fLength.length !=0) && (cLength.length == 0) ){
			alert('You must enter your 2 digit area code!');
			c.focus(); 
			return false; 
	
		}
	}
	
	if( a == 'full_mob' ){
		if(fLength.length !=0 && fLength.length < 10){
			alert('You must enter 10 digits for your phone number');
			b.focus(); 
			return false; 
		}
	}
	
	return true;

}