function printFrame(frameName)
	{
		parent.detail.focus();
		parent.detail.print();	
	}

function select_value_from(from_value,from_field)
	{
		var this_value = from_value;
		for(i=0;i<from_field.length;i++)
			if(from_field.options[i].value == this_value)
				from_field.options[i].selected = true;	
			else
				from_field.options[i].selected = false;	
		}


function checknumber(this_field,field_value)
	{
		var x=this_field.value;
		var anum=/(^\d+$)|(^\d+\.\d+$)/;

		if (anum.test(x) || x == '')
			{
				return true;
			}
		else
			{
				alert('Please input a valid '+ field_value + '!');
				this_field.focus();
				return false;
			}
}






//Extra Scripts----------------------------------------------
var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  calendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (calendar != null) {
    // we already have some calendar created
    calendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(true, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    calendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  calendar.setDateFormat(format);    // set the specified date format
  calendar.parseDate(el.value);      // try to parse the text in field
  calendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  calendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

// If this handler returns true then the "date" given as
// parameter will be disabled.  In this example we enable
// only days within a range of 10 days from the current
// date.
// You can use the functions date.getFullYear() -- returns the year
// as 4 digit number, date.getMonth() -- returns the month as 0..11,
// and date.getDate() -- returns the date of the month as 1..31, to
// make heavy calculations here.  However, beware that this function
// should be very fast, as it is called for each day in a month when
// the calendar is (re)constructed.
function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  // construct a calendar giving only the "selected" handler.
  var cal = new Calendar(true, null, flatSelected);

  // hide week numbers
  cal.weekNumbers = false;

  // We want some dates to be disabled; see function isDisabled above
  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  // this call must be the last as it might use data initialized above; if
  // we specify a parent, as opposite to the "showCalendar" function above,
  // then we create a flat calendar -- not popup.  Hidden, though, but...
  cal.create(parent);

  // ... we can show it here.
  cal.show();
}


// Validate the Date


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateDate(DateField){
	var dt=DateField
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }
	/*********** Images Changes******************/
/*
		function newImage(arg) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
	}
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;
function initImgID() {di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}
function findElement(n,ly) {
	d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	d = document;
alert(d.layers);
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (d.layers) {img = findElement(changeImages.arguments[i],0);}
			else {img = d.images[changeImages.arguments[i]];}
			if (img) {img.src = changeImages.arguments[i+1];}
	}
}
	var preloadFlag = false;
	function preloadImages() {
			t_l_corner_b = newImage('/userdata/graphics/header/top_left_rec_blue.gif');
			t_l_corner_r = newImage('/userdata/graphics/header/top_left_rec_red.gif');
			t_r_corner_b = newImage('/userdata/graphics/header/top_right_rec_blue.gif');
			t_r_corner_r = newImage('/userdata/graphics/header/top_right_rec_red.gif');
			b_l_corner_b = newImage('/userdata/graphics/header/bottom_left_rec_blue.gif');
			b_l_corner_r = newImage('/userdata/graphics/header/bottom_left_rec_red.gif');
			b_r_corner_b = newImage('/userdata/graphics/header/bottom_right_rec_blue.gif');
			b_r_corner_r = newImage('/userdata/graphics/header/bottom_right_rec_red.gif');
		preloadFlag = true;
		}
		*/
		

function ChangeColour(column, colourto)
	{
		var e = document.getElementById(column);
		window.document.getElementById(column).style.backgroundColor = colourto;
		return true;
	}

function changeImage(rectangle, imageto)
	{
		window.document.getElementById(rectangle + '_l').src = '/userdata/graphics/header/' + imageto + '_bar_cnr_l.gif';
		window.document.getElementById(rectangle + '_r').src = '/userdata/graphics/header/' + imageto + '_bar_cnr_r.gif';
		return true;
	}

function open_help(story_id)
	{
		parent.detail.location='/show-story.cfm?link_code=HELP';
		return false;
	}

function print_page(story_id,print_story)
	{
		if(print_story)
				LoadFooter();
		else
				LoadFooter('login','back');
		
		parent.detail.document.MainActionForm.todo.value = 'print';
		VerifyForm('print');
		return false;
	}
	
function advanced_search(story_id)
	{
		parent.detail.advanced_search();
		return false;
	}
	
function simple_search(story_id)
	{
		parent.detail.simple_search();
		return false;
	}
	
function export_page(story_id)
	{
		parent.detail.document.MainActionForm.todo.value = 'export';
		VerifyForm('export');
		return false;
	}
function graph_page(story_id)
	{
		parent.detail.document.MainActionForm.todo.value = 'graph';
		VerifyForm('graph');
		return false;
	}

function top_page(story_id)
	{ 
		parent.detail.window.scroll(0,0);
		return false;
	}
function OpenCloseMenu(ObjectID, ShowHide){
	//Show the > next to the menu
		if(document.getElementById(ObjectID+'-Selected'))
		{
			var el = document.getElementById(ObjectID+'-Selected');
			el.style.display = (ShowHide == "Show")?"":"none";
		}

	//Change the class on the link
		if(document.getElementById(ObjectID+'-Link'))
		{
			var el = document.getElementById(ObjectID+'-Link');
			el.className = (ShowHide == "Show")?"pagemenuhlinkSelected":"pagemenuhlink";
		}
		
	//Show or Hide the Sub menu
	for(i=1; i<=200; i++)
	{
		if(document.getElementById(ObjectID+'-'+i))
		{
			var el = document.getElementById(ObjectID+'-'+i);
			el.style.display = (ShowHide == "Show")?"":"none";
		}
		else
		{
			i =200;
		}
	}
}

function refreshLeftMenu(){
parent.menu.location='/userdata/menu.cfm';

}
function refreshTopMenu(){
parent.top_menu.location='/userdata/top_menu.cfm';
}

function LoadFooter(footer_ref,footer_elements){
	if(footer_ref == 'login')
	{
		var el = parent.page_footer.document.getElementById('footer_login');
		el.style.display = "";
		var el = parent.page_footer.document.getElementById('footer_main');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_export_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_export_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_exportdisabled_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_exportdisabled_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_graph_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_graph_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_print_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_print_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_advancedsearch_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_advancedsearch_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_simplesearch_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_simplesearch_2');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_back_1');
		el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_login_back_2');
		el.style.display = "none";
			if (footer_elements)
				{
					arrayOfStrings = footer_elements.split(',');
					for (var i=0; i < arrayOfStrings.length; i++) {
						var el = parent.page_footer.document.getElementById('footer_login_'+arrayOfStrings[i]+'_1');
						el.style.display = "";
						var el = parent.page_footer.document.getElementById('footer_login_'+arrayOfStrings[i]+'_2');
						el.style.display = "";
					}
				}
	}
	else
	{
		var el = parent.page_footer.document.getElementById('footer_login');
			el.style.display = "none";
		var el = parent.page_footer.document.getElementById('footer_main');
			el.style.display = "";	}
}

