//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
var oDoc	= window.document;	
var oAll	= window.document.all;	
var oHddn	= window.document.getElementsByTagName("INPUT");
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	window.onload				= init;
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function url2(url)		{	window.location.href	= url;			}
function open2(url)		{	window.open(url,"newwin");				}
function open3(url,args){	window.open(url,"newwin",args);			}
function ws(arg)		{	window.status			= arg;			}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function init()
{
	if(	init.active)	return;
		init.active	=	true;
	
	try
	{
		window.event.cancelBubble	= true;
		
		
		
		window.focus();
	}
	catch(e){ws("init() "+e.description)}
	
	// color search words
	var data = document.all["PageHeader_SearchWords"]
	var container = document.all["tblPage"]
	if(data && !isnull(data.SearchWords) && container){
		multiColorMark(data.SearchWords,container)
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function isNone(o)
{
	if(o)
	{
		if(o.style.display=="none")			return true;	
		if(o.className.indexOf("none")>=0)	return true;	
		else								return false;
	} 
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function none(o)
{
	if(o) o.style.display		= "none";	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function block(o)
{
	if(o) o.style.display		= "block";	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function blocknone(o)
{	
	try
	{
		if(o)
		{
			if(o.style.display=="none" || o.className.indexOf("none")>=0)	
			{
					block(o);
					o.className	= o.className.replace(/none/gim,"");					
			}
			else	none(o);						
		}
	}
	catch(e){ws("blocknone() "+e.description)}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function dbg(O)
{
	if(typeof(O)=="string"||typeof(O)=="number"){alert(O);return;}
	
	var arr	=	[];
	
	for(var o in O){arr.push(o);} arr.sort(); alert(arr.join("; "));
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function trim(str)
{
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {
		return str;
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function getXMLData(xmlpath)
{
	try
	{
		xmlhttp	= new ActiveXObject("Microsoft.XMLHTTP");
		
		xmlhttp.onreadystatechange	= HandleStateChange;
		xmlhttp.Open("GET", xmlpath, false);
		xmlhttp.Send();
	}
	catch (e){"getXMLData() "+ws("postXMLData() "+e.description);}
	
	xmlhttp = null;

	return;

//'''''''''''''''''''''''''
	function HandleStateChange()
	{
		if(xmlhttp.readyState==4)
		{
		}
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function queryString()
{
	this.obj				= {};
	this.qs					= window.location.href;
	this.defaultTemplate	= "templates";
	
	if(this.qs.indexOf("?")<0)		return;
	
	var arr					= this.qs.split("?")[1].split("&");
	
	for(var j=0; j<arr.length; j++)
	{
		if(!arr[j])					continue;
		if(trim(arr[j])=="")		continue;
	
		this.obj[arr[j].split("=")[0]]	= arr[j].split("=")[1];
	}
	
}
//'''''''''''''
function queryString.prototype.getVirtualPath(tmplName)
{
	var tmpl	= trim(tmplName)==""?this.defaultTemplate:tmplName;
	var vpath	= "";
	
	if(this.qs.indexOf(tmpl)>0)	vpath = this.qs.toLowerCase().split(tmpl)[0];
	else						vpath = this.qs.toLowerCase().split(this.defaultTemplate)[0];

	return vpath;
}
//'''''''''''''
function queryString.prototype.getQueryString()
{
	return this.qs.split("?")[1];
}
//'''''''''''''
function queryString.prototype.getParameter(name)
{
	return this.obj[name];
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
//////////////////////
function nvl()
{
	for (var i=0; i<arguments.length; i++) {
		if (!isnull(arguments[i])) return arguments[i];
	}
	return null;
}

//////////////////////
//***********************************************************************************
// Print section
/////////// - global variables - (please set variables before use) /////
var cssURL = "../../Style/General.css";
var _dir = 'ltr';
var _charset = 'windows-1251';
//////////////////////////////////////////////////
function printFrame(frame, onfinish) 
{

	if ( !frame ) 
	{
		frame = window;
	}
	if ( frame.document.readyState !== "complete" &&
		!confirm("The document to print is not downloaded yet! Continue with printing?") )
	{
		if ( onfinish ) onfinish();
		return;
	}

	if ( printIsNativeSupport() ) 
	{
		var focused = document.activeElement; 
		frame.focus();
		frame.self.print();
		if ( onfinish ) onfinish();
		if ( focused && !focused.disabled ) focused.focus();
		return;
	}

	var eventScope = printGetEventScope(frame);
	var focused = document.activeElement;

	window.printHelper = function() 
	{
		execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
		printFireEvent(frame, eventScope, "onafterprint");
		printWB.outerHTML = "";
		if ( onfinish ) onfinish();
		if ( focused && !focused.disabled ) focused.focus();
		window.printHelper = null;
	}

	document.body.insertAdjacentHTML("beforeEnd",
		"<object id=\"printWB\" width=0 height=0 \
		classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");

	printFireEvent(frame, eventScope, "onbeforeprint");
	frame.focus();
	window.printHelper = printHelper;
	setTimeout("window.printHelper()", 0);
}
// helpers
function printIsNativeSupport() 
{
	var agent = window.navigator.userAgent;
	var i = agent.indexOf("MSIE ")+5;
	return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) 
{
	var handler = obj[name];
	switch ( typeof(handler) ) 
	{
		case "string": frame.execScript(handler); break;
		case "function": handler();
	}
}

function printGetEventScope(frame) 
{
	var frameset = frame.document.all.tags("FRAMESET");
	if ( frameset.length ) return frameset[0];
	return frame.document.body;
}


// main print function
// arguments:
//		htmlObj = the html object that clicked in order to perform the click.
function printDoc(htmlObj) 
//
{
	try
	{
		// disable the print button
		htmlObj.disabled = true;
		
		// create html for pop up
		with([]) 
		{
			push('<html dir="'+_dir+'">');
				push('<head>');
					push('<meta http-equiv="Content-Type" content="text/html; charset='+_charset+'">');
					
					// set the link
					push('<link href="' + cssURL + '" rel="stylesheet" type="text/css">');
					
				push('</head>');
				push('<body style="margin0;overflow:hidden">');
				
				// set the inner code
				push( printDivBox.innerHTML);
				push('</body>');
			push('</html>');
		
			// set html and print it
			with(frmPrintBox.window.document) 
			{
				// refresh frame
				write('');
				close();
				
				// set frame code
				write(join(''));
				
				// execute a printing command
				execCommand('Print');
			}
		}
		
		// enable the print button (or clicked object )
		htmlObj.disabled = false;
	} catch(e) 
	{
		alert('function:printDoc():' + e.description)
	}
}

//END of Print section
//***********************************************************************************
function serviceSearchExec()
{
	var searchInput		= trim(oAll.serviceInput.value);
	var searchSelect	= oAll.serviceSelect.value;
	var url				= oAll.Header1_searchText.searchPageURL;
		url			   += "&Search="+searchInput+"&Category="+searchSelect;

	if(checkSearchField(searchInput))
	{
			url2(url);
	}
	else	searchInput.focus();
}
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function filedownload(url)
{
	url2		(HOST_URL+"Shared/Library/saveasdialog.asp?doc="+url);
	//url2		("../../Shared/Library/saveasdialog.asp?doc="+url);
	//open2("../../Shared/Library/saveasdialog.asp?doc="+url);
}
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function printProblems(o)
{
	window.print();
}
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

//SEARCH FORM:
function goToSearchResults()
{
	var searchInput = document.getElementById("Header1_searchText");
	var searchSelect = document.getElementById("Header1_searchSections");
	
	// 2004-12-24: Add Support to search in differrent sites like google
	if (String(searchSelect.value).toUpperCase().indexOf("WWW.")>-1)
	{
		var newSearchWindow	= window.open(searchSelect.value+searchInput.value);
	}
	else
	{
		if(checkSearchField(searchInput.value)){
			document.location.href = searchInput.searchPageURL+"&Search="+searchInput.value.replace(/(^\s+)|(\s+$)/g,'')+"&Category="+searchSelect.value
			return;
		}
		else{
			searchInput.focus();
			return;
		}
	}
}
function goToSearchResultsFromHomepage(){
	
	var searchInput = document.getElementById("searchText");
	if(checkSearchField(searchInput.value)){
		document.location.href = searchInput.searchPageURL+"&Search="+searchInput.value.replace(/(^\s+)|(\s+$)/g,'')
		return;
	}
	else{
		searchInput.focus();
		return;
	}
}
function checkSearchField(str)
{
	var sSearchWord = str;
	var validSearch = true;
	var notValidStr = "";
	if (sSearchWord == '')
	{
		validSearch = false;
		notValidStr = MSG.CLIENT_MSG_EMPTY_SEARCH_CRITERIA;
	}
	if (sSearchWord != '' && sSearchWord.length < 2 )
	{
		validSearch = false;
		notValidStr = MSG.CLIENT_MSG_SHORT_SEARCH_CRITERIA;
	}
	//if (sSearchWord == '"' || sSearchWord == '.' || sSearchWord == '`') {
	//	validSearch = false;
	//	notValidStr = MSG.CLIENT_MSG_INVALID_SEARCH_CRITERIA+"\n\".'";
	//}
	//var regEx = new RegExp("([\\.\\@\\%\\~\\!\\#\\&\\<\\>\\=\\/\\;\\$\\(\\)\\*\\+\\[\\\\\\]\\^\\{\\|\\}])","igm");
	var regEx = new RegExp("([\\@\\%\\~\\!\\#\\&\\<\\>\\=\\/\\;\\$\\(\\)\\*\\+\\[\\\\\\]\\^\\{\\|\\}])","igm");
	if (sSearchWord.match(regEx) != null)
	{
		//notValidStr = MSG.CLIENT_MSG_INVALID_SEARCH_CRITERIA+"\n@%~.!#&-_=<>;$()*+[\]^{|}";
		notValidStr = MSG.CLIENT_MSG_INVALID_SEARCH_CRITERIA+"\n@%~!#&-_=<>;$()*+[\]^{|}";
		validSearch = false;
	}
	if(!validSearch)
	{
		alert(notValidStr);
		return false;
	}
	else return true;
}

var ActiveSearchResultsCategory = null;
var ActivesearchResultsContainerID = -1;
function SearchResultsCategory_OnMouseOver(obj){
	if(ActiveSearchResultsCategory != null && obj == ActiveSearchResultsCategory) return;
	obj.className = "sr_bg_on"
}
function SearchResultsCategory_OnMouseOut(obj){
	if(ActiveSearchResultsCategory != null && obj == ActiveSearchResultsCategory) return;
	obj.className = "sr_bg";
}
function SearchResultsCategory_OnClick(obj,ind){
	
	if(ActiveSearchResultsCategory != null && obj == ActiveSearchResultsCategory){
		document.all["documents_container_"+ActivesearchResultsContainerID].style.display = "none";
		document.all["bullet_container_"+ActivesearchResultsContainerID].className = "sr_category_bullet";
		ActiveSearchResultsCategory = null
		ActivesearchResultsContainerID = -1
	}
	else{
		if(ActiveSearchResultsCategory != null){
			ActiveSearchResultsCategory.className = "sr_bg";
			if(ActivesearchResultsContainerID != -1){
				document.all["documents_container_"+ActivesearchResultsContainerID].style.display = "none";
			}
			document.all["bullet_container_"+ActivesearchResultsContainerID].className = "sr_category_bullet";
		}
		
		obj.className = "sr_bg_on";
		document.all["documents_container_"+ind].style.display = "";
		document.all["bullet_container_"+ind].className = "sr_category_bullet_on";
		
		
		
		ActivesearchResultsContainerID = ind
		ActiveSearchResultsCategory = obj;
	}
	
}


//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function multiColorMark(searchString,o)
{
	try
	{
		if(!o)						return;
		if(searchString=="")		return;
		
		var colors		= ["#FFF8B2","#FFF8B2","#FFF8B2","#FFF8B2","#FFF8B2"];
		
		searchString	= searchString.replace(/\+/gim," ");
		
		var arr			= searchString.split(" ");

		for(var j=0; j<arr.length; j++)
		{
			//if(trim(arr[j])=="")	continue;
			
			if(trim(arr[j]).length < 2) continue;
			
			markText(arr[j],o,colors[j%4]);
		}
	}
	catch(e){throw new Error(" multiColorMark() "+e.description)}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//*	Mark text in a given object
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	function markText(sText,oObject,sColor)
	{
		
		// the color of the markup
		if(!sColor) sColor='yellow';
		
		// create first level objects
		var aPreviusObjects = [oObject];
	
		// while previus level has items
		while(aPreviusObjects.length>0)
		{
			// current level items
			var aLevelObjects = [];
			
			// loop previus level items
			for(var iPrevIndex in aPreviusObjects)
			{
			
				// get current level items
				var oNodes = aPreviusObjects[iPrevIndex].childNodes;
				
				// collect text nodes
				var aLevelTextNodes=[];
				
				// loop current level items
				for(var iCurrIndex=0;iCurrIndex<oNodes.length;iCurrIndex++)
				{
				
					// get item reference
					var oItem = oNodes.item(iCurrIndex);
					
					// if text node
					if(oItem.nodeName=='#text')
					{
						aLevelTextNodes.push(oItem);
					}
					else
					{
						// not text node add to current level item array
						aLevelObjects.push(oItem);
					}
				}	
				
				// loop all text nodes
				for(var iTextIndex in aLevelTextNodes)
				{
					// get item reference
					var oItem = aLevelTextNodes[iTextIndex];
					
					// search string first index
					var iFoundIndex = -1;
					
					// if text node contains search string
					if((iFoundIndex=String(oItem.nodeValue).indexOf(sText))>-1)
					{
						// loop while more instances
						while(iFoundIndex>-1)
						{
							
							// get start text node
							oItem = oItem.splitText(iFoundIndex);
							
							// create a span and insert before found text
							var oSpan =	document.createElement("SPAN");
							oSpan.style.background=sColor;
							oItem.parentNode.insertBefore(oSpan,oItem);
							
							// slice remaining text and insert to span
							var oSearchItem = oItem.splitText(sText.length);
							oSpan.appendChild(oItem);
							oItem = oSearchItem;
							
							// search on remaining text
							iFoundIndex=String(oItem.nodeValue).indexOf(sText);
						}
					}
				}
			}
			
			// set previus level item array
			aPreviusObjects = aLevelObjects;
		}
	}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


function changeWorldIcon(currImg, iImgNumber, bOver)
{
	try
	{
		var obj	= eval('WolrdImg'+(bOver ? 'Off' : 'On')+String(iImgNumber));
		if (!obj) return;
		if (obj.src=='') return;
		currImg.src	= obj.src;
	}catch(e){}
}

function winOpen(sUrl,sName,sParams)
{
	var newWin	= window.open(sUrl,sName,sParams);
}

function openMoviePopup(docID,catID,_lang,h,w,sUrl)
{
	var properties = 'height=620,width=810,left=0,top=0,addres=no,status=no,';
	var url = sUrl+"?docID="+docID+"&FolderID="+catID+"&lang="+_lang+"&res=0&pos=0&tabn=0";
	window.open( url, 'movie_popup', properties );
}
function movieNav(catid,lng)
{
	alert("hey");
}
