var $_test_vlad = function (id, doc) 
{
	if((id)&&((typeof id == "string")||(id instanceof String))){
	if (!doc) { doc = document; }
	var ele = doc.getElementById(id);
	// workaround bug in IE and Opera 8.2 where getElementById returns wrong element
	if (ele && (ele.id != id) && doc.all) {
	ele = null;
	// get all matching elements with this id
	eles = doc.all[id];
	if (eles) {
	// if more than 1, choose first with the correct id
	if (eles.length) {
	for (var i=0; i < eles.length; i++) {
	if (eles[i].id == id) {
	ele = eles[i];
	break;
	}
	}
	// return 1 and only element
	} else { ele = eles; }
	}
	}
	return ele;
	}
	return id; // assume it's a node
}



//---- workaround for IE to correct getElementById wrong return
if (((/msie/i.test(navigator.userAgent))  || (/msie 7/i.test(navigator.userAgent))) && (!document.nativeGetElementById)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.id == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				if(document.all[id]!=null) {
				for(var i=1;i<document.all[id].length;i++)
				{
					
					if(document.all[id][i].id == id)
					{
						return document.all[id][i];
					}
				}
				}
			}
		}
		return null;
	};
}


//---- vlad.diaconu --------------
// fires a form submit running first the onsubmit function

function submitTheForm(formId)
{
	//alert('am intrat')
	var theForm = document.getElementById(formId);
	
	if(theForm)
	{
		if(typeof(theForm.onsubmit) == 'function')
		{
			//alert('da');
			if(theForm.onsubmit())
				theForm.submit();
		}
		else
		{
			//alert('nu are')
			theForm.submit();
		}
	}
	else
		return -1;
				
}
//----------------------


//-- vlad.diaconu ----------------------------
// checks first if the object with specified id exists, then if test is true executs code fragment specified in the second parameter; if test fails it executes code fragment specified in the third parameter; pass '' if you don't want anything to be executed on the false side
// if yor code affects only the object specified and its properties you can pass a fourth and fifth parameter with true value and then part of code without document.getElementById....


function checkAndExcute(objId, trueJavascriptCode, falseJavascript, trueTst, falseTst)
{
	if(document.getElementById(objId))
	{
		if(trueTst)
			eval("document.getElementById(objId)."+trueJavascriptCode);
		else
			eval(trueJavascriptCode);
		
		return true;	
	}
	else
		(!falseJavascript)
		{
			if(falseTst)
				eval("document.getElementById(objId)."+falseJavascript);
			else
				eval(falseJavascript);
				
		}
	return false;
}

//--------------------------------------
// vlad.diaconu
// -------------------------------------

function createAndAppendHelpLinkForm(savedConfNumber)
{
	
	var elementForm; 
	try {
	    elementForm = document.createElement("<form id='helpForm' action='myitinerary.php' method='POST'>");
	} catch (e) {
	    elementForm = document.createElement("form");
	    elementForm.setAttribute("id", "helpForm");
	    elementForm.setAttribute("action", "myitinerary.php");
	    elementForm.setAttribute("method", "POST");
	}
	
	document.body.appendChild(elementForm);
	
	var element; 
	try {
	    element = document.createElement("<input type='hidden' name='pas' value='3' />");
	} catch (e) {
	    element = document.createElement("input");
	    element.setAttribute("id", "3");
	    element.setAttribute("name", "pas");
	    element.setAttribute("type", "hidden");
	}
	
	document.getElementById("helpForm").appendChild(element)
	
	
	
}

// ----------------------------------
// vlad.diaconu
// ----------------------------------
function createAndAppendElement(arElementAttributes, arAttributesValues, parentElement)
{
	
}

// ----------------------------------
// vlad.diaconu
// ----------------------------------
function selectByValue(id, val)
{
	var sel = document.getElementById(id);
	for(var i = 0; i<sel.options.length; i++)
	{
		if(sel.options[i].value == val)
		{
			sel.selectedIndex = i;
			break;
		}
	}
}


// ----------------------------------
// vlad.diaconu
// ----------------------------------
function replaceForXML(str)
{
	var xmlSearch = new Array('&', '<', '>');
	var xmlReplace = new Array('&amp;', '&lt;', '&gt;')
	/*for(x in xmlSearch)
	{
		//alert(xmlSearchAndReplace[x]);
		str = str.replace("/"+xmlSearch[x]+"/g", xmlReplace[x]);
	}*/
	
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	
	return str;
}



