function getXMLHTTP()
{
	var result = false;
	if (typeof XMLHttpRequest != "undefined")
		result = new XMLHttpRequest();
	else
	{
		try
		{
			result = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				result = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (ie)
			{
			}
		}
	}
	return result;
}

function utf8_decode ( str_data ) {
		
	var string = "", i = 0, c = c1 = c2 = 0;
 
	while ( i < str_data.length ) {
		c = str_data.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		} else if((c > 191) && (c < 224)) {
			c2 = str_data.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = str_data.charCodeAt(i+1);
			c3 = str_data.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	
	string = string.replace( /#38;/g, '' );
	return string;
}

function checkDate( cday, cmonth, cyear ) {
  	var myDayStr = cday * 1;
	var myMonthStr = cmonth * 1;
	var myYearStr = cyear * 1;	
	aMonth	=	new Array( 1,2,3,4,5,6,7,8,9,10,11,12 );
	cDate	=	new Date( );
	
	if( myYearStr * 1 < cDate.getFullYear( ) ) {
		return false;
	}
	if( myMonthStr * 1 < aMonth[cDate.getMonth( )] && myYearStr * 1 <= cDate.getFullYear( ) ) {
		return false;
	}
	if( myDayStr <= ( cDate.getDate() * 1 + 1 ) && myMonthStr * 1 <= aMonth[cDate.getMonth( )] ) {
		return false;
	}
	
	/* Using form values, create a new date object
	using the setFullYear function */
	var myDate = new Date();
	myDate.setFullYear( myYearStr, myMonthStr, myDayStr );

	if ( myDate.getMonth() != myMonthStr ) {
	  return false;
	} else {
	  return true;
	}
}

function checkMail( s )
{
	var a = false;
	var res = false;
	
	if(typeof(RegExp) == 'function')
	{
		var b = new RegExp('abc');
		if(b.test('abc') == true)
		{
			a = true;
		}
	}

	if(a == true)
	{
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)@([a-zA-Z0-9]+)([a-zA-Z0-9\\-\\.]+)([a-zA-Z0-9]+)\.([a-zA-Z]{2,5})$');
		res = (reg.test(s));
	}
	else
	{
		res = (s.search('@') >= 1 &&
			   s.lastIndexOf('.') > s.search('@') &&
			   s.lastIndexOf('.') >= s.length-5)
	}
	
	return(res);
}

function removeChars( field )
{
	field.value = field.value.replace(/[^\d\-\/\ ]/g, "");
}

function checkFieldState( field )
{
	
	var type 		= document.forms[0].elements[field].tagName;
	if( type == "SELECT" )
	{
		if( !document.forms[0].elements[field].selectedIndex && !document.forms[0].elements[field].options[document.forms[0].elements[field].selectedIndex].value )
		{
			alert(fieldEmptyAlert+'!');
	
			document.forms[0].elements[field].style.border 			= "1px solid #FF0000";
			document.forms[0].elements[field].style.backgroundColor = "#f1c6c6";
			document.forms[0].elements[field].focus();
			
			return false;	
		}
		else
		{
			document.forms[0].elements[field].style.border 			= "1px solid #000000";
			document.forms[0].elements[field].style.backgroundColor = "";
			
			return true;			
		}
	}
	else if( type == "INPUT" )
	{
		if( !document.forms[0].elements[field].value || document.forms[0].elements[field].value.replace(/\-{0,}\/{0,}\ {0,}/,"") == '' )
		{
			
			document.forms[0].elements[field].style.border 			= "1px solid #FF0000";
			document.forms[0].elements[field].style.backgroundColor = "#f1c6c6";
			document.forms[0].elements[field].focus();
			
			alert(fieldEmptyAlert+'!');
	
			return false;
		}
		else
		{
			document.forms[0].elements[field].style.border 			= "1px inset #000000";
			document.forms[0].elements[field].style.backgroundColor = "";
			
			return true;
		}		
	}	
}

function setDuration( minval, maxval, selectedval, stdvalue, descPl, descSl ) {
	for( i = minval; i <= maxval; i++ ) {
		if( selectedval != 0 ) {
			if( i == selectedval )
				document.writeln( '<option value="'+i+'" selected>'+i+' '+( i < 2 ? descSl:descPl )+'</option>' );
			else
				document.writeln( '<option value="'+i+'">'+i+' '+( i < 2 ? descSl:descPl )+'</option>' );
		}
		else if( i == stdvalue ) {
			document.writeln( '<option value="'+i+'" selected>'+i+' '+( i < 2 ? descSl:descPl )+'</option>' );
		}
		else
			document.writeln( '<option value="'+i+'">'+i+' '+( i < 2 ? descSl:descPl )+'</option>' );
	}
}