////////////////////////////////////////////////////////////////////////////////////
/// Written By Jamil 
/// The cc function will return the number of seconds since the beginning of the 
/// Year.
/// Please do not remove this date Function
/// Changed By : <Name and explain chnges>
////////////////////////////////////////////////////////////////////////////////////
function cc()
{
	var jdate = new Date();
	var centdate = new Date(jdate.getFullYear(),0,1,1,1,1,1)

	SinceBeginning = Date.parse(jdate) - Date.parse(centdate);
	if((SinceBeginning % 1000) ==0)
	{
		SinceBeginning = SinceBeginning/1000;
	}	
	return SinceBeginning;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///  This Function will make the download button on the status bar visible.
///  - It will also assign the onclick event for the button.  Please note that the clickhandler is not a
///  string variable but the actual function name. example : if your handler is function Hello(){..." then 
///  you would pass Hello to the function not "Hello". 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showDownload(clickhandler)
{
	if(document.all("aladnstatusbar"))
	{
		if( (document.all("dnlist")) && (document.all("dnlist").iam) && (document.all("dnlist").iam=="aladnrc"))
		{
			document.all("dnlist").className = "downBTN";
			if(clickhandler)
			{
				document.all("dnlist").onclick	 = clickhandler;
			}
		}
	}
}


/////////////////////////////////////////////////////////////////////////////////////
//  Append Or update the cc value in the passed URL and return the updated one
//  - if cc is abscent cc=unique will be appended
//  - if it is present the value will be updated to a newly unique value
//  - if more than cc= occurs in the url only the last one will be updated
/////////////////////////////////////////////////////////////////////////////////////
function replaceCC(pURL)
{
	var reCC;
	var nURL = pURL;
	
	// Create a regular Expression Object.
	reCC = /^(.*)([?&]cc=)(\d*)(&.*|$)/;

	// If match replace the old number by the number generated from the function		
	if(reCC.test(pURL))
	{
		nURL = nURL.replace(/cc=\d+/g,"cc=" + cc());
	}
	else //add a cc= to the passed URL.
	{
		if(nURL.indexOf("?")>=0)
		{
			nURL = nURL + "&cc=" + cc();
		}
		else
		{
			nURL = nURL + "?cc=" + cc();
		}
	}
	
	return nURL
}


//////////////////////////////////////////////////////////////////////////////////////
///  Written By Jamil on 11/2/2002
///	 This function will act like a parser to get the assigned value to a given tag.
///  It assumes that the string has the following format
///  tag1:val1;tag2:val2;tag3:val3......
///  The function than will be called with the tag you are after paraID and the whole
///  string to extract from and would return back the value assigned to this tag.
///	 Changed By : <Name and explain chnges>
///                  
//////////////////////////////////////////////////////////////////////////////////////
function extractParam(paraID, paraStr)
{
	var value;
	var pieces;
	var i = 0;
	var rx = new RegExp(paraID + '\s*\:',"i")
	
	pieces = paraStr.split(";");
	for(i=0;i<pieces.length;i++)
	{	
		value = TrimStr(pieces[i]);
		//alert("Looking For : " + paraID + "\n In " + value + "\n Result " + rx.test(value))
		if(rx.test(value))
		{
			//alert(paraID + " Found In : " + value);
			value = value.substr(value.indexOf(":")+1);
			value = TrimStr(value);
			return value;
		}
	}
	
	//alert(paraID + " - " +  paraStr);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Written By Jamil 
/// Function will trim the passed string , that is it will eliminate all leading 
/// and trailing SPACES, HTABS, VTABS, LF, CR and PF 
///  Changed By : <Name and explain chnges>
/////////////////////////////////////////////////////////////////////////////////////////////
function TrimStr(Str)
{
	Str = Str.replace(/^(\s+)+|(\s+)$/g,"");
	return Str
}

////////////////////////////////////////////////////////////////////////////////////////////
/// Written By Jamil 14/2/2002
/// This function will scan the passed form for changes. In order to do that you need to set
/// watches on the element you want to monitor. You do that by setting the wvalue property
/// on the object.
/// <INPUT wvalue=3  ....>
/// The item is than considered changed if the current value on the field id differen
/// from wvalue (the watched value). 
/// Changed By : <Name and explain chnges>
////////////////////////////////////////////////////////////////////////////////////////////
function ScanWatchedForm(pForm)
{
	var idx 
	var flag = false;
	var elem
	
	for(idx=0;idx<pForm.length;idx++)
	{
		elem = pForm.elements[idx];
		if(typeof(elem.wvalue) != "undefined")
		{
			if(elem.wvalue != elem.value)
			{
				flag = true;
				break;
			}
		}
	} 
	return flag;
}
///////////////////////////////////////////////////////////////////////////////////////////////
///
/// This Function will merely tint the scroll bars with some colors.
///
///////////////////////////////////////////////////////////////////////////////////////////////
function colorScroll()
{
	window.document.body.style.scrollbarFaceColor		= jsLightBlue;
	window.document.body.style.ScrollbarHighlightColor	= 'black';
	window.document.body.style.ScrollbarShadowColor		= 'black';
	window.document.body.style.scrollbar3dLightColor	= 'black';
	window.document.body.style.scrollbarArrowColor		= jsDarkBlue;
	window.document.body.style.ScrollbarTrackColor		= 'black';
	window.document.body.style.scrollbarDarkShadowColor	= 'black';
	window.document.body.style.scrollbarBaseColor		= 'black';
}


//////////////////////////////////////////////////////////////////////////////
/// This function will show a pop-up. The ideal use for it is tooltip for a 
/// large text.
/// - You need to specify 
/// 1. The dimention of your tooltip (width:height) e.g. "250:400"
/// 2. The title to show on top of the Popup;
/// 3. The content to be shown in the popup.
/// 4. The scrFooter is an optional parameter and would show in the bottom 
///    line when present.
/////////////////////////////////////////////////////////////////////////////
function aladnToolTip(scrDimension, scrTitle, scrContent, scrFooter)
{
	// variables which has to do with the mesurement.
	var theW, theH, theTL, theBL, theML;
	// input validation.
	var re = /^(\s*)(\d+)[:](\d+)(\s*)$/
	// The HTML side of things.
	// The innerHTML string to be loaded in the window
	var htmlStr		= ""
	var popWin		= window.createPopup();
	var popWinBody	= popWin.document.body;

	// Initialize the top and bottom line. 
	theTL	= 20;
	theBL	= 20;
	
	// Check if we have the correct number of parameters.
	if(arguments.length < 3)
	{
		alert("Wrong usage of aladnToolTip.\n\nUsage : aladnToolTip(scrDimension, scrTitle, scrContent)");
		return -1
	}
	
	//Assign a value to the footer of the window.
	if(!scrFooter)
	{
		scrFooter = "&nbsp;"
	}

	// Extract the diemntion for the window.
	if(!re.test(scrDimension))
	{
		alert("The dimensions of the popup is missing or badly formated;");
		return -1;
	}
	else
	{
		theW	=	RegExp.$2 - 0;
		theH	=	RegExp.$3 - 0;
	}

	// window Dimension - Set the height to the closest multiple of 4.
	var theML		= theH - theTL - theBL;
	
	// Build the HTML string
	htmlStr += "<TABLE onselectstart='return false;' HEIGHT=" + theH + "px WIDTH='100%' BORDER=0 CELLSPACING='0' CELLPADDING='0'>"
	htmlStr += "<TR height=" + theTL + "px valign=middle bgcolor='#3366FF' ><TD>&nbsp;&nbsp;&nbsp;</TD><TD style='COLOR:white;FONT-SIZE=10pt;FONT-WEIGHT:BOLD;' width=100% colspan=3>" + scrTitle + "</TD><TD>&nbsp;&nbsp;&nbsp;</TD></TR>"
	htmlStr += "<TR height=" + theML + "px valign=middle><TD >&nbsp;</TD><TD style=\"TEXT-ALIGN:justify;FONT-FAMILY: Verdana;FONT-SIZE=9pt\">" + unescape(scrContent) + "</TD><TD>&nbsp;</TD></TR>"
	htmlStr += "<TR height=" + theBL + "px valign=middle bgcolor='#3366FF' ><TD>&nbsp;&nbsp;&nbsp;</TD><TD style='COLOR:AliceBlue;FONT-SIZE=8pt;FONT-WEIGHT:BOLD;' width=100% colspan=3>" + scrFooter + "</TD><TD>&nbsp;&nbsp;&nbsp;</TD></TR>"
	htmlStr	+= "</TABLE>"
	
	popWinBody.style.border	= "1 solid #666666";
	popWinBody.innerHTML	= htmlStr;
	popWin.show(event.screenX,event.screenY,theW,theH);
}

/////////////////////////////////////////////////////////////////////////////////////////////
/// This function will cause the passed elem to flash in blue color for 3 secs.
/////////////////////////////////////////////////////////////////////////////////////////////
function flash(elem)
{
	var runcode;
	var oldClass;
	var etype = document.all(elem).type;
	var etag  = document.all(elem).tagName;	
	if(document.all(elem))
	{
		oldClass = document.all(elem).className;
		if(etype == "text")
		{
			document.all(elem).focus();
			document.all(elem).className = "flashtext";
			runcode = "document.all('" + elem + "').className = 'textfield'";
			setTimeout(runcode,3000);
		}
		else if(etype == "textarea")
		{
			document.all(elem).focus();
			document.all(elem).className = "flashtextarea";
			runcode = "document.all('" + elem + "').className = 'textarea'"
			setTimeout(runcode,3000);
		}
		else if( etype == "select-one")
		{
			//document.all(elem).focus();
			document.all(elem).className = "flashdropDown";
			runcode = "document.all('" + elem + "').className = 'dropDown'"
			setTimeout(runcode,3000);
		}
		else if( etype== "file")
		{
			document.all(elem).focus();
			document.all(elem).className = "flashtext";
			runcode = "document.all('" + elem + "').className = '" + oldClass + "'" ;
			setTimeout(runcode,3000);
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////
/// This function will take a group of elements and call the flash function on each
//////////////////////////////////////////////////////////////////////////////////////////////
function groupflash(group)
{
	var elems = group.split(";");
	var i;
	
	for(i=0;i<elems.length;i++)
	{
		elem = elems[i];
		flash(elem);
	}
}

