nav = navigator.appName.indexOf("Microsoft")!= -1 ? 1 : 2;

function popup(url, name, width, height, scroll, modal, resizable) {
	width=Math.min(screen.availWidth,width);
	height=Math.min(screen.availHeight-40,height);
	var poz_x=(screen.availWidth-width)/2;
	var poz_y=(screen.availHeight-height-30)/2;
	newwin=window.open(url, name, 'scrollbars='+scroll+', menubar=no, width='+width+', height='+height+', resizable=no,toolbar=no, left='+poz_x+', top='+poz_y+', location=no, status=no');
	if(modal){
		popInt=setInterval(function(n){
			if(typeof(newwin.name)=="string"){
				if(newwin.document.body){
					openerfocus=function(){
						if(typeof(newwin.name)=="string"){
							newwin.focus();
						}else{
							document.body.onfocus=null;
						}
					}
					document.body.onfocus=openerfocus;
					newwin.window.document.body.onunload=function(){}
					newwin.focus();
					/*with(newwin){
						self.focus()
						opener.document.body.onfocus=function(){self.focus();opener.alert(4);}
						self.document.body.onunload=function(){opener.document.body.onfocus=null}
					}*/
					clearInterval(popInt);
				}
			}else{
				clearInterval(popInt)
			}
		},1)
	}
}

function rand( min, max ) {
	var argc = arguments.length;
	if (argc == 0) {
		min = 0;
		max = 2147483647;
	} else if (argc == 1) {
		throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
	}
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}

var v_array = [8,35,36,37,39,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105];
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

/* AICI sunt elementele necesare validarii automate a formularelor din site*/
var email_exp= new RegExp("^[\\w\\+-]+(\\.[\\w\\+-]+)?@((\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\|([\\w\\+-]+\\.[a-zA-Z0-9\.]{2,}))$");
var cnp_exp=new RegExp("^[128][0-9]\{12\}$");

function valideaza_email(sName,mesaj){
	if(document.getElementsByName(sName)){
		var objEmail=document.getElementsByName(sName);
		for(i=0;i<objEmail.length;i++) {
			if(objEmail[i].value.replace(/^\s+|\s+$/,'')=='' || (!email_exp.test(objEmail[i].value))){
				mesaj_eroare=mesaj_eroare+mesaj+' \n';
			}
		}
	}
}

function valideaza_cnp(sName,mesaj){
	if(document.getElementsByName(sName)){
		var objCNP=document.getElementsByName(sName);
		for(i=0;i<objCNP.length;i++) {
			if(objCNP[i].value.replace(/^\s+|\s+$/,'')=='' || (!email_exp.test(objCNP[i].value))){
				mesaj_eroare=mesaj_eroare+mesaj+' \n';
			}
		}
	}
}

function valideaza_text(sName,mesaj){
	if(document.getElementsByName(sName)){
		var objTXT=document.getElementsByName(sName);
		for(i=0;i<objTXT.length;i++) {
			if(objTXT[i].value.replace(/^\s+|\s+$/,'')==''){
				mesaj_eroare=mesaj_eroare+mesaj+' \n';
			}
		}
	}
}

function valideaza_radio(sName,mesaj){
	if(document.getElementsByName(sName)){
		var objRadio=document.getElementsByName(sName);
		for (i=0; i<objRadio.length; i++) {
			if(objRadio[i].checked){
			}else{
				mesaj_eroare=mesaj_eroare+mesaj+' \n';
			}
		}
	}
}

function valideaza_bifa(sName,mesaj){
	if(document.getElementsByName(sName)){
		var objCheck=document.getElementsByName(sName);
		for (i=0; i<objCheck.length; i++){
			if(objCheck[i].checked==true){
			}else{
				mesaj_eroare=mesaj_eroare+mesaj+' \n';
			}
		}
	}
}
/********************************************************/

// taburile
//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

function cascadedstyle(el, cssproperty, csspropertyNS){
	if(el){
		if (el.currentStyle)
			return el.currentStyle[cssproperty]
		else if (window.getComputedStyle){
			var elstyle=window.getComputedStyle(el, "")
			return elstyle.getPropertyValue(csspropertyNS)
		}
	}
}

var previoustab=""

function expandcontent(cid, aobject){
	if(document.getElementById(cid)){
		if (document.getElementById){
			highlighttab(aobject)
			detectSourceindex(aobject)
			if (previoustab!="")
				document.getElementById(previoustab).style.display="none"
			document.getElementById(cid).style.display="block"
			previoustab=cid
			if (aobject.blur)
				aobject.blur()
			return false
		}
		else
			return true
	}
}

function highlighttab(aobject){
	if(aobject){
		if (typeof tabobjlinks=="undefined")
			collecttablinks()
		for (i=0; i<tabobjlinks.length; i++)
			tabobjlinks[i].style.backgroundColor=initTabcolor
		var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor
		aobject.style.backgroundColor=document.getElementById("tabcontentcontainer").style.backgroundColor=themecolor
	}
}

function collecttablinks(){ 
	var tabobj=document.getElementById("tablist");
	if(tabobj){
		tabobjlinks=tabobj.getElementsByTagName("A");
	}else{
		tabobjlinks=0;
	}
}

function detectSourceindex(aobject){
	for (i=0; i<tabobjlinks.length; i++){
		if (aobject==tabobjlinks[i]){
			tabsourceindex=i //source index of tab bar relative to other tabs
			break
		}
	}
}

function do_onload(){
	var cookiecheck=window.get_cookie && get_cookie(window.location.pathname).indexOf("|")!=-1
	collecttablinks()
	initTabcolor=cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
	initTabpostcolor=cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
	if (typeof enablepersistence!="undefined" && enablepersistence && cookiecheck){
		var cookieparse=get_cookie(window.location.pathname).split("|")
		var whichtab=cookieparse[0]
		var tabcontentid=cookieparse[1]
		expandcontent(tabcontentid, tabobjlinks[whichtab])
	}else
	expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload