function textCounter(field,cntfield,maxlimit) 
{
	if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit);
	else cntfield.value = maxlimit - field.value.length;
}


function ChangeClass(menu, newClass) 
{ 
	 if (document.getElementById) 
	 { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 

//redirect functions

function ChangeUrl(url)
{
	location.href=url;
}

function MM_openBrWindow(theURL,winName,features)
{ 
  window.open(theURL,winName,features);
}

function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) 
{ 
  if (confirm(messagetext)==1)
  {
  	location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
  }
}

function BRB_PHP_DelWithCon_2_variables(deletepage_url,field_name, field_name2 ,field_value,field_value2,messagetext) 
{ 
  if (confirm(messagetext)==1)
  {
  	location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'&'+field_name2+'='+field_value2+'\"');
  }
}

function um_parametrii(val,pre)
{
	ref=document.getElementById(pre+"param"+val).value;
	if(document.getElementById(pre+"param"+val).checked==true)
	{
		for(i=0;i<=50;i++)
		{
			if(document.getElementById(pre+"param"+i))
			{
				if(document.getElementById(pre+"param"+i).value!=ref) document.getElementById(pre+"param"+i).disabled=true;
			}
		}
	}
	else
	{
		for(i=0;i<=50;i++)
		{
			if(document.getElementById(pre+"param"+i))
			{
				if((document.getElementById(pre+"param"+i).checked==true) && (document.getElementById(pre+"param"+i).value==ref))
				{
					return 0;
				}
			}
		}
	
		for(i=0;i<=50;i++)
		{
			if(document.getElementById(pre+"param"+i))
			{
				if(document.getElementById(pre+"param"+i).value!=ref) document.getElementById(pre+"param"+i).disabled=false;
			}
		}
	}
}

//addGraph is used to insert a chart into the page
//elementId is the element that will contain the chart
//scriptUsed is the php (or xml) script that builds the chart input configuration
function addGraph(elementId, scriptUsed, libraryUsed )
{
	addGraph4(elementId, scriptUsed, libraryUsed, '650', '900' ,'high');
}

function addGraph3(elementId, scriptUsed, libraryUsed, height)
{
	addGraph4(elementId, scriptUsed, libraryUsed, height, 'high');
}

function addGraphJava(elementId, scriptUsed, libraryUsed, height) {
	var _app = navigator.appName;
	var htmlContent = "";
	if (_app == 'Microsoft Internet Explorer') {
		htmlContent += ' <OBJECT  ';
		htmlContent += '	width="900" ';
		htmlContent += '	height="'+height+'" ';
		htmlContent += 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
		htmlContent += ' codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab" ';
		htmlContent += '	>';
		htmlContent += '<PARAM name="code"	value="JCApplet.class">';
		htmlContent += '<PARAM name=archive	value="'+libraryUsed+'/jc_applet.jar,'+libraryUsed+'/JClib/gnujaxp.jar,'+libraryUsed+'/JClib/iText-2.1.3.jar,'+libraryUsed+'/JClib/jcommon.jar,'+libraryUsed+'/JClib/jcommon-1.0.15.jar,'+libraryUsed+'/JClib/jcommon-1.0.15.jar,'+libraryUsed+'/JClib/jfreechart-1.0.12.jar,'+libraryUsed+'/JClib/jfreechart-1.0.12-experimental.jar,'+libraryUsed+'/JClib/servlet.jar,'+libraryUsed+'/JClib/swtgraphics2d.jar">';
		htmlContent += '<PARAM name="inputFile" value="'+scriptUsed+'">';
		htmlContent += '	</OBJECT> ';
	}
	else {
		htmlContent += ' <applet archive="'+libraryUsed+'/jc_applet.jar,'+libraryUsed+'/JClib/gnujaxp.jar,'+libraryUsed+'/JClib/iText-2.1.3.jar,'+libraryUsed+'/JClib/jcommon.jar,'+libraryUsed+'/JClib/jcommon-1.0.15.jar,'+libraryUsed+'/JClib/jcommon-1.0.15.jar,'+libraryUsed+'/JClib/jfreechart-1.0.12.jar,'+libraryUsed+'/JClib/jfreechart-1.0.12-experimental.jar,'+libraryUsed+'/JClib/servlet.jar,'+libraryUsed+'/JClib/swtgraphics2d.jar"';
		htmlContent += ' code="JCApplet.class"';
		htmlContent += '	width="900"';
		htmlContent += '	height="'+height+'"';
		htmlContent += '	>';
		htmlContent += '	<param name="inputFile" value="'+scriptUsed+'">';
		htmlContent += '	</applet> ';
	}
	
	//document.write(htmlContent);
	document.getElementById(elementId).innerHTML = htmlContent;
}