function addLoadEvent(func) 
{
	var oldonload = (typeof window.onload == 'function')?window.onload:null;
	window.onload = function() {
		if(oldonload != null && typeof oldonload == 'function') oldonload();
		eval(func);
	}
}

function addOnScrollWindowEvent(func) 
{
	var oldscroll = (typeof window.onscroll == 'function')?window.onscroll:null;
	window.onscroll = function() 
	{
		if(oldscroll != null && typeof oldscroll == 'function') oldscroll();
		eval(func);
	}
}

function addOnResizeWindowEvent(func) 
{
	var oldresize = (typeof window.onresize == 'function') ? window.onresize : null;
	window.onresize = function() 
	{
		if(oldresize != null && typeof oldresize == 'function') oldresize();
		eval(func);
	}
}

function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;
}

function getIdValue(id)
{
	if(document.getElementById(id))
	{
		return document.getElementById(id).value;
	}
	//alert("INVALID ELEMENT ID: " + id);
}

function setIdValue(id, val)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).value = val;
	}
	else
	{
		alert("INVALID ELEMENT ID: " + id);	
	}
	
}

function element(id)
{
	return document.getElementById(id);
}

function loadOnClick(element, code, overwrite) 
{
	var objElement = document.getElementById(element);
	var oldEvent = (objElement.onclick != 'undefined')? objElement.onclick:null;
	
	//code.replace(/this./g, 'document.getElementById('+element+').');
	
	//alert(code);
	
	objElement.onclick = function() 
	{
		if(!overwrite)
		{
			if(oldEvent != null && typeof oldEveznt == 'function') oldEvent();
		}
		
		eval(code);
	}
}

function loadOnChange(element, code, overwrite) 
{
	var objElement = document.getElementById(element);
	var oldEvent = (objElement.onchange != 'undefined')? objElement.onchange : null;
	
	//code.replace(/this./g, 'document.getElementById('+element+').');
	
	objElement.onchange = function() 
	{
		if(!overwrite)
		{
			//alert('test');
			if(oldEvent != null && typeof oldEvent == 'function') 
			{
				//alert('executam codul vechi');
				oldEvent();
				//alert('am terminat de excutat codul vechi');
			}
		}
		
		eval(code);
	}
}



function loadOnBlur(element, code) 
{
	var objElement = document.getElementById(element);
	var oldEvent = (objElement.onblur != 'undefined')? objElement.onblur:null;
	
	objElement.onblur = function() 
	{
		if(oldEvent != null && typeof oldEvent == 'function') oldEvent();
		eval(code);
	}
}






//************************************************************
// adi
//************************************************************


function removeAllOptions(from){
	if(typeof(from)!="object") from=document.getElementById(from);
	if(!hasOptions(from)){return;}
	var nr=from.options.length-1;
	for(var i=nr;i>=0;i--){
		from.options[i] = null;
	}
	from.selectedIndex = -1;
}

function removeAllOptionsId(fromid,msg){
	var from=document.getElementById(fromid);
	if(!hasOptions(from)){return;}
	var nr=from.options.length-1;
	for(var i=nr;i>=0;i--){
		from.options[i] = null;
	}
	from.selectedIndex = -1;
	addOption(from,msg,0,'');
}
function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}
function addOption(obj,text,value,selected,color){
	if(obj!=null && obj.options!=null){
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		if(color!='undef'){
			obj.options[obj.options.length-1].style.color=color;
		}
	}
}
function evaluateJS(id){
	var e=document.getElementById(id);
	if(e){
		var js=e.getElementsByTagName("script");
		for(var i=0;i<js.length;i++){
			eval(js[i].innerHTML);
		}
	}
}

function showHideDiv(ename,flag){
	var e=document.getElementById(ename);
	if(e){ if(!parseInt(flag)) e.style.display='none';else e.style.display='';}
}

function trimInputs() {		
	for (i = 0; i < document.forms.length; i++) {
		for (j = 0; j < document.forms[i].elements.length; j ++) {				
			if (document.forms[i].elements[j].type == "text" || document.forms[i].elements[j].type == "textarea") {				
				if (document.forms[i].elements[j].addEventListener) {
					document.forms[i].elements[j].addEventListener('blur',
						function (e) {																		
							value = this.value;
							while (value.substring(0,1) == ' ') {
								value = value.substring(1, value.length);
							}
							while (value.substring(value.length-1, value.length) == ' ') {
								value = value.substring(0,value.length-1);
							}
							this.value = value;
						}
					,'true');
				}
				else {
					if ( document.forms[i].elements[j].attachEvent ) {
						document.forms[i].elements[j].attachEvent('onblur', function (e) {																		
							value = e.srcElement.value;
							while (value.substring(0,1) == ' ') {
								value = value.substring(1, value.length);
							}
							while (value.substring(value.length-1, value.length) == ' ') {
								value = value.substring(0,value.length-1);
							}
							e.srcElement.value = value;
						});								
					}
				}
			}				
		}			
	}
}

