// JavaScript Document

 	

function isNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }






//Determine the length of a string for min an d max values
function checkStrLength(str, minLength, maxLength)
{		
	//alert("checkStrLength")
	var status = true
	var length = str.length
	
	if(minLength != ''){
		//Check that there are aleast a min amount of characters
		if(length < minLength){
			//There is not enough characters
			status = false
		}//end inner if
	}//end outer if
	
	
	if(maxLength != ''){
		//Check that there are aleast a min amount of characters
		if(length > maxLength){
			//There are too many characters
			status = false
		}//end inner if
	}//end outer if
	

	
	//Send back the status of the function
	alert(status)
	return status

}//end function




//Check to see if a set of radio elements have been checked
function isRadioChecked(elementName, numElements){
		
		//alert('IsRadioChecked');
		
		var radioStatus = false
		
		for(i=0;i<numElements;i++){
				//alert(elementName+"_"+i)
				
				if(document.getElementById(elementName+"_"+i).checked == true){
						radioStatus = true
						i = numElements
				}//end if
				
		}//end loop
		
		
		return radioStatus

}//end function
				
	
	
//BatchId grouping
function batchIds(element, container){

	var mylist = $(container).value;
	
	var myarray = mylist.split(",");
	
	if(element.checked == true){
		myarray.push(element.value);
	}
	else{
		//alert("Remove from the array");
		for(i=0;i<myarray.length;i++){
			if(myarray[i] == element.value){
				myarray.splice(i,1);
			}//end if
		}//end loop
	}//end else
	
	$(container).value = myarray;

}//end function




//Graying out the screen
function grayOut(vis, options, message) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}
	
	
	
	
	
//Email formatted string validation
function isEmail(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }

  return true;

}



//Clear the contents on an element
function clearBox(element){
	element.value = ''
}//end function





function trim(str) {
	var trimmed = str.replace(/^\s+|\s+$/g, '') ;
	return trimmed
}




//Shortcut function to accession HTML DOM properties
function $(name){
	return document.getElementById(name)	
}

//Shortcut to a flash object
function $flash(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
	
	//alert(document[movieName])
}


function varDump(expression){
	
	//Loop through object properties and 
	for(i in expression){
		
		if(typeof(expression[i]) == 'object'){
			varDump(expression[i])
		}
		else
		{
			document.write(i +":->"+ expression[i] + "<BR>")
		}//end if-else
		
	}//end loop
	
	//Create spacer line
	document.write('<BR>')
}//end function




//Return the current time as an object
function getTimeObject(){
	
	var date = new Date()
	var obj = new Object()

	obj['year'] = date.getFullYear()
	obj['month'] =  date.getMonth() + 1
	obj['day'] =  date.getDate()
	obj['hour'] =  date.getHours() 
	obj['minute'] =  date.getMinutes()
	obj['second'] =  date.getSeconds()
	
	if(obj.hour == 0){
		obj['hour'] = '00'
	}

	//Cycle through object and look for single charagter strings
	for(i in obj){
		var term = new String(obj[i])
		if(term.length == 1){
			obj[i] = '0'+term
		}//end if
	}//end loop


	//Return the obj
	return obj

}

function highlight(element, color){	
	element.style.background = color
}

function setBackground(element, color){
	element.style.backgroundColor = color
}


function toggle(id){

	if($(id).style.display == 'none'){
		$(id).style.display = ''
	}
	else
	{
		$(id).style.display = 'none'
	}
		
}



function getUrl(url){
	if(trim(url) != ''){
		window.location.href = url	
	}
}




function stringToXML(xmlString){
try //Internet Explorer
  {
  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(xmlString);
  var xml = xmlDoc
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    var xml = (new DOMParser()).parseFromString(xmlString, "text/xml");
	}
  catch(e) {alert(e.message)}
  }

	//Return the XML object
	return xml
}



function hasNumbers(t)
{
return /\d/.test(t);
}




function toggleGroup(param){
	//Break param into an array
	toggleArray = param.split(',')
	
	return toggleArray
}

function toggleElement(id){
	try{
		for(i=0; i< toggleArray.length; i++){
			if(id == toggleArray[i]){
				$(toggleArray[i]).style.display = ''	
			}
			else
			{
				$(toggleArray[i]).style.display = 'none'	
			}//end if/else
		}//end loop
		
	}
	catch(e){
		alert("Error"+e)
	}

}//end function




function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}


function setCookie(c_name, value, expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}




/* get position 
function getPos(e)
{

try{



	var obj = $(e);

	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	
	var obj = e;
	
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	return {x:curleft, y:curtop};
	
	
	
}
	}
	catch(e){
		alert("Error:"+e)
	}
	
};
*/

