function openNewWindow(url,name,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	properties = "width="+windowWidth+",height="+windowHeight+",noresize,scrollbars=yes,top="+mytop+",left="+myleft;
	focusWindow = window.open(url,name,properties);
	focusWindow.focus();
}


function validateSearchFieldsPage(form)
{
	/*var form = window.document.search_form;*/
	if (form.keyword.value.length < 3) {
		alert('Va rugam sa introduceti minim 3 caractere!');
		return false;
	}
	
	if (form.keyword.value == 'cauta in site') {
		alert('Va rugam sa introduceti minim 3 caractere');
		return false;
	}
	
	return true;
}
function getURL(mode, page, params)
{
	host='http://damfis.ro';
	if (page == "")
		return host + (!mode ? '/index.php' : '/') + (params && params != '' ? (params.substr(0, 1) != '#' ? '&' : '') + params : '');
	
	return host + (!mode ? '/index.php?page=' : '') + (mode ? '/' : '') + page + (mode ? '.html' : '') + (params && params != '' ? (params.substr(0, 1) != '#' ? '&' : '') + params : '');
}



var popupLinkConfig = new Array;

popupLinkConfig["popup"]    = new Array ( "compara", "width=850,height=600,scrollbars=yes,resizable=yes,status=no,toolbar=no");
popupLinkConfig["bigimage"]    = new Array ( "bigimage", "width=520,height=532,scrollbars=yes,resizable=yes,status=no,toolbar=no");


// ==========================================================================
window.onload = initPage;  
// Note: Make sure that no other javscripts assign a fuction to window.onload
// There can be only one function tied to window.onload at a time.

function initPage() {
  initPopupLinks();
  // place here any other code you wish to run when the page loads.
}

function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}




function loadAjaxData(elementId, url, refreshfields)
{ 
	var req = null; 

	/*document.getElementById(elementId).innerHTML = "<div style='height: 300px;'>Se incarca...</div>";*/

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
			req.overrideMimeType('text/html');
	} 
	else 
	if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	req.onreadystatechange = function() { 
		/*document.getElementById(elementId).innerHTML = "<div style='height: 300px;'>Waiting for server...</div>";*/
		if (req.readyState == 4) {
			if (req.status == 200) {
				document.getElementById(elementId).innerHTML = req.responseText + '';
				if (refreshfields)
					refreshElements(refreshfields);
			}
			else
				document.getElementById(elementId).innerHTML = "<div style='height: 300px;'>Eroare la incarcare (code " + req.status + " " + req.statusText + ")<br/>URL: " + url +"</div>";
		} 
	}; 
	
	req.open("GET", url, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; Charset=ISO-8859-1"); 
	req.send(null); 
} 


function loadAjaxOptions(elementId, url, autoSelect, message)
{ 
	var req = null; 

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
			req.overrideMimeType('text/html');
	} 
	else 
	if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	req.onreadystatechange = function() { 
		if (req.readyState == 4) {
			if (req.status == 200) {
				var optionArr = req.responseText.split(";");
				var select = document.getElementById(elementId);
				var options = select.options;
				var cnt = options.length;
				var cnt1 = 0;
				//optGroup = undefined;
				
				if (req.responseText == '') {
					select.disabled = true;
					if (message != undefined)
						alert(message);
					return;
				}
				
				if (getBrowser() == 'mozilla') {
					var groups = select.getElementsByTagName('optgroup');
					for (var i = groups.length - 1; i >= 0; i--) {
						var oOptions = groups[i].getElementsByTagName('option');
						for (var j = oOptions.length - 1; j >= 0; j--)
							oOptions[j] = null;
						
						select.removeChild(groups[i]);
						//groups[i] = null;
					}
				}
				else {
					var groups = select.getElementsByTagName('optgroup');
					for (var i = groups.length - 1; i >= 0; i--) {
						select.removeChild(groups[i]);
					}
				}
				
				for (var i = 0; i < optionArr.length; i++) {
					if (optionArr[i] == '')
						break;
					var oa = optionArr[i].split(',');
					
					if (oa[0] == 'optgroup') {
						var optGroup = document.createElement('optgroup');
						optGroup.label = oa[1];
						select.appendChild(optGroup);
						continue;
					}
					
					if (getBrowser() == 'mozilla') {
						if (optGroup != undefined) {
							var option = new Option(oa[1], oa[0]);
							optGroup.appendChild(option);
						}
						else
							options[i] = new Option(oa[1], oa[0]);
					}
					else
						options[i] = new Option(oa[1], oa[0]);
					
					cnt1++;
				}
				
				for (i = cnt; i >= cnt1; i--) 
					options[i] = null;
				
				if (autoSelect)
					select.selectedIndex = (options.length > 2 ? 0 : 1);
				select.disabled = false;
			}
		} 
	}; 
	
	req.open("GET", url, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
} 