function registerFunction(id,func,event)
{
	var elem=document.getElementById(id);
	if(elem){
		if(typeof(func)!='function') return -2;
		eval("elem."+event+"=function(){ return "+func+"()};");
		if(elem.attachEvent){
			elem.attachEvent(event,func);
		}
	}
	else return -1;
}

function customPeriodOverlap(frmname,periodTableID,prefix){
	
	var fromarray=Array();
	var toarray=Array();
	var myDate1=new Date();
	var myDate2=new Date();
	if(periodTableID == 'undefined') periodTableID='mainperiods';
	if(prefix == 'undefined') prefix='';
	var elem=document.getElementById(periodTableID);

	if(elem){
		var nr=elem.rows.length;
		for(var i=1;i<nr;i++){
			var ide=elem.rows[i].cells[0].id;
			var id=parseInt(ide.substring(prefix.length+6),10);
			for(var j=1;j<4;j++){
				eval("var elem1_"+j+"=parseInt(document."+frmname+"."+prefix+"a"+id+"date"+j+".value,10)");
				eval("var elem2_"+j+"=parseInt(document."+frmname+"."+prefix+"d"+id+"date"+j+".value,10)");
			}
			myDate1.setFullYear(elem1_3,(elem1_1-1),elem1_2);
			myDate2.setFullYear(elem2_3,(elem2_1-1),elem2_2)
			fromarray.push(myDate1.getTime());
			toarray.push(myDate2.getTime());
		}
		//overlap test;

		var sortedArray=Array();
		sortedArray=aSort(fromarray);
		for(var a=0;a<sortedArray.length;a++){
			if(a==0) continue;
			if(sortedArray[a][1]-toarray[sortedArray[a-1][0]]<=0 || sortedArray[a][1]<=toarray[sortedArray[a-1][0]]){
				return 1;
			}
		}
		return 0;
	}
	else alert('js error on mainperiods table');
}

function customPeriodOverlap1(frmname,periodTableID,prefix,compareDateFrom,compareDateTo){
	
	var fromarray=Array();
	var toarray=Array();
	var myDate1=new Date();
	var myDate2=new Date();
	if(periodTableID == 'undefined') periodTableID='mainperiods';
	if(prefix == 'undefined') prefix='';
	var elem=document.getElementById(periodTableID);
	var myCompareDateFrom = compareDateFrom.getTime();
	var myCompareDateTo = compareDateTo.getTime();
	
	if(elem){
		var nr=elem.rows.length;
		for(var i=1;i<nr;i++){
			var ide=elem.rows[i].cells[0].id;
			var id=parseInt(ide.substring(prefix.length+6),10);
			for(var j=1;j<4;j++){
				eval("var elem1_"+j+"=parseInt(document."+frmname+"."+prefix+"a"+id+"date"+j+".value,10)");
				eval("var elem2_"+j+"=parseInt(document."+frmname+"."+prefix+"d"+id+"date"+j+".value,10)");
			}
			myDate1.setFullYear(elem1_3,(elem1_1-1),elem1_2);
			myDate2.setFullYear(elem2_3,(elem2_1-1),elem2_2);
			
			if(myCompareDateFrom==myDate1.getTime()) {
				fromarray.push(myDate1.getTime());
			}
			
			if(myCompareDateTo!=myDate2.getTime()) {
				toarray.push(myDate2.getTime());
			}
		}
		
		
		//overlap test;

		var sortedArray=Array();
		sortedArray=aSort(fromarray);
		if(sortedArray.length>=2) {
			return 1;
		}
		return 0;
	}
	else alert('js error on mainperiods table');
}



function arrHasDupes( A ) {                          // finds any duplicate array elements using the fewest possible comparison
	var i, j, n;
	
	A.splice(0, 1);
	n=A.length;
	for (i=0; i<n; i++) {   
		for (j=i+1; j<n; j++) {
			if (trim(A[i])==trim(A[j])) 
			{
				return A[i];
			}
		}	
	}
	return 'no';
}

function arrHasDupesTemp( A ) {                          // finds any duplicate array elements using the fewest possible comparison
	var i, j, n;
	
	
	n=A.length;
	for (i=0; i<n; i++) {   
		for (j=i+1; j<n; j++) {
			if (trim(A[i])==trim(A[j])) 
			{
				return A[i];
			}
		}	
	}
	return 'no';
}


