function popWin(theUrl, theTitle, theFeatures)
	{
	window.open(theUrl, theTitle, theFeatures);
	}
	
function disableButton(theButton, buttonValue)
	{
	theButton.value = buttonValue;
	theButton.disabled = true;
	}

function selectLocation(whichLocation)
	{
	if(whichLocation != '')
		{
		location.href = whichLocation;
		}
	}
	
function changeFieldVal(theField, theValue)
	{
	theField.value = theValue;
	}
	
function retNot()
	{
	return;
	}
	
function confirmDelete(message)
	{
	var confirmMessage = confirm(message);
	if(!confirmMessage)
		{
		return false;
		}
	return true;
	}
	
function checkElementDisable(checkElement, displayElement)
	{
	if(checkElement.checked == true)
		{
		document.getElementById(displayElement).disabled = false;
		}
	else
		{
		document.getElementById(displayElement).disabled = true;
		}
	}
	
function valueElementDisplay(inVal, showVal, showElementList, hideVal, hideElementList)
	{
	var showElementArray = showElementList.split('|');
	var hideElementArray = hideElementList.split('|');
	
	if(inVal == showVal)
		{
		for(i=0; i<showElementArray.length; i++)
			{
			if(document.getElementById(showElementArray[i]))
				{
				document.getElementById(showElementArray[i]).style.display = 'inline';
				}
			}
		}
	else if(inVal != showVal)
		{
		for(i=0; i<hideElementArray.length; i++)
			{
			if(document.getElementById(hideElementArray[i]))
				{
				document.getElementById(hideElementArray[i]).style.display = 'none';
				}
			}
		}
	}
	
function checkElementDisplay(checkElement, displayElementList, displayStyle, hideStyle)
	{
	var displayElementArray = displayElementList.split('|');
	var checkStatus = false;
	var howDisplay;
	
	if(checkElement.checked == true)
		{
		checkStatus = true;
		howDisplay = displayStyle;
		}
	else {howDisplay = hideStyle};
	
	for(i=0; i<displayElementArray.length; i++)
		{document.getElementById(displayElementArray[i]).style.display = howDisplay;}
	}
	
function checkFieldRequire(checkElementVal, requireVal, requireFieldVal)
	{
	//alert(checkElementVal);
	//alert(requireVal);
	//alert(requireFieldVal);
	if(checkElementVal == requireVal && requireFieldVal == '')
		{
		return false;
		}
	return true;
	}
	
function swapElementDisplay(displayElement, hideElement)
	{
	document.getElementById(displayElement).style.display = 'block';
	document.getElementById(hideElement).style.display = 'none';
	}
	
function swapElementDisable(ableList, disableList)
	{
	var ableArray = ableList.split('|');
	var disableArray = disableList.split('|');
	
	for(i=0; i<ableArray.length; i++)
		{
		document.getElementById(ableArray[i]).disabled = false;
		}
		
	for(i=0; i<disableArray.length; i++)
		{
		document.getElementById(disableArray[i]).disabled = true;
		}
	}
	
function checkLength(inString, maxLength)
	{
	if(inString.length > maxLength)
		{
		return false;
		}
	return true;
	}
	
	
	
function findObj(n, d) {
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 
  return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
    if ((x=findObj(a[i]))!=null){
      document.MM_sr[j++]=x; 
      if(!x.oSrc) x.oSrc=x.src; 
      x.src=a[i+2];
    }
}

