var searchFieldEntered = false;
function openSecWindow(URL) {
    window.open(URL,"Ext_Win","menuBar=no,HEIGHT=300,WIDTH=400,resizable,scrollbars");
}
function openEditor(editor, id, siteId) {
	//var w = window.open(editor + '=' + id + '&s=' + siteId,'oE' + id,"width=790,height=500,directories=no,location=yes,menubar=yes,scrollbars=no,status=yes,toolbar=no,resizable=yes");
	var w = window.open((editor + '=' + id + '&s=' + siteId).split('==').join('='),'oE' + id,"width=790,height=500,directories=no,location=yes,menubar=yes,scrollbars=no,status=yes,toolbar=no,resizable=yes");
	w.focus();
}
function oE(contentId, siteId) {
	openEditor(editorURL, contentId, siteId);
}
function oME(menuId, siteId) {
	openEditor(menuURL, menuId, siteId);
}
function oC(siteId, pcId, type) {
	var w = window.open(createURL + '&s=' + siteId + '&pcId=' + pcId + '&type=' + type,'oE',"width=790,height=500,directories=no,location=yes,menubar=yes,scrollbars=no,status=yes,toolbar=no,resizable=yes");
	changeCDAElt('pref' + pcId);
	w.focus();
}
function oMC(siteId) {
	openEditor(createMenuURL, '', siteId);
}
function toggleEdit() {
	var et = document.getElementById('editorToggle');
	et.className = et.className == 'editorOn' ? 'editorOff' : 'editorOn';
}
function getFullOffsetTop(elt) {
	var obj = elt;
	var result = obj.offsetTop;
	while (obj = obj.offsetParent) {
		result += obj.offsetTop;
	}
	return result;
}
function getFullOffsetLeft(elt) {
	var obj = elt;
	var result = obj.offsetLeft;
	while (obj = obj.offsetParent) {
		result += obj.offsetLeft;
	}
	return result;
}
function changeCDAElt(eltName) {
	try {
		var val = document.getElementById(eltName);
		if (val && val.style) {
			var img = document.getElementById(eltName + 'Img');
			val.style.top = getFullOffsetTop(img) + 16;
			val.style.left = getFullOffsetLeft(img) - 70;
			val.style.display = (val.style.display == 'inline') ? 'none' : 'inline';
		}
	} catch (e) {
	}
}
function replaceQueryArg(str, arg, val) {
	var result = str;
	var splitter = '&';
	var queryParts = str.split('&' + arg + '=');
	if (queryParts.length == 1) {
		splitter = '?';
		queryParts = str.split('?' + arg + '=');
	}
	if (queryParts.length == 2) {
		result = queryParts[0] + splitter + arg + '=' + val;
		var nextAmp = queryParts[1].indexOf('&');
		if (nextAmp > -1) {
			result += queryParts[1].substring(nextAmp, queryParts[1].length);
		}
	}
	return result;
}
function removeQueryArg(str, arg) {
	var result = str.split('?').join('&');
	var splitter = '&' + arg + '=';
	var queryParts = result.split(splitter);
	if (queryParts.length == 2) {
		result = queryParts[0];
		var nextAmp = queryParts[1].indexOf('&');
		if (nextAmp > -1) {
			result += queryParts[1].substring(nextAmp, queryParts[1].length);
		}
	}
	result = '?' + result.substring(1);
	return result;
}
function getOIDValue(valsToRemove) {
	var l = location.search;
	if (valsToRemove) {
		var vals = valsToRemove.split(',');
		for (var i = 0; i < vals.length; ++i) {
			l = removeQueryArg(l, vals[i]);
		}
	}
	if (l.indexOf("&x=") > -1) {
		var qStr = l.split("&x=");
		if (qStr[1].indexOf("&") > -1) {
			return qStr[0] + "&x=" + qStr[1].substring(0, qStr[1].indexOf("&")) + '&';
		} else {
			return qStr[0] + "&x=" + qStr[1] + '&';
		}
	} else if (l.indexOf("languageId=") > -1){
		return '?';
	} else if (l.indexOf("?x=") > -1) {
		return l + '&';
	}
	return "?";
}
function sendSearch(formName,searchValue, searchUrl) {
	formName.submit();
}
function setupEditor(siteId) {
	var toggleVal = 'N';
	if (document.cookie.indexOf('ileAccess') != -1) {
		var ileC = document.cookie.split('ileAccess')[1].split(';')[0];
		var ileArr = ileC.split('#' + siteId + '=');
		if (ileArr.length > 1) {
			toggleVal = ileArr[1].split('#')[0];
			var te = document.getElementById('toggleEditor');
			if (te && te.style)
				te.style.visibility = 'visible';
			var te2 = document.getElementById('toggleEditor2');
			if (te2 && te2.style)
				te2.style.visibility = 'visible';
		}
	}
	document.getElementById('editorStatus').className = 'user' + toggleVal;
}
function languageRedirect(newLang, delim, oldLang, isCDA) {
	loc = parent.location.href.split("x" + delim + oldLang);
	if (loc.length > 1) {
		parent.location.href = loc[0] + "x" + delim + newLang + loc[1];
	} else if (parent.location.href.indexOf('?') > -1) {
		parent.location.href = parent.location.href + "&x" + delim + newLang;
	} else {
		parent.location.href = parent.location.href + "?x" + delim + newLang;
	}
	if (document.form1) {
		loc = document.form1.action.split("x" + delim + oldLang);
		document.form1.action = loc[0] + "x" + delim + newLang + loc[1];
		document.form1.submit();
	}
}
function openApp(selectBox) {
	if (selectBox.selectedIndex == 0)
		return false;
	var s = selectBox.options[selectBox.selectedIndex].value.split('*');
	if (s[0] == 'N') {
		parent.location.href=s[1];
	} else {
		if (s[1].length > 11 && s[1].substring(0, 11) == "javascript:") {
			eval(s[1].substring(11, s[1].length));
		} else {
			var win=window.open(s[1], 'Ext_Win' + selectBox.selectedIndex); win.focus();
		}
	}
}
function toggleVisibility(elt) {
	if(document.getElementById(elt).style.display =='none') {
		document.getElementById(elt).style.display = 'block';
	} else {
		document.getElementById(elt).style.display = 'none';
	} 
}
function populate(dbvalue) {
	   for (var i=0; i < 5; i++) {
         if(preference.noofresults.options[i].value == dbvalue){
        	 preference.noofresults.options[i].selected=true     
         }
	   }
}
function showCurrentDate() {
	var now = new Date();
	var months = new Array(
		'Jan','Feb','Mar','Apr','May',
		'Jun','Jul','Aug','Sep','Oct',
		'Nov','Dec');
	var year = now.getYear();
	var today = 
		((now.getDate()<10) ? "0" : "") + now.getDate() + "-" +
		months[now.getMonth()] + "-" +
		((year < 1000) ? year + 1900 : year);
	document.write(today);
}
var windowProfiles = new Array();
windowProfiles[0] = '';
windowProfiles[1] = 'width=800,height=600,left=50,right=50,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes';
function openWindow(url, profile) {
	if (profile && windowProfiles[profile]) {
		var w = window.open(url, 'Ext_Win' + profile, windowProfiles[profile]);
		w.focus();
	} else {
		window.open(url,profile ? profile : "window","menuBar=yes,HEIGHT=600,WIDTH=600,resizable,scrollbars");
	}
}