//FA:SCAN29102008 - showing animation for processing
function showanimation(){
    //MC: First check if the DIV exists or not, so that it does not return any error.
    if (document.getElementById('pagewidth'))
	{
		document.getElementById('pagewidth').style.visibility='hidden';
    }
    //MC: In portals the main DIV is "allcontent" instead of "pagewidth"
    if (document.getElementById('allcontent'))
	{
		document.getElementById('allcontent').style.visibility='hidden';
    }
    var h1 = document.getElementsByTagName("h1"); 
    for (var i = 0; i < h1.length; i++) { 
        h1[i].style.display = 'none'; 
    }
    document.getElementById('searching').style.display='block';
}

/* Shows an alternate image if the src image is missing, should be called from an onerror event on an img tag.*/
function showalternate(obj,image){

    if (obj.src != image){
         obj.src=image;
	}
}

/*aaaaaaaaaaaaa*/
function setFocus(ctrlID)
{
//    document.getElementById(ctrlID).focus();
}
//var staying_in_site = false;
/*
window.onbeforeunload = popup;

if (window.onbeforeunload = popup)
{
    alert("here u go");
}
else
{
    alert("here you dont go");
}


function popup() {
  if(staying_in_site == false) {
    return "are you sure??? u kidding yeah?";
  }
}
*/
/*aaaaaaaaaaaaa*/

function AJ() {
	var obj;
	if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
	else if (window.ActiveXObject){
		try{
			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
		}
		catch(er){
			try{
				obj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(er){
				obj= false;
			}
		}
	}
	return obj;
}

function isThere(url) {
	var req= new AJ(); // XMLHttpRequest object
	try {
		req.open("HEAD", url, false);
		req.send(null);		
		return req.status== 200 ? true : false;
	}
	catch (er) {
		return false;
	}
}

function bookmark()
{
	if (window.external) 
	{ 
		window.external.AddFavorite(document.location,document.title); 
	} 
}

function printpage()
{
	var pr = (window.print)?1:0;
  	if(pr) //NS4,IE5
	{
    	window.print();
    }
    else
    {
		alert("Sorry, your browser doesn't support this feature.");
	}
}

/* 
used to disable the submit button once a user has clicked it
pass thru the objName and eventArgument if the submit has an server side onClick event already
*/
function disableSubmitButton(obj, newValue, objName, eventArgument)
{
	obj.disabled = true;
	obj.value = newValue;
	if (objName != null)
	{
		__doPostBack(objName, eventArgument);
	}
}

function setcalendar(cal)
{
	var date = cal.date;
	var time = date.getTime()
	var fieldname = cal.params.inputField.name;
	var oDate = document.getElementById(fieldname);
	var oDay = document.getElementById(fieldname.replace('_Date','_Day'));
	var oMonth = document.getElementById(fieldname.replace('_Date','_Month'));
	var oYear = document.getElementById(fieldname.replace('_Date','_Year'));
	
	oYear.value = date.getFullYear();
	oMonth.value = Right('0' + (date.getMonth() + 1),2);
	createdays(oDate,oDay,oMonth,oYear)
	oDay.value = Right('0' + date.getDate(),2);
	resetdatefield(oDate,oDay,oMonth,oYear);
}

function createdays(aoDateField,aoDay,aoMonth,aoYear)
{
	var i = 1;
	var ldToday = new Date();
	var liYear = (aoYear.value.length > 0)?aoYear.value:ldToday.getFullYear();
	var liMonth = (aoMonth.value.length > 0)?aoMonth.value:ldToday.getMonth();
	var ldLastDay = new Date(liYear,aoMonth.value,0);
	var liLastDay = ldLastDay.getDate();
	var liSelected = aoDay.selectedIndex
	aoDay.length = 0;
	aoDay.options[0] = new Option('Day','');
	for(k = 1;k < liLastDay + 1;k++){
		aoDay.options[i] = new Option(Right('0' + k,2),Right('0' + k,2));
		i++;
	}
	aoDay.selectedIndex = (liSelected > aoDay.length)?aoDay.length - 1:liSelected;
	resetdatefield(aoDateField,aoDay,aoMonth,aoYear);
}

function resetdatefield(aoDateField,aoDay,aoMonth,aoYear)
{
	var ldToday = new Date();
	var liYear = (aoYear.value.length > 0)?aoYear.value:ldToday.getFullYear();
	var liMonth = (aoMonth.value.length > 0)?aoMonth.value:ldToday.getMonth() + 1;
	var liDay = (aoDay.value.length > 0)?aoDay.value:ldToday.getDate();
	aoDateField.value = Right('0' + liDay,2) + '/' + Right('0' + liMonth,2) + '/' + liYear;
}

function dateGreaterThan(date, y, m, d) {
	ldToday = new Date();
	return (date >= ldToday)?'':'shaded';
}

function dateGreaterThanEqual(date, y, m, d) {
	ldToday = new Date();
	return (date >= ldToday)?'':'shaded';
}

function dateLessThan(date, y, m, d) {
	ldToday = new Date();
	return (date < ldToday)?'':'shaded';
}

function dateLessThanEqual(date, y, m, d) {
	ldToday = new Date();
	return (date <= ldToday)?'':'shaded';
}

function openlink(url)
{
	location.href(url);
	return;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// adding pop up window
function openpopup(popurl)
{
	var winpops=window.open(popurl,"","width=360,height=400,toolbar='no',location='no',status='no',scrollbars,menubar='no',resizable='no',left='0',top='0'")
}

function displayEmail(Server, Login, Display)
{
    if ((Display.length == 0)) 
    {
        document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>"); 
    }
    else 
    {
        document.write("<a href="+ "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>"); 
    }
}

//FA:SCAN06082009 - clear the value in search box
function ClearValue()
{   
    document.getElementById('keyword').style.color = '#000';
    
    if(document.search_form.keyword.value=='SEARCH')
    {   
        document.search_form.keyword.value = '';           
    } 
}
//FA:SCAN11092009 - Set the height of maincol to the height of wrapper class. IM2421
function SetContentHeight() {
    var Wrapper=document.getElementById("wrapper");     
    var MainContent=document.getElementById("maincol");
    var WrapperHeight = Wrapper.offsetHeight;        
    
    MainContent.style.height = WrapperHeight + "px";
    //maincontent.margin="auto";               
 } 

//Show/Hide specific controls in all the forms.
function ShowHideControl()
{
    for(k = 0; k < document.forms.length; k++)
    {
        for(j = 0; j < document.forms[k].elements.length; j++)
        {
	        if(document.forms[k].elements[j].type=='select-one')
	        {
	            //alert (document.forms[k].elements[j].style.visibility);
	        
	            if (document.forms[k].elements[j].style.visibility == 'hidden')
	            {
	                document.forms[k].elements[j].style.visibility = 'visible';
	            }
	            else
	            {
	                document.forms[k].elements[j].style.visibility = 'hidden';
	            }
	            
	        }
	        else if(document.forms[k].elements[j].type=='textarea')
	        {
		        document.forms[k].elements[j].style.display = 'none';
	        }
        }
    }
    
}