function loadAjaxValue(elementId, url)
{ 
	var req = null; 

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
			req.overrideMimeType('text/html');
	} 
	else 
	if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}


	req.onreadystatechange = function() { 
		if (req.readyState == 4) {
			if (req.status == 200) {
				document.getElementById(elementId).value = req.responseText;
				//alert(elementId + '='+document.getElementById(elementId).value);
			}
		} 
	}; 
	
	req.open("GET", url, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}


function execAjax(url)
{ 
	var req = null; 

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
			req.overrideMimeType('text/html');
	} 
	else 
	if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}


	req.onreadystatechange = function() { 
		//alert(req.readyState + ' / '  + req.status);
		
		if (req.readyState == 4) {
			if (req.status == 200) {
				//document.getElementById(elementId).value = req.responseText;
				//alert(elementId + '='+document.getElementById(elementId).value);
			}
		} 
	}; 
	
	//alert(url);
	
	req.open("GET", url, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
} 


function sendAjaxForm(form, url, msgId, refreshfields)
{ 
	var req = null; 
	
	document.getElementById(msgId).innerHTML = "Se trimit datele...";

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) 
			req.overrideMimeType('text/html');
	} 
	else 
	if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	req.onreadystatechange = function() {
		document.getElementById(msgId).innerHTML = "Waiting for server...";
		if (req.readyState == 4) {
			if (req.status == 200) {
				document.getElementById(msgId).innerHTML = req.responseText;
				if (refreshfields)
					refreshElements(refreshfields);
			}
			else
				document.getElementById(msgId).innerHTML="Eroare la incarcare (code " + req.status + " " + req.statusText + ")";
		}
	}; 
	
	req.open("POST", url, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(formData2QueryString(form)); 
}


function refreshContent(element, url, timeout)
{
	intId = window.setInterval('doRefreshContent()', timeout, element, url);
}


function doRefreshContent(element, url)
{
	window.clearInterval(intId);
	loadAjaxData(element, url);
	intId = -1;
}


function refreshElements(fields)
{
	if (!fields)
		return;
	
	for (var i = 0; i < fields.length; i++)
		if (fields[i]) {
			if (fields[i]['float'])
				fields[i]['element'].innerHTML = '';
			else
				loadAjaxData(fields[i]['element'], fields[i]['url']);
		}
}


////////////////////////////////////////////////////////
/*
 * Copyright 2005 Matthew Eernisse (mde@fleegix.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Original code by Matthew Eernisse (mde@fleegix.org), March 2005
 * Additional bugfixes by Mark Pruett (mark.pruett@comcast.net), 12th July 2005
 * Multi-select added by Craig Anderson (craig@sitepoint.com), 24th August 2006
 *
 * Version 1.3
*/

/**
 * Serializes the data from all the inputs in a Web form
 * into a query-string style string.
 * @param docForm -- Reference to a DOM node of the form element
 * @param formatOpts -- JS object of options for how to format
 * the return string. Supported options:
 *    collapseMulti: (Boolean) take values from elements that
 *    can return multiple values (multi-select, checkbox groups)
 *    and collapse into a single, comman-delimited value
 *    (e.g., thisVar=asdf,qwer,zxcv)
 * @returns query-string style String of variable-value pairs
 */