function swapImgRestore() {
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function isDate(inDate)
	{
	var day, month, year, parsedDate;
	
	// EMPTY CHECK
	if(inDate.length < 1) return false;

	
	// PARSE DATE
	if(inDate.indexOf('/') >= 0) parsedDate = inDate.split('/');
	else if(inDate.indexOf('-') >= 0) parsedDate = inDate.split('-');
	else return false;

	
	// CHECK FOR ALL DATE PARTS
	if(parsedDate.length != 3) return false;
	month = parsedDate[0];
	day = parsedDate[1];
	year = parsedDate[2];
	
	//start new code
	//check string lengths and formatting of them before moving on...	
	if(year.length != 4){
		return false;}


	//d = month.toString();
	if(month.substring(0,1)=='0'){
		return false;}

	if(day.substring(0,1)=='0'){
		return false;}

	//end new code	
	
	// CREATE DATE
	var dateObj = new Date(month+'/'+day+'/'+year);

	// CHECK MONTH
	d = month - 1;
	if(d != dateObj.getMonth()) return false;

	// CHECK DAY

	b = dateObj.getDate();
	if (day.toString() != b.toString()) return false;

	// CHECK YEAR
	if(year.length != 2 && year.length != 4){
		return false;}

	c = dateObj.getFullYear();
	if(year.length == 4 && year.toString() != c.toString()){
		return false;}

	if(year.length == 4 && (dateObj.getFullYear() < 1900 || dateObj.getFullYear() > 2500)){
		return false;}

	return true;
	}

	
function isNumber(inNum)
	{
	if(inNum == '')
		{
		return false;
		}

	var allowables = '0123456789';
	var numLen = inNum.length;

	for(z=0; z<numLen; z++)
		{
		if(allowables.indexOf(inNum.charAt(z)) < 0)
			{
			return false;
			}
		}
	return true;
	}
	
function isFloat(inNum)
	{
	if(inNum.length < 1)
		{
		return false;
		}

	var allowables = '-0123456789.';
	var numLen = inNum.length;

	for(z=0; z<numLen; z++)
		{
		if(allowables.indexOf(inNum.charAt(z)) < 0)
			{
			return false;
			}
		}
	return true;
	}


function setSelectVal(selectElement, theValue)
	{
	for(i=0; i<selectElement.options.length; i++)
		{
		if(selectElement.options[i].value == theValue)
			{
			selectElement.selectedIndex = i;
			}
		}
	}
	
function showState(country_field, state_field, province_field, state_span, province_span)
	{
	var country_field = document.getElementById(country_field);
	var state_field = document.getElementById(state_field);
	var province_field = document.getElementById(province_field);
	var province_span = document.getElementById(province_span);
	var state_span = document.getElementById(state_span);
	
	if(country_field[country_field.selectedIndex].value == 'US')
		{
		state_span.style.display = '';
		province_span.style.display = 'none';
		province_field.selectedIndex = 0;
		}
	else if(country_field[country_field.selectedIndex].value == 'CA')
		{
		state_span.style.display = 'none';
		state_field.selectedIndex = 0;
		province_span.style.display = '';
		}
	else
		{
		state_span.style.display = 'none';
		state_field.selectedIndex = 0;
		province_span.style.display = 'none';
		province_field.selectedIndex = 0;
		}
	}
	
function GetXmlHttpObject(){ 
	var objXMLHttp=null

	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}

	return objXMLHttp}
	
function trimAll(sString)
	{
	while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
	}
	
function popDhtmlWindow()
	{
	document.getElementById('dhtml_window').style.display = 'block';
	}
	
function hideDhtmlWindow()
	{
	document.getElementById('dhtml_window').style.display = 'none';
	}
	
function getDaysBetweenDates( date_one, date_two )
{
	if( isDate( date_one) && isDate( date_two ) )
	{
		var one_day = 1000*60*60*24;  //in milliseconds
		var date_one_time = new Date( date_one ).getTime();
		var date_two_time = new Date( date_two ).getTime();
		var diff_time = Math.abs( date_one_time - date_two_time );
		return Math.ceil( diff_time/one_day );
	}
	
	return 0;
}

function getAge( date_of_birth, date_to )
{
	if (isDate(date_of_birth) && isDate(date_to))
	{
	
		var uptoDate = new Date(date_to);
		var birthDate = new Date(date_of_birth);
		var age = uptoDate.getFullYear() - birthDate.getFullYear();
		var m = uptoDate.getMonth() - birthDate.getMonth();
		if (m < 0 || (m === 0 && uptoDate.getDate() < birthDate.getDate())) {
			age--;
		}
		
	    return age;
	}
	
	return "";
	
}