function resetTableRowsClass(row_from, row_to, start_class){
		
	//Show or Hide the Sub menu
	for(i=row_from; i<=row_to; i++)
	{
		if(document.getElementById('row-'+i))
		{
			var el = document.getElementById('row-'+i);
			if(el.style.display =="")
			{
				el.className = start_class;
	
				if (start_class == "light_class")
					start_class = "dark_class";
				else
					start_class = "light_class";
			}
		}
	}
}
function VerifyForm(todo){
		var vgraph_count = parent.detail.document.MainActionForm.graph_count.value;
		parent.detail.document.MainActionForm.todo.value=todo;
		if (parent.detail.document.MainActionForm.todo.value == 'graph' && vgraph_count == 0)
		{
			alert('Please select at least 1 row to graph!');
			return false;
		}

		if (parent.detail.document.MainActionForm.todo.value == 'export' && parent.detail.document.MainActionForm.showed_record_count.value == 0)

		{
			alert('There is no data to export!');
			return false;
		}
		if (parent.detail.document.MainActionForm.todo.value == 'print' && parent.detail.document.MainActionForm.showed_record_count.value == 0)

		{
			alert('There is no data to print!');
			return false;
		}
		if(parent.detail.document.MainActionForm.export_file && (parent.detail.document.MainActionForm.todo.value == 'export' || parent.detail.document.MainActionForm.todo.value == 'print'))
			parent.detail.document.MainActionForm.action=parent.detail.document.MainActionForm.export_file.value;	
		
		parent.detail.document.MainActionForm.submit();
		return true;
	}

function openPrintWindow(vLink,vToLink)
{
	alert(vLink);
	window.open(vLink, 'Print123455', 'location=no,menubar=no,toolbar=no,height=600,width=800,scrollbars=yes,resizable=yes');
	alert(2);
}