//************************************************************
// eof adi
//************************************************************

function getInputTopPosition(inputObj)
{

  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}

function getInputLeftPosition(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}


//Adds loading field when the Ajax call is made
//Params: fieldId (array - the ids of fields that needs to be updated)
//className (string - the class name for the select - I supposed that they will have all the same class)
//disabled - (boolean  - if true the select will be disabled during the Ajax call)
//option - (string - what will be disaplyed to the user during the ajax call)
//Usage - (myVar = new Loading(new Array('field1','field2'),'myClass','myStyle','true','------loading..........--------'); myVar.display();)
function Loading(fieldId,className,style,disabled,option) {
	
	this.className  = className;
	this.style  = style;
	this.disabled = disabled;
	this.option = option;
	this.fieldId = fieldId;
	
	if (this.disabled=='false') {
		this.disabled = '';
	}

}	

Loading.prototype.display = function() 
{
	for (var i = 0; i < this.fieldId.length; i++) 
	{
		document.getElementById(this.fieldId[i]).innerHTML = '<select class="'+this.className+'" style="'+this.style+'" '+this.disabled+'><option>'+this.option+'</option></select>';			
	}
}



/**
 * Get the x,y scrolling position
 */
function getScrollXY() 
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

/**
 * Resize a absolute div and move it to the center of the 
 * client area
 */
function moveDivToCenter(divID, divWidth, divHeight)
{
	if(element(divID))
	{
		if(divWidth == undefined) divWidth = parseInt(element(divID).style.width, 10);
		if(divHeight == undefined) divHeight = parseInt(element(divID).style.height, 10);
		
		var scrollDetails = getScrollXY();
		var visibleArea = getClientVisibleArea();
		
		if (visibleArea[1] < divHeight) {
			divHeight = visibleArea[1] - 45;
		}
	    var centerWidth = (visibleArea[0] - divWidth) / 2;
	    var centerHeight = (visibleArea[1] - divHeight) / 2;
	    
		    
	    // asdjust to the center where the user has scrolled
	    if(scrollDetails[1] > (centerHeight / 2))
	    	centerHeight += (scrollDetails[1] - (centerHeight / 2) );
	    	
	    if(scrollDetails[0] > (centerWidth / 2))
	    	centerWidth += (scrollDetails[0] - (centerWidth / 2) );
	    	
	    
	    element(divID).style.width = divWidth + 'px';
	    element(divID).style.height = divHeight + 'px';
	    element(divID).style.left = centerWidth;
	    element(divID).style.top = centerHeight;
	    element(divID).style.display = '';
	}
}


function getClientVisibleArea()
{
	// Firefox
	if (window.innerHeight && window.innerWidth) 
	{
		return new Array(window.innerWidth, window.innerHeight);
	} 
	// all but Explorer Mac
	else if (document.body.clientHeight && document.body.clientWidth)
	{ 
		return new Array(document.body.clientWidth, document.body.clientHeight);
	}
	// works in Explorer 6 Strict, Mozilla (not FF) and Safari
	else if (document.documentElement.clientHeight && document.documentElement.clientWidth)
	{ 
		return new Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
  	}
	return new Array(window.screen.width, window.screen.height);
}