function addGraph4(elementId, scriptUsed, libraryUsed, height, width, quality)
{
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
			alert("This page requires AC_RunActiveContent_overwrite.js.");
	} else {
			
			var hasRightVersion = true;//DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
			if(hasRightVersion) {
				//alert (scriptUsed);
				var htmlContent = AC_FL_RunContent(
					'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
					'width', width,
					'height', height,
					'scale', 'noscale',
					'salign', 'TL',
					'bgcolor', '#777788',
					'wmode', 'opaque',
					'movie', 'charts',
					'src', libraryUsed+'/charts',
					'FlashVars', 'library_path='+libraryUsed+'/charts_library'+'&xml_source='+scriptUsed, 
					'id', 'my_chart',
					'name', 'my_chart',
					'menu', 'true',
					'allowFullScreen', 'true',
					'allowScriptAccess','sameDomain',
					'quality', quality,
					'align', 'middle',
					'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
					'play', 'true',
					'devicefont', 'false'
					); 
				
				//insert the generated content in the element we specify
				//id of the element is elementId
				//the htmlContent generated is htmlContent
				
				//document.write(htmlContent);
				document.getElementById(elementId).innerHTML = htmlContent;
				
			} else {
				var alternateContent = 'This content requires the Adobe Flash Player. '
				+ '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
				document.write(alternateContent);
			}
	}
}

function addGraph2(scriptUsed, libraryUsed, width)
{
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
			alert("This page requires AC_RunActiveContent_overwrite.js.");
	} else {
			
			var hasRightVersion = true;//DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
			if(hasRightVersion) {
				//alert (scriptUsed);
				var htmlContent = AC_FL_RunContent(
					'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
					'width', width,
					'height', '650',
					'scale', 'noscale',
					'salign', 'TL',
					'bgcolor', '#777788',
					'wmode', 'opaque',
					'movie', 'charts',
					'src', libraryUsed+'/charts',
					'FlashVars', 'library_path='+libraryUsed+'/charts_library'+'&xml_source='+scriptUsed, 
					'id', 'my_chart',
					'name', 'my_chart',
					'menu', 'true',
					'allowFullScreen', 'true',
					'allowScriptAccess','sameDomain',
					'quality', 'high',
					'align', 'middle',
					'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
					'play', 'true',
					'devicefont', 'false'
					); 
				
				//insert the generated content in the element we specify
				//id of the element is elementId
				//the htmlContent generated is htmlContent
				document.write(htmlContent);
			} else { 
				var alternateContent = 'This content requires the Adobe Flash Player. '
				+ '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
				document.write(alternateContent);
			}
	}
}

//#### invert day with month in a string, Ex: 10/30/2008 -> 30/10/2008
//#### input: the date in format mm/dd/yyyy
//#### output: the date in format dd/mm/yyyy or false if the format is not the one we expect
function invert_day_with_month(americanDate)
{
	var temp = new Array();
	temp=americanDate.split("/");
	if(temp.length!=3)
		return false;
	return ''+temp[1]+'/'+temp[0]+'/'+temp[2];
}


//#### this function is used to check if the 2 dates used in this page are of correct input
//#### input: the id's of the 2 input tags in the page that we check
//#### output: false if at least one of the dates is not valid, true if both are valid
function check_date_validity(dateId1, dateId2)
{
	//#### we ceck the validity of the dates we use on the querryes in this page
	if(document.getElementById(dateId1) && document.getElementById(dateId2) && (document.getElementById(dateId1) != '') && (document.getElementById(dateId2) != ''))
	{
		var dateValue = invert_day_with_month(document.getElementById(dateId1).value);
		if(dateValue == false)
		{
			alert('Atentie! Intervalul de timp introdus nu este valid!');
			return false;
		}
		var date1 = new Date(dateValue);
		dateValue = invert_day_with_month(document.getElementById(dateId2).value);
		if(dateValue == false)
		{
			alert('Atentie! Intervalul de timp introdus nu este valid!');
			return false;
		}
		var date2 = new Date(dateValue);
		
		if( date1 == 'Invalid Date' || date2 == 'Invalid Date')
		{
			alert('Atentie! Intervalul de timp introdus nu este valid!');
			return false;
		}
		if(Number(date1) > Number(date2))
		{
			alert('Atentie! Prima data a intervalului este mai mare ca a doua!');
			return false;
		}	
	}
	else
	{
		alert('Atentie! Campurile pentru alegerea intervalului de timp nu sunt setate!');
		return false;
	}
	
	return true;
}
