var curVisBlink = "";
var curVisIndex = 0;
var curVisInterval = 200;
var cutVisRatio = 20;


////////////////////////////////////////////////////////////////////////////////////
/// 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;
}

// Just another name.
function ck()
{
	return cc();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///  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 replaceCK(pURL)
{
	var reCK;
	var nURL = pURL;
	
	// Create a regular Expression Object.
	reCK = /^(.*)([?&]ck=)(\d*)(&.*|$)/;

	// If match replace the old number by the number generated from the function		
	if(reCK.test(pURL))
	{
		nURL = nURL.replace(/ck=\d+/g,"ck=" + ck());
	}
	else //add a ck= to the passed URL.
	{
		if(nURL.indexOf("?")>=0)
		{
			nURL = nURL + "&ck=" + ck();
		}
		else
		{
			nURL = nURL + "?ck=" + ck();
		}
	}
	
	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(/;|~/g);
	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);
}


/////////////////////////////////////////////////////////////////////
// Break the String into a Hash
/////////////////////////////////////////////////////////////////////
function HashBuilder(initStr, tokDelim, valDelim, filters)
{
	var hashTable	= new Array();
	var initTokens	= initStr.split(tokDelim);
	var thisToken;
	var keyPieces;
	var idx ;
	var filterR, filterW;
	var keyID, keyVal, keyPerm, keyR, keyW;
	
	////////////////////////////////////
	// Get filters.
	///////////////////////////////////
	filterR = extractParam("R",filters);
	filterW	= extractParam("W",filters);
	
	if((!filterR)||((filterR!="0") && (filterR!="1")))
	{
		filterR = "?"
	}

	if((!filterW)||((filterW!="0") && (filterW!="1")))
	{
		filterW = "?"
	}
	
	///////////////////////////////////
	// Go through one by one ...
	//////////////////////////////////
	for(idx=0; idx<initTokens.length; idx++)
	{
		thisToken	= initTokens[idx];
		keyPieces	= thisToken.split(valDelim);
		
		keyID		= keyPieces[0];
		keyVal		= keyPieces[1];
		keyPerm		= keyPieces[2];
		
		keyR		= keyPerm.substr(0,1);
		keyW		= keyPerm.substr(1,1);
		
		// Create an Array entry in this Hash.
		if( ((filterR=="?") || (filterR==keyR)) && ((filterW=="?") || (filterW==keyW)))
		{
			hashTable[keyID] = new Array(keyVal,keyR,keyW);
		}
	}
	
	// Return the Hash 
	return hashTable
}

