	function myPopUp( url, name, width, height )
	{
		window.open( url, name, 'width='+width+', height='+height+', scrollbars=yes, resizable=yes, status=yes' );
	}


	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
	
	
	function changeColor( elm ) 
	{
		elmThingy = document.getElementById( elm );
		elmThingy.style.backgroundColor = '#FF8E90';
	}
	        
	function resetColor( elm ) 
	{
		elmThingy = document.getElementById( elm );
		elmThingy.style.backgroundColor = 'white';
	}

		var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

		function base64_encode( input )
		{
			return encode64( input );
		}

		function encode64(input) 
		{
			var output = '';
			var chr1, chr2, chr3;
			var enc1, enc2, enc3, enc4;
			var i = 0;
		
			do {
				chr1 = input.charCodeAt(i++);
				chr2 = input.charCodeAt(i++);
				chr3 = input.charCodeAt(i++);
		
				enc1 = chr1 >> 2;
				enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
				enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
				enc4 = chr3 & 63;
		
				if (isNaN(chr2)) {
					enc3 = enc4 = 64;
				} else if (isNaN(chr3)) {
					enc4 = 64;
				}
		
				output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
				keyStr.charAt(enc3) + keyStr.charAt(enc4);
			} while (i < input.length);
		   
			return output;
		}

		function base64_decode(input) {
		   var output = '';
		   var chr1, chr2, chr3;
		   var enc1, enc2, enc3, enc4;
		   var i = 0;
		
		   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
		   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
		
		   do {
		      enc1 = keyStr.indexOf(input.charAt(i++));
		      enc2 = keyStr.indexOf(input.charAt(i++));
		      enc3 = keyStr.indexOf(input.charAt(i++));
		      enc4 = keyStr.indexOf(input.charAt(i++));
		
		      chr1 = (enc1 << 2) | (enc2 >> 4);
		      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		      chr3 = ((enc3 & 3) << 6) | enc4;
		
		      output = output + String.fromCharCode(chr1);
		
		      if (enc3 != 64) {
		         output = output + String.fromCharCode(chr2);
		      }
		      if (enc4 != 64) {
		         output = output + String.fromCharCode(chr3);
		      }
		   } while (i < input.length);
		
		   return output;
		}

		var handleSuccess = function(o)
		{
			
			if(o.responseText !== undefined)
			{   
				document.getElementById( o.argument.element ).innerHTML = o.responseText;
			}   
		}
		
		var handleFailure = function( o )
		{
			alert( o.responseXML );
			alert( 'Something Failed' );
			alert( 'Response Text: ' + o );
			alert( 'Element: ' + o.argument.element );
		}

		//start AJAX stuff		
		var http = createRequestObject(); 
		var myUrl = null;
		var myReturnTo = null;
		var ajaxReturned = false;
		var ajaxDisableId = null;
		function getMyHtml( url, returnTo, disableId  )
		{
			myUrl = url;
			myReturnTo = returnTo;
			ajaxDisableId = disableId;
			http.open('get', myUrl, false );
			http.onreadystatechange = handleProducts; 
			http.send(null);
				
		}
	
		/* Function called to handle the list that was returned from the internal_request.php file.. */
		function handleProducts()
		{
			
			/* Make sure that the transaction has finished. The XMLHttpRequest object 
				has a property called readyState with several states:
				0: Uninitialized
				1: Loading
				2: Loaded
				3: Interactive
				4: Finished */
		
				
			if(http.readyState == 4)
			{ 
				//Finished loading the response
				//document.getElementById('error').innerHTML = '';
				/* We have got the response from the server-side script,
					let's see just what it was. using the responseText property of 
					the XMLHttpRequest object. */
				var response = http.responseText;
				/* And now we want to change the product_categories <div> content.
					we do this using an ability to get/change the content of a page element 
					that we can find: innerHTML. */
				//alert( response );
				document.getElementById(myReturnTo).innerHTML = response;
				if( trim( response ) != '')
				{
					if( ajaxDisableId != null && ajaxDisableId != '' )
					{
						document.getElementById( myReturnTo ).style.display = '';
						document.getElementById( ajaxDisableId ).disabled = true;
					}
				} else {
					if( ajaxDisableId != null && ajaxDisableId != '' )
					{
						document.getElementById( myReturnTo ).style.display = 'none';
						document.getElementById( ajaxDisableId ).disabled = false;
					}
				}
			}
		}
				
		function createRequestObject()
		{
			var request_o; //declare the variable to hold the object.
			var browser = navigator.appName; //find the browser name
			if(window.ActiveXObject)
			{
				/* Create the object using MSIE's method */
				request_o = new ActiveXObject('Microsoft.XMLHTTP');
			} else
			{
				/* Create the object using other browser's method */
				request_o = new XMLHttpRequest();
			}
			return request_o; //return the object
		}

		function trim(s) 
		{
  			while (s.substring(0,1) == ' ') 
			{
				s = s.substring(1,s.length);
			}
			while (s.substring(s.length-1,s.length) == ' ') 
			{
				s = s.substring(0,s.length-1);
			}
			return s;
		}

function checkDate( objDate )
{
	//alert( sender.controltovalidate );

	dt1  = objDate

	dt = new String(objDate.value)
	var dateRegEx = /^([01]?\d)[\.\-\/\s]?([0123]?\d)[\.\-\/\s]?((\d{2})|(\d{4}))$/;
	var yearRegEx = /^((\d{2})|(\d{4}))[\.\-\/\s]?([01]?\d)[\.\-\/\s]?([0123]?\d)$/;
	var superDateValidator = /^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/;

	var result = dt.match(dateRegEx);
	var result_year = dt.match(yearRegEx);

	//alert( valid_date );
	var month;
	var day;
	var year;
	if(result != null)
	{
		month = result[1];
		day = result[2];
		year = addCentury(result[3]);
		dt1.value = (padDateLength(month,2) + "/" + padDateLength(day, 2) + "/" + padDateLength(year, 4));
		//return
	} else if (result_year != null)
	{
		month = result_year[4];
		day = result_year[5];
		year = addCentury(result_year[1]);
		dt1.value = (padDateLength(month,2) + "/" + padDateLength(day, 2) + "/" + padDateLength(year, 4));
		//return
	} else
	{
		if( dt != '' )
		{
			alert( 'Date is invalid' );
		}
	}
	var dt2 = objDate.value
	var valid_date = dt2.match( superDateValidator );
	if( valid_date == null )
	{
		//args.IsValid = true;
		alert( "Date is invalid" );
	}
}

function padDateLength(val, len)
{
	val = "" + val;
	while(val.length < len)
	{
		val = "0" + val;
	}
	return val;
}

function addCentury(yval)
{

	var enteredYear = parseInt(parseFloat(yval))
	var buffer = 10
	var base = new Date()
	var Cent = parseInt(base.getFullYear()/100)*100;

	//alert( 'Entered Year: ' + enteredYear + ', Cent: ' + Cent + ', Base: ' + base.getFullYear() );
	if (yval.length == 2)
	{
		if (Cent+enteredYear > base.getFullYear()+buffer)
		{
			return Cent-100+enteredYear;
		}
		return Cent+enteredYear;
	}

	return enteredYear
}