function formData2QueryString(docForm, formatOpts)
{  
	var opts = formatOpts || {};
	opts.collapseMulti = true;
	var str = '';
	var formElem;
	var lastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		formElem = docForm.elements[i];
		
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				str += formElem.name + '=' + encodeURIComponent(formElem.value) + '&';
				break;
		
			// Multi-option select
			case 'select-multiple':
				var isSet = false;
				for(var j = 0; j < formElem.options.length; j++) {
					var currOpt = formElem.options[j];
					if (currOpt.selected) {
						if (opts.collapseMulti) {
							if (isSet)
								str += ',' + encodeURIComponent(currOpt.value);
							else {
								str += formElem.name + '=' + encodeURIComponent(currOpt.value);
								isSet = true;
							}
						}
						else
							str += formElem.name + '=' + encodeURIComponent(currOpt.value) + '&';
					}
				}
				
				if (opts.collapseMulti)
					str += '&';
				
				break;
		
			// Radio buttons
			case 'radio':
				if (formElem.checked)
					str += formElem.name + '=' + encodeURIComponent(formElem.value) + '&'
				
				break;
	
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Collapse multi-select into comma-separated list
					if (opts.collapseMulti && (formElem.name == lastElemName)) {
						// Strip of end ampersand if there is one
						if (str.lastIndexOf('&') == str.length-1)
							str = str.substr(0, str.length - 1);
					
						// Append value as comma-delimited string
						//if (str.indexOf(formElem.name + '=') != -1)
						str = str.replace(formElem.name + '=',  formElem.name + '=' + encodeURIComponent(formElem.value) + ',');
					}
					else
						str += formElem.name + '=' + encodeURIComponent(formElem.value);
					
					str += '&';
					lastElemName = formElem.name;
				}
				break;
		}
	}
	
	// Remove trailing separator
	str = str.substr(0, str.length - 1);
	return str;
}