function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) 
	{// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else 
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

/**
 * get the size of the client area (the whole page)
 */
function getClientSize()
{
	if( window.innerHeight && window.scrollMaxY ) // Firefox 
	{
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
	{
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{ 
		pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
		pageHeight = document.body.offsetHeight + document.body.offsetTop; 
	}
	return [pageWidth, pageHeight];
}

/**
 * Show / hide a element
 */
function displayDiv(divID, show)
{
	if(element(divID))
	{
		element(divID).style.display = (show == true ? '' : 'none');
	}
}

/**
 * Diable the page (grey, transparent background)
 * the user cannot click on anything
 */
function disablePageTransparnet(divName)
{
	divName = (divName == undefined ? 'disabledPageContainerUI' : divName);
	//alert(divName);
	if(element(divName))
	{
		var clientSize = getClientSize();
		//element('disabledPageContainerUI').style.width = clientSize[0];
		element(divName).style.height = clientSize[1];
		
		var htmlDiv = '';
		
		if(clientSize[1] <= 2048)
		{
			htmlDiv = getTranslucentDiv(clientSize[1], 0);
		}
		else
		{
			for(var idx=0; idx<clientSize[1]; idx+=2048)
			{
				var diff = clientSize[1] - idx;
				var heightTmp = (diff > 2048 ? 2048 : diff);
				htmlDiv += getTranslucentDiv(heightTmp, idx);
			}
		}
		
		element(divName).innerHTML = htmlDiv;
		//element('disabledPageContainerUI').contentWindow.document.body.innerHTML = htmlDiv;
		element(divName).style.display = '';
	}
}

/**
 * Close the modal pop up div
 */
function closeDivPopUp(divDisabledPage, divContent)
{
	divDisabledPage = (divDisabledPage == undefined ? 'disabledPageContainerUI' : divDisabledPage);
	divContent = (divContent == undefined ? 'blockUIPopupContent' : divContent);
	
	//displayDiv('blockUIPopupContent', false);
	//displayDiv('disabledPageContainerUI', false);
	displayDiv(divContent, false);
	displayDiv(divDisabledPage, false);
	needToConfirm = true;
	if(typeof closeCalendar  == "function")
	{
		closeCalendar();
	}
}


/**
 * Open a modal div pop up in the center of the client area
 * the rest of the page will be disabled with transparent grey background
 */
function openDivPopUp(width, height, divDisabledPage, divContent)
{
	var marginPopupWidth = 120;
	var marginPopupHeight = 80;
	var visibleArea = getClientVisibleArea();
	// leave 20 px
	var maxWidth = (visibleArea[0] > marginPopupWidth ? visibleArea[0] - marginPopupWidth : visibleArea[0]);
	var maxHeight = (visibleArea[1] > marginPopupHeight ? visibleArea[1] - marginPopupHeight : visibleArea[1]);
	
	width = (width > maxWidth ? maxWidth : width);
	height = (height > maxHeight ? maxHeight : height);
	
	divDisabledPage = (divDisabledPage == undefined ? 'disabledPageContainerUI' : divDisabledPage);
	divContent = (divContent == undefined ? 'blockUIPopupContent' : divContent);
	disablePageTransparnet(divDisabledPage);
	
	//if(element('blockUIPopupContent')) moveDivToCenter('blockUIPopupContent', width, height);
	if(element(divContent)) moveDivToCenter(divContent, width, height);
}


function divPopUpResize(divContentId)
{
	if(element(divContentId))
	{
		var divWidth = parseInt(element(divContentId).style.width, 10);
		var divHeigth = parseInt(element(divContentId).style.height, 10);
		
		divWidth = (divWidth < 300 ? 600 : divWidth);
		divHeigth = (divHeigth < 200 ? 400 : divHeigth);
			
		if(!isNaN(divWidth) && !isNaN(divHeigth))
		{
			var marginPopupWidth = 120;
			var marginPopupHeight = 80;

			var visibleArea = getClientVisibleArea();
			// leave 20 px
			var maxWidth = (visibleArea[0] > marginPopupWidth ? visibleArea[0] - marginPopupWidth : visibleArea[0]);
			var maxHeight = (visibleArea[1] > marginPopupHeight ? visibleArea[1] - marginPopupHeight : visibleArea[1]);
			
			
			element(divContentId).style.width = (divWidth > maxWidth ? maxWidth : divWidth);
			element(divContentId).style.height = (divHeigth > maxHeight ? maxHeight : divHeigth);
			
		}
	}
}


function divPopUpResizeAll()
{
	if(element('blockUIPopupContent') && element('blockUIPopupContent').style.display != 'none')
	{
		 divPopUpResize('blockUIPopupContent');
	}
	if(element('blockGroupsUIPopupContent') && element('blockGroupsUIPopupContent').style.display != 'none')
	{
		divPopUpResize('blockGroupsUIPopupContent');
	}
}

function divPopupRearrange()
{
	if(element('blockUIPopupContent') && element('blockUIPopupContent').style.display != 'none')
	{
		moveDivToCenter('blockUIPopupContent');
	}
	if(element('blockGroupsUIPopupContent') && element('blockGroupsUIPopupContent').style.display != 'none')
	{
		moveDivToCenter('blockGroupsUIPopupContent');
	}
}



/**
 * Set the content of the modal div with the rest of the page disabled, transparent, grey
 */
function setContentDivPopUp(html, divContent)
{
	divContent = (divContent == undefined ? 'blockUIPopupContent' : divContent);
	if(element(divContent))
	{
		element(divContent).innerHTML = html;
		evaluateJS(divContent);
	}
}

/**
 * Get the transparent iframes to fill the page
 * BUG IN IE: a transparent element can have maximum height of 2048 pixels
 */
function getTranslucentDiv(height, topPosition)
{
	//var divHTML = '<div ';
	var divHTML = '<iframe ';
	divHTML += 'frameborder="text/html" hspace="0" marginheight="0" marginwidth="0" scrolling="No"  vspace="0" bgcolor="black" ';
	divHTML += 'style="background-color: black; width: 100%; height: '+ height +'; position: absolute; left: 0px; top: '+ topPosition +'px;';
	divHTML += 'filter:alpha(opacity=50);-moz-opacity:0.5;opacity:0.5; overflow: hidden;';
	divHTML += 'margin: 0px; padding: 0px; border: 0px;" ';
	divHTML += 'onclick="return false" onmousedown="return false" onmousemove="return false" onmouseup="return false" ';
	divHTML += 'ondblclick="return false">&nbsp;';
	divHTML += '</iframe>';
	//divHTML += '</div>';
	return divHTML;
}


function getLoadingPopUp(message, showAnimation, returnContent, divDisabledPage, divContent,showCloseButton)
{
	divDisabledPage = (divDisabledPage == undefined ? 'disabledPageContainerUI' : divDisabledPage);
	divContent = (divContent == undefined ? 'blockUIPopupContent' : divContent);
	var loading = '<table border="0" width="100%" height="100%">';
	loading += '<tr><td align="center" valign="middle" height="100%">';
	if(showAnimation == true)
	{
		loading += '<img src="'+ JS_SITE_URL +'/images/gears.gif" border=0 />';
	}
	
	loading += '<br />'+message;
	loading += '</td></tr>';
	loading += '<tr><td align="right" height="40">';
	if(showCloseButton==true || showCloseButton == undefined ) {
		loading += '<button type="button" style="border: medium none ; background-color: transparent; cursor: pointer; text-decoration: none;" ';
		loading += 'onclick="closeDivPopUp(\''+ divDisabledPage +'\',\''+ divContent +'\');"><img ';
		loading += 'src="'+ JS_SITE_URL +'/new_button.php?height=20&verspace=7&text=CLOSE&fromcolor=7FB7C6&tocolor=008597&btmcolor=0498AB&height=23&fontsize=8&horspace=20" ';
		loading += 'align="absmiddle" border="0" hspace="0" vspace="0"></button>';
	}
	loading += '<td></tr></table>';
	if(returnContent == true) return loading;
	
	setContentDivPopUp(loading, divContent);
}

/*
* @author: gus 26.11.2008
* selects innerhtml content of a specified id's html element
*/ 

function fnSelect(objId) {
	fnDeSelect();
	if (document.selection) {
	var range = document.body.createTextRange();
	        range.moveToElementText(document.getElementById(objId));
	range.select();
	}
	else if (window.getSelection) {
	var range = document.createRange();
	range.selectNode(document.getElementById(objId));
	window.getSelection().addRange(range);
	}
}
	
function fnDeSelect() {
	if (document.selection) document.selection.empty(); 
	else if (window.getSelection)
            window.getSelection().removeAllRanges();
}



function validateEmailAddressString(emailString)
{
	if(emailString.indexOf(' ') != -1) return false;
	if(emailString.indexOf('=') != -1) return false;
	if(emailString.indexOf(',') != -1) return false;
	
	if(emailString.indexOf('@') == -1) return false;
	if(emailString.indexOf('@') != emailString.lastIndexOf('@')) return false;
	
	if(emailString.indexOf('.') == -1) return false;
	
	
	if(( emailString.indexOf('@') > 0 && 
		 emailString.indexOf('@') + 1 < emailString.lastIndexOf('.') && 
		 emailString.lastIndexOf('.') < emailString.length-2 && 
		 (emailString.length - emailString.lastIndexOf('.')) <= 7) == false)
	{
		return false;   	
	}
	
	return true;
}


function _addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function _removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
var loadingDivContent='<div align="center" valign="top" name="cautare" id="cautare" style="position:absolute;left:0px;top:0px;width:100%;height:100%;background-color:#FFFFFF;z-index:50;"><table height="100%"><tr><td height="100%"><table height="300px" width="360px" style="border: #FF7300 1px solid;background-color:#FFFFFF;"><tr><td height="100%" valign="middle" align="center"><font style="COLOR: #FF8A31;FONT-FAMILY: Verdana, Tahoma, Arial, Helvetica; FONT-SIZE: 14px;FONT-WEIGHT: bold;"><img src="../images/animatie_moment_please.gif" border="0"><br><br><img src="../images/animatie_cautare.gif" border="0"><br><br><img src="../images/weareprocessing.gif" border="0"><br><img src="../images/noback.gif" border="0"><br><img src="../images/take.gif" border="0"><br><br></font></td></tr></table></td></tr></table></div>';

function openHealthSafetyCompliancePopup(serviceType, serviceId, validation, switchId) {
	
	openDivPopUp(945, 500);
	getLoadingPopUp('Loading', true, false);
	document.getElementById('healthSafetyComplianceDiv').innerHTML = loadingDivContent;
	xajax_loadHealthSafetyCompliance(serviceType, serviceId, 'blockUIPopupContent', true, '', false, validation, switchId);
}

function closeHealthSafetyCompliancePopup(serviceType, serviceId, tabbed, readonly, extranet, validation) {
	if (document.getElementById('blockUIPopupContent')) {
		closeDivPopUp();
		tabbed = false;
		readonly = 'disabled';
	}
	var healthSafetyCompliance = [];
	document.getElementById('healthSafetyComplianceDiv').innerHTML = '<div style="text-align:center"><img src="' + JS_SITE_URL + '/images/gears.gif" border=0 /><br />Loading</div>';	
	xajax_loadHealthSafetyCompliance(serviceType, serviceId, 'healthSafetyComplianceDiv', tabbed, readonly, extranet, validation);
}

function switchStep(step, noStepts) {
	
	var atributeName = 'class';
	
	if (BrowserDetect.browser == 'Explorer') {
		var atributeName = 'className';
	}
	
	for (var i = 1; i <= noStepts; i++) {
		if (i == step) {
			document.getElementById('liStep' + i).setAttribute(atributeName, "tabSelected");
			document.getElementById('categoryStep' + i).style.display = '';
		} else {
			document.getElementById('liStep' + i).setAttribute(atributeName, "tab");
			document.getElementById('categoryStep' + i).style.display = 'none';
		}
	}
}
//gus 25.09.2009
//js function for health$safety compliance
function delete_HSC_Doc(code) {
	
	if(confirm("Are you sure that you want to delete ?"))
	{
		document.getElementById('doc_HSC_SaveStatus').innerHTML='';	
		delete_HSC_Document(code);	
	}
}
//gus 25.09.2009
//js function for health$safety compliance
function delete_HSC_Document(noteId) { 
	
	var url=JS_SITE_URL + "/ajax/fillsel.php?id=" + Math.random() + "&deleteDocNote=" + noteId
	xmlHttp=GetXmlHttpObject(stateChanged_HSC_delDoc)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}
//gus 25.09.2009
//js function for health$safety compliance
function stateChanged_HSC_delDoc() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var responseText = xmlHttp.responseText;
		var retVars = responseText.split("###");
		var notesTable = document.getElementById('Doc_HSC_Table');
		retVars[0] = retVars[0].replace('\n', '')
		retVars[0] = retVars[0].replace('\r', '')
		myId='doc_HSC_'+retVars[0]
		var rowId = document.getElementById(myId).rowIndex;
		
		notesTable.tBodies[0].deleteRow(rowId);
		//renumerotam randurile
		nrRows = notesTable.tBodies[0].rows.length;
		if(nrRows >1)
		{
			for(i=1; i< nrRows; i++)
			{
				notesTable.tBodies[0].rows[i].cells[0].innerHTML = i+'.';
			}
		} else {//add no note
		var newrow = notesTable.insertRow(1);
			newrow.id = 'doc_HSC_x';
		var mycell = newrow.insertCell(0);			
			mycell.colSpan = 3;
			mycell.innerHTML = '<div class="error">There is no Document uploaded.</div>'			
		}
		document.getElementById('doc_HSC_SaveStatus').innerHTML ='The information was deleted successfully.';
	} 
}
function GetXmlHttpObject(handler)
{ 

var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("Do not use Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
function highlightLabel(id, newColor) {
	
	document.getElementById(id).style.color = newColor;
}

function saveSafetyCompliance(serviceType, serviceId, data, tabbed, readonly, extranet, validation) {
	
	var ok = true;	
	healthSafetyCompliance['liabilityInsuranceExpiryDate'] = document.getElementById('liabilityInsuranceExpiryDate').value;
	healthSafetyCompliance['fireRiskExpiryDate'] = document.getElementById('fireRiskExpiryDate').value;
	
	if (validation)
		ok = healthSafetyComplianceValidation();
		
	if (ok) {
		xajax_saveHealthSafetyCompliance(serviceType, serviceId, data, extranet, tabbed, readonly, validation);
	}
}

//gus, ie indexOf fix
if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}

function setHealthSafetyComplianceItem(field, fieldType, fieldValue) {
	
	switch (fieldType) {
		case 'input':
		case 'radio':
			healthSafetyCompliance[field] = fieldValue;
			break;
		case 'check':
		var checked = healthSafetyCompliance[field];
			if (checked) {
				checked = checked.split(',');
				var pos = checked.indexOf(fieldValue);
				if (pos >= 0) 	{
					checked.splice(pos, 1);
				} else {
					checked.push(fieldValue);
				}
			} else {
				checked = new Array(fieldValue);
			}				
			healthSafetyCompliance[field] = checked.toString();			
			break;
	}
}

function showSpecificCustomerSelect(selectedValue) {
	if(selectedValue==3) {
		document.getElementById('subCustomers').style.display = '';
	} else {
		document.getElementById('subCustomers').style.display = 'none';
	}
}

	
//vlad.diaconu 
// 14.08.2008

// Returns true if the passed value is found in the
// array. Returns false if it is not.

Array.prototype.inArray = function (value, caseSensitive, count)
{
	var i;
	if(count == true)
		var numberOfValues = 0;
	
	for (i = 0; i < this.length; i++) 
	{
		if(caseSensitive)
		{
			if (this[i].toLowerCase() == value.toLowerCase()) 
			{
				if(count == true)
					numberOfValues++;
				else
					return true;
			}
		}
		else
		{
			if (this[i] == value) 
			{
				if(count == true)
					numberOfValues++;
				else
					return true;
			}
		}
	}
	if(count == true)
		return numberOfValues;
	else
		return false;
}


Array.prototype.compare = function (testArr) 
{
    if (this.length != testArr.length) return false;
    for (var i = 0; i < testArr.length; i++) {
        if (this[i].compare) { 
            if (!this[i].compare(testArr[i])) return false;
        }
        if (this[i] !== testArr[i]) return false;
    }
    return true;
}

Array.prototype.pushElement = function (elem)
{
	if(!isArray(elem))
	{
		this[this.length] = elem;
		return;	
	}
	else
	{
		this[this.length] = new Array();
		for(var i = 0; i < elem.length; i++)
		{
			this[parseInt(this.length, 10) - 1].pushElement(elem[i]);
		}
	}
}

//returns true is it is an array

function isArray(obj) 
{
	if(!obj)
		return false;
		
	if (obj.constructor.toString().indexOf('Array') == -1)
		return false;
	else
		return true;
}

// vlad.diaconu
// 30.09.2008
// format number and return string 

function numberFormat(nr, digits, decSep, thouSep)
{
	if(typeof digits == "undefined")
		digits = 2;
		
	if(typeof decSep == "undefined")
		decSep = '.';
		
	if(typeof thouSep == "undefined")
		thouSep = ',';
		
	nrStr = nr.toFixed(digits);
	
	nrStr += '';
	
	x = nrStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? decSep + x[1] : '';

	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + thouSep + '$2');
	}
	return x1 + x2;

}