/////////////////////////////////////////////////////////////////////////////////////////
/// 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
	}

	// 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;
	}
	
	//Assign a value to the footer of the window.
	if(!scrFooter)
	{
		scrFooter	= "";
		theBL		= 0;
	}

	// window Dimension - Set the height to the closest multiple of 4.
	var theML		= theH - theTL - theBL;
	
	// Set the Div Style;
	var divStyle	 = "HEIGHT:100%;";
	divStyle		+= "WIDTH:100%;";
	divStyle		+= "PADDING-RIGHT:10px;";
	divStyle		+= "PADDING-TOP:5px;";
	divStyle		+= "PADDING-BOTTOM:5px;";
	divStyle		+= "SCROLLBAR-FACE-COLOR: #d1d1a7;";
	divStyle		+= "SCROLLBAR-BASE-COLOR:#ffffff;";
	divStyle		+= "SCROLLBAR-HIGHLIGHT-COLOR:#606060;";
	divStyle		+= "SCROLLBAR-SHADOW-COLOR:#606060;";
	divStyle		+= "SCROLLBAR-3DLIGHT-COLOR:#606060;";
	divStyle		+= "SCROLLBAR-ARROW-COLOR:#0000FF;";
	divStyle		+= "SCROLLBAR-TRACK-COLOR:#e7e7ce;";
	divStyle		+= "SCROLLBAR-DARKSHADOW-COLOR: #606060;";
	divStyle		+= "OVERFLOW-Y:auto;";
	
	// Build the HTML string
	htmlStr += "<TABLE style='PADDING-LEFT:10px;' onselectstart='return false;' HEIGHT=" + theH + "px WIDTH='100%' BORDER=0 CELLSPACING='0' CELLPADDING='0'>";
	htmlStr += "<TR height=" + theTL + "px valign=middle bgcolor='#949408' ><TD style='COLOR:white;FONT-FAMILY:Arial;FONT-SIZE=8pt;FONT-WEIGHT:BOLD;'>" + scrTitle + "</TD></TR>";
	htmlStr += "<TR height=" + theML + "px valign=middle bgcolor='#FEFEE4' ><TD style=\"TEXT-ALIGN:justify;FONT-FAMILY:Arial;FONT-SIZE=8pt\">"; 
	htmlStr += "<DIV style='" + divStyle + "'>";
	htmlStr += unescape(scrContent)
	htmlStr += "</DIV>";
	htmlStr += "</TD></TR>";
	
	if(scrFooter != "")
	{
		htmlStr += "<TR height=" + theBL + "px valign=middle bgcolor='#FEFEE4' ><TD style='COLOR:AliceBlue;FONT-SIZE=8pt;FONT-WEIGHT:BOLD;' width=100% colspan=1>" + scrFooter + "</TD></TR>";
	}
	
	htmlStr	+= "</TABLE>";

	popWinBody.style.border	= "1 solid #666666";
	popWinBody.innerHTML	= htmlStr;
	popWin.show(event.screenX,event.screenY,theW,theH);
	
	return popWin
}


function GeneralToolTip(scrDimension, scrTitle, scrContent)
{
	// variables which has to do with the mesurement.
	var theW, theH, 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;

	// Check if we have the correct number of parameters.
	if(arguments.length < 3)
	{
		alert("Wrong usage of GeneralToolTip.\n\nUsage : GeneralToolTip(scrDimension, scrTitle, scrContent)");
		return -1
	}
	
	// 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
	
	// Build the HTML string
	htmlStr += "<TABLE bgcolor='#FFFFE3' onselectstart='return false;' HEIGHT=" + theH + "px WIDTH='100%' CELLSPACING='0' CELLPADDING='0'>"
	htmlStr += "<TR ><TD style=\"TEXT-ALIGN:Center;FONT-FAMILY:'Arial';FONT-SIZE=11pt;COLOR:#0000FF;FONT-WEIGHT:Bold\">" + scrTitle + "</TD></TR>"
	htmlStr += "<TR ><TD style=\"TEXT-ALIGN:justify;FONT-FAMILY:'Arial';FONT-SIZE=9pt\">" + scrContent + "</TD></TR>"
	htmlStr	+= "</TABLE>"

	//alert(htmlStr)
	popWinBody.style.background= "#FFFFE3"
	popWinBody.style.border	= "1 solid #999999";
	popWinBody.style.padding = "7px 7px 7px 7px";
	popWinBody.innerHTML	= htmlStr;
	//popWin.show(event.screenX,event.screenY-10,theW,theH,event.srcElement);
	popWin.show(30,5,theW,theH,event.srcElement);
	return popWin
}