/* http://ypslideoutmenus.sourceforge.net/ */
ypSlideOutMenu.Registry=[];ypSlideOutMenu.aniLen=250;ypSlideOutMenu.hideDelay=1000;ypSlideOutMenu.minCPUResolution=10;function ypSlideOutMenu(id,_2,_3,_4,_5,_6){this.ie=document.all?1:0;this.ns4=document.layers?1:0;this.dom=document.getElementById?1:0;this.css="";if(this.ie||this.ns4||this.dom){this.id=id;this.dir=_2;this.orientation=_2=="left"||_2=="right"?"h":"v";this.dirType=_2=="right"||_2=="down"?"-":"+";this.dim=this.orientation=="h"?_5:_6;this.hideTimer=false;this.aniTimer=false;this.open=false;this.over=false;this.startTime=0;this.gRef="ypSlideOutMenu_"+id;eval(this.gRef+"=this");ypSlideOutMenu.Registry[id]=this;var d=document;var _8="";_8+="#"+this.id+"Container{visibility:hidden;";_8+="left:"+_3+"px;";_8+="top:"+_4+"px;";_8+="overflow:hidden;z-index:10000;}";_8+="#"+this.id+"Container,#"+this.id+"Content{position:absolute;";_8+="width:"+_5+"px;";_8+="height:"+_6+"px;";_8+="clip:rect(0 "+_5+" "+_6+" 0);";_8+="}";this.css=_8;this.load();}}ypSlideOutMenu.writeCSS=function(){document.writeln("<style type=\"text/css\">");for(var id in ypSlideOutMenu.Registry){document.writeln(ypSlideOutMenu.Registry[id].css);}document.writeln("</style>");};ypSlideOutMenu.prototype.load=function(){var d=document;var _10=this.id+"Container";var _11=this.id+"Content";var _12=this.dom?d.getElementById(_10):this.ie?d.all[_10]:d.layers[_10];if(_12){var _13=this.ns4?_12.layers[_11]:this.ie?d.all[_11]:d.getElementById(_11);}var _14;if(!_12||!_13){window.setTimeout(this.gRef+".load()",100);}else{this.container=_12;this.menu=_13;this.style=this.ns4?this.menu:this.menu.style;this.homePos=eval("0"+this.dirType+this.dim);this.outPos=0;this.accelConst=(this.outPos-this.homePos)/ypSlideOutMenu.aniLen/ypSlideOutMenu.aniLen;if(this.ns4){this.menu.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT);}this.menu.onmouseover=new Function("ypSlideOutMenu.showMenu('"+this.id+"')");this.menu.onmouseout=new Function("ypSlideOutMenu.hideMenu('"+this.id+"')");this.endSlide();}};ypSlideOutMenu.showMenu=function(id){var reg=ypSlideOutMenu.Registry;var obj=ypSlideOutMenu.Registry[id];if(obj.container){obj.over=true;for(menu in reg){if(id!=menu){ypSlideOutMenu.hide(menu);}}if(obj.hideTimer){reg[id].hideTimer=window.clearTimeout(reg[id].hideTimer);}if(!obj.open&&!obj.aniTimer){reg[id].startSlide(true);}}};ypSlideOutMenu.hideMenu=function(id){var obj=ypSlideOutMenu.Registry[id];if(obj.container){if(obj.hideTimer){window.clearTimeout(obj.hideTimer);}obj.hideTimer=window.setTimeout("ypSlideOutMenu.hide('"+id+"')",ypSlideOutMenu.hideDelay);}};ypSlideOutMenu.hideAll=function(){var reg=ypSlideOutMenu.Registry;for(menu in reg){ypSlideOutMenu.hide(menu);if(menu.hideTimer){window.clearTimeout(menu.hideTimer);}}};ypSlideOutMenu.hide=function(id){var obj=ypSlideOutMenu.Registry[id];obj.over=false;if(obj.hideTimer){window.clearTimeout(obj.hideTimer);}obj.hideTimer=0;if(obj.open&&!obj.aniTimer){obj.startSlide(false);}};ypSlideOutMenu.prototype.startSlide=function(_21){this[_21?"onactivate":"ondeactivate"]();this.open=_21;if(_21){this.setVisibility(true);}this.startTime=(new Date()).getTime();this.aniTimer=window.setInterval(this.gRef+".slide()",ypSlideOutMenu.minCPUResolution);};ypSlideOutMenu.prototype.slide=function(){var _22=(new Date()).getTime()-this.startTime;if(_22>ypSlideOutMenu.aniLen){this.endSlide();}else{var d=Math.round(Math.pow(ypSlideOutMenu.aniLen-_22,2)*this.accelConst);if(this.open&&this.dirType=="-"){d=-d;}else{if(this.open&&this.dirType=="+"){d=-d;}else{if(!this.open&&this.dirType=="-"){d=-this.dim+d;}else{d=this.dim+d;}}}this.moveTo(d);}};ypSlideOutMenu.prototype.endSlide=function(){this.aniTimer=window.clearTimeout(this.aniTimer);this.moveTo(this.open?this.outPos:this.homePos);if(!this.open){this.setVisibility(false);}if((this.open&&!this.over)||(!this.open&&this.over)){this.startSlide(this.over);}};ypSlideOutMenu.prototype.setVisibility=function(_24){var s=this.ns4?this.container:this.container.style;s.visibility=_24?"visible":"hidden";};ypSlideOutMenu.prototype.moveTo=function(p){this.style[this.orientation=="h"?"left":"top"]=this.ns4?p:p+"px";};ypSlideOutMenu.prototype.getPos=function(c){return parseInt(this.style[c]);};ypSlideOutMenu.prototype.onactivate=function(){};ypSlideOutMenu.prototype.ondeactivate=function(){};