// vlad.diaconu - received from florin.langa
// 08.10.2008
// trim function

 function trim(str)
 {
   s = str.replace(/^(\s)*/, '');
   s = s.replace(/(\s)*$/, '');
   return s;
 }



function eatenter(e, codeToExecute) 
{
	if (window.event) { // IE
		if (e.keyCode == 13) {
			//override default value so you know it was caused by input
			if(codeToExecute != undefined) eval(codeToExecute);
			return false;
		}
	}
	else if(e.which == 13) { // Netscape/Firefox/Opera
		if(codeToExecute != undefined) eval(codeToExecute);
		return false;
	}
}



    function isNumber (InString)  {
        if(InString.length==0) return (false);
        var RefString="1234567890";
        for (Count=0; Count < InString.length; Count++)  {
            TempChar= InString.substring (Count, Count+1);
            if (RefString.indexOf (TempChar, 0)==-1)  
                return (false);
        }
        return (true);
   }





function gbLoadGroupBookingDetails(formName, bookingCode, tableName)
{
	if(element('servCode')) element('servCode').value = bookingCode; 
	if(element('bookingTable')) element('bookingTable').value = tableName; 
	if(element('isGroupBookingFlag')) element('isGroupBookingFlag').value = 1; 
	element(formName).submit();
}


// puco - on window scrool
addOnScrollWindowEvent("divPopupRearrange();");
addOnResizeWindowEvent("divPopUpResizeAll();");
addOnResizeWindowEvent("divPopupRearrange();");


// vlad.diaconu
// 10.04.2009
// copied here this function from other places to avoid multiple declarations

function checkEmail(id)
{
	if (/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i.test(document.getElementById(id).value))
	return (true);
	return (false);
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();