/////////////////////////////////////////////////////////////////////////////////////////////
/// This function will cause the passed elem to flash in blue color for secsDelay secs.
/// - secsDelay will default to 4 seconds. (< 0  highlight for ever).
/////////////////////////////////////////////////////////////////////////////////////////////
function flash(elem,secsDelay)
{
	var runcode;
	var oldClass;
	var etype = document.all(elem).type;
	var etag  = document.all(elem).tagName;	
	var delayTime;
	
	//Default minDelay
	delayTime = (secsDelay) ? (1000*secsDelay - 0) : (4000 - 0);
	
	if(document.all(elem))
	{
		oldClass = document.all(elem).className;
		if(oldClass.indexOf("flash")==0)
		{
			return ;
		}
		
		if((etype == "text") || (etype == "password"))
		{
			document.all(elem).focus();
			runcode = "document.all('" + elem + "').className ='" + oldClass + "'";
			document.all(elem).className = "flashtext";
			
			if(delayTime > 0)
			{
				setTimeout(runcode,delayTime);
			}
		}
		else if(etype == "textarea")
		{
			document.all(elem).focus();
			runcode = "document.all('" + elem + "').className ='" + oldClass + "'";
			document.all(elem).className = "flashtextarea";
			if(delayTime > 0)
			{
				setTimeout(runcode,delayTime);
			}
		}
		else if( etype == "select-one")
		{
			document.all(elem).focus();
			runcode = "document.all('" + elem + "').className ='" + oldClass + "'";
			document.all(elem).className = "flashdropDown";
			
			if(delayTime > 0)
			{
				setTimeout(runcode,delayTime);
			}
		}
		else if( etype== "file")
		{
			document.all(elem).focus();
			runcode = "document.all('" + elem + "').className ='" + oldClass + "'";
			document.all(elem).className = "flashtext";
			if(delayTime > 0)
			{
				setTimeout(runcode,delayTime);
			}
		}
		else if( etype=="checkbox")
		{
		    document.all(elem).focus();
			runcode = "document.all('" + elem + "').className ='" + oldClass + "'";
			document.all(elem).className = "flashcheckBox";
			if(delayTime > 0)
			{
				setTimeout(runcode,delayTime);
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////
/// This function will take a group of elements and call the flash function on each
/// - secsDelay is time (in seconds) the field will remain highlighted for.
////////////////////////////////////////////////////////////////////////////////////////
function groupflash(group,secsDelay)
{
	var elems = group.split(/;|~/g);
	var i;
	var disFields = "";
	
	// Remove dupes ....
	elems	= RemoveDupes(elems,false)
	
	for(i=0;i<elems.length;i++)
	{
		elem = elems[i];
		
		if(document.all(elem))
		{
			if(!document.all(elem).disabled)
			{
				flash(elem,secsDelay);
			}
			else
			{
				disFields += elem + ";";
			}
		}
	}
	
	if(document.all(elems[0]))
	{
		if(!document.all(elems[0]).disabled)
		{
			document.all(elems[0]).focus();
		}
	}
	
	//Jamil On 19/01/2005
	if(disFields != "")
	{
		disFields = disFields.substr(0,disFields.length -1);
		PopMessage("A", "One or more are fields are problematic but cannot be highlighted because they are disabled.<BR><BR>Fields:<B style='COLOR:red'>" + disFields + "</B>.","Report the fields list to the administrator.");
	}
}

////////////////////////////////////////////////////////////
// Scan for all blink text and make them blink ....
////////////////////////////////////////////////////////////
function TextBlinker() 
{
	var blink = document.getElementsByTagName("BLINK")
	
	for (var i=0; i<blink.length; i++)
	{
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
	}
}

///////////////////////////////////////////////////////////
// Make all the the Text Blink ....
///////////////////////////////////////////////////////////
function StartTextBlinker() 
{
	if (document.forms[0])
	{
		setInterval("TextBlinker()",1000);
	}
}


///////////////////////////////////////////////////////////
// Make all the the Text Blink ....
///////////////////////////////////////////////////////////
function StartTextBlinkerByTag(tagName, tagMarker, stopOver) 
{
    if(arguments.length != 3)
    {
        alert("Wrong usage of : StartTextBlinkerByTag");
        return;
    }

	if (document.all)
	{
		setInterval("TextBlinkerByTag('" + tagName  + "','" + tagMarker + "'," + stopOver + ")", curVisInterval );
	}
}

////////////////////////////////////////////////////////////
// Scan all object of the given tag and have the marker in thir ID.
////////////////////////////////////////////////////////////
function TextBlinkerByTag(tagName, tagMarker, stopOver) 
{
	var blink = document.all.tags(tagName)
	curVisBlink = ((curVisBlink == "") ? "hidden" : "");
	curVisIndex = curVisIndex - 0;
	
	//alert(curVisIndex + " - " + curVisBlink + " - " + cutVisRatio)
	
	// Show and Hide.
	if(curVisIndex >= cutVisRatio)
	{
	    curVisIndex = 0;
	}
	else
	{
	    curVisIndex++;
	}
	
	// hide on zero otherwise show.
	if(curVisIndex == 0)
	{
	    curVisBlink = "hidden";
	}
	else
	{
	    curVisBlink = "";
	}
	
	for (var i=0; i<blink.length; i++)
	{
	    var curElem = blink[i];
	    
	    if((curElem.id) && (curElem.id != "") && (EndsWith(curElem.id, tagMarker, 0)))
	    {
	        var stopBlink = ((curElem.stopblink) && ( curElem.stopblink == 1))
	        
	        //blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
	        
	        if((!stopOver) || (!stopBlink))
	        {
		        blink[i].style.visibility = curVisBlink;
		    }
		    else
		    {
		        blink[i].style.visibility = "";
		    }
	    }
	}
}



///////////////////////////////////////////////////////////////////////////////
// This function will basically remove duplicate elements from the array.
// 1. inArray is the Array from which the dupes should be removed.
// 2. sortFlag indicate if the Array shour be sorter or not.
///////////////////////////////////////////////////////////////////////////////
function RemoveDupes(inArray, sortFlag)
{
	var i, j;
	var curVal;
	var newArray = new Array(); 
	var found;
	
	if((typeof(inArray) != "object") || (!inArray.length))
	{
		alert("The function 'RemoveDupes' expects an array as the first parameter"); 
		return inArray
	}
	
	////////////////////////////////////////
	// Dow we need to sort the Array.
	////////////////////////////////////////
	if(sortFlag)
	{
		inArray = inArray.sort();
	}

	///////////////////////////////////////
	// Loop through and eliminate dupes.
	///////////////////////////////////////
	for(i=0; i<inArray.length; i++)
	{
		curVal = inArray[i];
		////////////////////////////////
		// Search the new Array ...
		////////////////////////////////
		found = false;
		for(j=0; j<newArray.length; j++)
		{
			if(newArray[j] == curVal)
			{
				found = true;
			}
		}
		// Add it if it is not already there ....
		if(!found)
		{
			newArray[newArray.length] = curVal;
		}
	}
	
	//Return and exit.
	return newArray
}



//////////////////////////////////////////////////////////////////////////////////////////////
/// This function will return the version of the browser used to browse the site.
/// IE browser older than version 5 or non IE will be returned as OTHER.
//////////////////////////////////////////////////////////////////////////////////////////////
function SniffBrowser()
{
	var browser="OTHER";

	if(navigator.appVersion.indexOf('MSIE 5.5')>0)
	{
		browser='MSIE5'
	}
	else 
	if(navigator.appVersion.indexOf('MSIE 6')>0)
	{
		browser='MSIE6'
	}			
	else if(navigator.appVersion.indexOf('MSIE 7')>0)
	{	
		browser='MSIE7'
	}						
	else if(navigator.appVersion.indexOf('MSIE 8')>0)
	{	
		browser='MSIE8'
	}						
	else if(navigator.appVersion.indexOf('MSIE 9')>0)
	{	
		browser='MSIE9'
	}						
	else if(navigator.appVersion.indexOf('MSIE 10')>0)
	{
		browser='MSIE10'
	}						
	else if(navigator.appVersion.indexOf('MSIE 11')>0)
	{
		browser='MSIE11'
	}						
	
	return browser
}

/////////////////////////////////////////////////////
// Dummy functions to return true/false;
/////////////////////////////////////////////////////
function dtrue()
{
	return true;
}

function dfalse()
{
	return false;
}

// Start of new code ... vvdolar 9/Jul/2010

//window.onload = window_onload;
var dispLHSMenu= '1';
var gapCarPark = '';
var mast_PrefixMain = '';
//function window_onload(){
/*
    if (gapCarPark){
        if (gapCarPark=="1"){
            document.getElementById(mast_PrefixMain +"tblGapFull").style.display= "";  
        }
    }
    if (dispLHSMenu=='1'){
        document.getElementById("LHSMenu").style.display= "";  
    }


}
*/
