function openNewTab(href) {
	var w=window.open(href);w.focus();return false;
}

var iText;
function insertTags(tag){
	if(iText!=null){
		iText.value += tag;
	}
}

function diacriticInsert(textInput) {
	iText=textInput;
}

var imagesPath = 'images/';

function ExpandAdv(element1, element2, hid, whatToDo)
	{
		var oHiddenRow = document.getElementById(element1);
		var oImage = document.getElementById(element2);
		var oHidd  = document.getElementById(hid);

		if ( oHiddenRow != null )
		{


		if (whatToDo=='close') {
			oHiddenRow.style.display  = 'none';
			oImage.src = imagesPath+"arrow_unchecked.gif";
			oHidd.value = 'T';
		}
		else if (whatToDo=='open') {
				oHiddenRow.style.display  = '';
				oImage.src = imagesPath+"arrow_checked.gif";
				oHidd.value = 'F';
		}
		else {
			if ( oHiddenRow.style.display == '' ) {
				oHiddenRow.style.display  = 'none';
				oImage.src = imagesPath+"arrow_unchecked.gif";
				oHidd.value = 'T';
				if (element1=='HiddenSearch') ExpandAdv('HiddenBrowse', 'ImageBrowse', 'hiddBrowse', 'open');
				else if (element1=='HiddenBrowse') ExpandAdv('HiddenSearch', 'ImageSearch', 'hiddSearch', 'open');
			}
			else {
				oHiddenRow.style.display  = '';
				oImage.src = imagesPath+"arrow_checked.gif";
				oHidd.value = 'F';

				if (element1=='HiddenSearch') ExpandAdv('HiddenBrowse', 'ImageBrowse', 'hiddBrowse', 'close');
				else if (element1=='HiddenBrowse') ExpandAdv('HiddenSearch', 'ImageSearch', 'hiddSearch', 'close');
			}
		}

		}
	}

function Expand2Area(area1, image1, boolean1, area2, image2, boolean2) {
	var oArea1 = document.getElementById(area1);
	var oImage1 = document.getElementById(image1);
	var oBoolean1  = document.getElementById(boolean1);

	var oArea2 = document.getElementById(area2);
	var oImage2 = document.getElementById(image2);
	var oBoolean2  = document.getElementById(boolean2);
	
	if (oBoolean1.value == 'F') {
		oBoolean1.value = 'T';
		oArea1.style.display = '';
		var src1 = oImage1.src; 
		oImage1.src = oImage2.src;
		
		oBoolean2.value = 'F';
		oArea2.style.display = 'none';
		oImage2.src = src1;
	} else {
		oBoolean2.value = 'T';
		oArea2.style.display = '';
		var src2 = oImage2.src; 
		oImage2.src = oImage1.src;
		
		oBoolean1.value = 'F';
		oArea1.style.display = 'none';
		oImage1.src = src2;
	}
}

function Expand()
	{
		var oExpand = document.getElementById("Template_Search_Expand");
		var oHiddenRow = document.getElementById("HiddenRow");

		if ( oHiddenRow != null )
		{
			if ( oHiddenRow.style.display == '' )
			{
				oHiddenRow.style.display  = 'none';
//				oExpand.innerHTML = 'arata optiunile de cautare';
				document.getElementById("Image").src = imagesPath+"arrow_expand.gif";
			}
			else
			{
		//		oExpand.innerHTML = 'ascunde optiunile de cautare';
				oHiddenRow.style.display  = '';
				document.getElementById("Image").src = imagesPath+"arrow_collapse.gif";
			}
		}
	}

function ExpandServere()
	{


		var oHiddenRowServere = document.getElementById("HiddenRowServere");

		if ( oHiddenRowServere != null )
		{
			if ( oHiddenRowServere.style.display == '' )
			{
				oHiddenRowServere.style.display  = 'none';


				document.getElementById("ImageServere").src = imagesPath+"arrow_expand.gif";

			}
			else
			{
				oHiddenRowServere.style.display  = '';
				document.getElementById("ImageServere").src = imagesPath+"arrow_collapse.gif";
			}
		}
	}

function ExpandDiacritice()
	{

		var oHiddenDiacritics = document.getElementById("HiddenDiacritics");

		if ( oHiddenDiacritics != null )
		{
			if ( oHiddenDiacritics.style.display == '' )
			{
				oHiddenDiacritics.style.display  = 'none';
				document.getElementById("ImageDiacritice").src = imagesPath+"arrow_expand_right.gif";
			}
			else
			{
				oHiddenDiacritics.style.display  = '';
				document.getElementById("ImageDiacritice").src = imagesPath+"arrow_collapse_right.gif";
			}
		}
	}

	function ExpandOptions()
	{

		var oHiddenOptions = document.getElementById("HiddenOptions");

		if ( oHiddenOptions != null )
		{
			if ( oHiddenOptions.style.display == '' )
			{
				oHiddenOptions.style.display  = 'none';
				document.getElementById("ImageOptions").src = imagesPath+"arrow_expand_right.gif";
			}
			else
			{
				oHiddenOptions.style.display  = '';
				document.getElementById("ImageOptions").src = imagesPath+"arrow_collapse_right.gif";
			}
		}
	}

	function ExpandActions()
	{

		var oHiddenActions = document.getElementById("HiddenActions");

		if ( oHiddenActions != null )
		{
			if ( oHiddenActions.style.display == '' )
			{
				oHiddenActions.style.display  = 'none';
				document.getElementById("ImageActions").src = imagesPath+"arrow_expand_right.gif";
			}
			else
			{
				oHiddenActions.style.display  = '';
				document.getElementById("ImageActions").src = imagesPath+"arrow_collapse_right.gif";
			}
		}
	}

// Transtech/Peter Add for transtechsearch 96/6/20 Start
  function ExpandTranstechSymbols()
	{

		var oHiddenDiacritics = document.getElementById("HiddenTranstechSymbols");

		if ( oHiddenDiacritics != null )
		{
			if ( oHiddenDiacritics.style.display == '' )
			{
				oHiddenDiacritics.style.display  = 'none';
				document.getElementById("ImageDiacritice2").src = imagesPath+"arrow_expand_right.gif";
			}
			else
			{
				oHiddenDiacritics.style.display  = '';
				document.getElementById("ImageDiacritice2").src = imagesPath+"arrow_collapse_right.gif";
			}
		}
	}
// Transtech/Peter Add for transtechsearch 96/6/20 End

var openedMenu_lv0="";
var openedMenu_lv1="";
var openedMenu_lv2="";

function openClose(element, level){

var meniu = document.getElementById("group_" + element); //meniul selectat

if (level==0){
//prima data verifica daca openedMenu este chiar meniul selectat
if (openedMenu_lv0 == element){//este acelasi - le inchide pe amandoua

//daca este deschis il inchide
meniu.style.display='none';
openedMenu_lv0='';//inchide
}
else if (openedMenu_lv0!=''){

document.getElementById("group_"+openedMenu_lv0).style.display='none';//inchide

meniu.style.display='';//deschide

openedMenu_lv0 = element;//fixeaza noul meniu deschis
}
else {//nu e nimic deschis - trebuie sa deschidem

meniu.style.display='';//deschide

openedMenu_lv0 = element;//fixeaza noul meniu deschis

}
}//pentru level 0
else if (level==1){

if (openedMenu_lv1 == element){//este acelasi - le inchide pe amandoua

//daca este deschis il inchide
meniu.style.display='none';
openedMenu_lv1='';//inchide
}
else if (openedMenu_lv1!=''){

document.getElementById("group_"+openedMenu_lv1).style.display='none';//inchide

meniu.style.display='';//deschide

openedMenu_lv1 = element;//fixeaza noul meniu deschis
}
else {//nu e nimic deschis - trebuie sa deschidem

meniu.style.display='';//deschide

openedMenu_lv1 = element;//fixeaza noul meniu deschis

}

}
else if (level==2){

if (openedMenu_lv2 == element){//este acelasi - le inchide pe amandoua

//daca este deschis il inchide
meniu.style.display='none';
openedMenu_lv2='';//inchide
}
else if (openedMenu_lv2!=''){

document.getElementById("group_"+openedMenu_lv2).style.display='none';//inchide

meniu.style.display='';//deschide

openedMenu_lv2 = element;//fixeaza noul meniu deschis
}
else {//nu e nimic deschis - trebuie sa deschidem

meniu.style.display='';//deschide

openedMenu_lv2 = element;//fixeaza noul meniu deschis

}

}




}




function selTag(){

var taguri = document.getElementById('claseUtilizatori').taguri;
var subtaguri = document.getElementById('claseUtilizatori').subtaguri;
var selLength = taguri.length;

var count = 0;
for (i = 0; ((i < selLength) || (count == 2)); i++) {
if (taguri.options[i].selected) count++;
}
if (count==1) Tapestry.submit_form('claseUtilizatori', 'selTag');
else {

while (subtaguri.length!=0)
for (i = 0; i < subtaguri.length; i++)
subtaguri.options[i]=null;

}

}

function listPopup(href, listID) {

popupwindow = window.open("" ,'listValidare', 'status=no,toolbar=no,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=650,height=450');
popupwindow.moveTo(screen.width/2-275, screen.height/2-225);
popupwindow.focus();

if (listID==1) href=href+"&sp=S"+document.searchForm.criteriul1.value+"&sp=S"+document.searchForm.field1.value;
else if (listID==2) href=href+"&sp=S"+document.searchForm.criteriul2.value+"&sp=S"+document.searchForm.field2.value;
else if (listID==3) href=href+"&sp=S"+document.searchForm.criteriul3.value+"&sp=S"+document.searchForm.field3.value;
else if (listID==4) href=href+"&sp=S"+document.searchForm.criteriul4.value+"&sp=S"+document.searchForm.field4.value;

popupwindow.location = href;


if (popupwindow == null) popupwindow.opener = self;
return false;
}


function editTipTag3Popup(href, start, nrElements) {

alert('editTagPopup('+href+','+start+','+nrElements+')');

popupwindow = window.open("" ,'editTag', 'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=600,height=400');
popupwindow.moveTo(screen.width/2-300, screen.height/2-200);
popupwindow.focus();

var insertElem="";
for (i=1; i<=nrElements; i++){
var inputtext = document.getElementById("elementTipTag3Value" + eval(i + start));
insertElem = insertElem+"&sp=S"+inputtext.value;
}

href = href + insertElem;

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;
}

function createPreviewPop(href){

alert("createPreviewPOP");

popupwindow = window.open("" ,"previewPop", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1,width=600,height=700");
popupwindow.moveTo(screen.width/2-300, screen.height/2-350);
popupwindow.focus();


var vinputTitles = document.getElementById("inputTitles");


var addvars =  "&sp=S"+document.getElementById("invoiceAddress").value
	 		 + "&sp=S"+document.getElementById("deliveryAddress").value
			 + "&sp=S"+document.getElementById("deliveryDateEstimated").value;


addvars = addvars + "&sp="+vinputTitles.options.length;

for (var i = 0; i < vinputTitles.options.length; i++) addvars = addvars + "&sp="+vinputTitles.options[ i ].value;

popupwindow.location = href + addvars;

if (popupwindow == null) popupwindow.opener = self;
return false;
}



function editTagPopup(href, start, nrElements) {
popupwindow = window.open("" ,'editTag', 'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=600,height=400');
popupwindow.moveTo(screen.width/2-300, screen.height/2-200);
popupwindow.focus();

var insertElem="";
for (i=1; i<=nrElements; i++){
var inputtext = document.getElementById("elementValue" + eval(i + start));

if (inputtext!=null)
		insertElem = insertElem+"&sp="+i+"&sp=S"+inputtext.value;

}

href = href + insertElem;

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;
}


function selectAll(formIds){

 var rootCheck = document.getElementById("rootCheck");
 var len = document.getElementById(formIds).elements.length;

	if (rootCheck.checked){
	for(var i=0;i<len;i++) {
	var item = document.getElementById(formIds).elements[i];
			if (typeof(item.name) != 'undefined'){
				if (item.name.indexOf("selectat") == 0)
					item.checked = true;
			}
		}
	}
	else {
		for(var i=0;i<len;i++) {
			var item = document.getElementById(formIds).elements[i];
			if (typeof(item.name) != 'undefined'){
				if (item.name.indexOf("selectat") == 0)
					item.checked= false;
			}
		}

	}
}

function editFixlenSubtag(href) {

popupwindow = window.open("" ,'editFixlenSubTag', 'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1,width=600,height=400');
popupwindow.moveTo(screen.width/2-300, screen.height/2-200);
popupwindow.focus();

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;
}



function encodeURL(str){

    var s0, i, s, u;

    s0 = "";                // encoded str

    for (i = 0; i < str.length; i++){   // scan the source

        s = str.charAt(i);

        u = str.charCodeAt(i);          // get unicode of the char

        if (s == " "){s0 += "+";}       // SP should be converted to "+"

        else {

            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape

                s0 = s0 + s;            // don't escape

            }

            else {                  // escape

                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format

                    s = "0"+u.toString(16);

                    s0 += "%"+ s.substr(s.length-2);

                }

                else if (u > 0x1fffff){     // quaternary byte format (extended)

                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

                else if (u > 0x7ff){        // triple byte format

                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);

                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

                else {                      // double byte format

                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);

                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

            }

        }

    }

    return s0;

}



/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")

    Copyright (C) 2002, Cresc Corp.

    Version: 1.0

*/

function decodeURL(str){

    var s0, i, j, s, ss, u, n, f;

    s0 = "";                // decoded str

    for (i = 0; i < str.length; i++){   // scan the source str

        s = str.charAt(i);

        if (s == "+"){s0 += " ";}       // "+" should be changed to SP

        else {

            if (s != "%"){s0 += s;}     // add an unescaped char

            else{               // escape sequence decoding

                u = 0;          // unicode of the character

                f = 1;          // escape flag, zero means end of this sequence

                while (true) {

                    ss = "";        // local str to parse as int

                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse

                            sss = str.charAt(++i);

                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {

                                ss += sss;      // if hex, add the hex character

                            } else {--i; break;}    // not a hex char., exit the loop

                        }

                    n = parseInt(ss, 16);           // parse the hex str as byte

                    if (n <= 0x7f){u = n; f = 1;}   // single byte format

                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format

                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format

                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)

                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits

                    if (f <= 1){break;}         // end of the utf byte sequence

                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte

                    else {break;}                   // abnormal, format error

                }

            s0 += String.fromCharCode(u);           // add the escaped character

            }

        }

    }

    return s0;

}


function validarePopup(href, listID) {


var inputtext = document.getElementById("elementValue" + listID);

popupwindow = window.open("" ,'validare', 'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=650,height=450');
popupwindow.moveTo(screen.width/2-275, screen.height/2-225);
popupwindow.focus();


popupwindow.location = href+"&sp=S"+encodeURL(inputtext.value);


if (popupwindow == null) popupwindow.opener = self;
return false;
}


function selUtil(element){
element.href = element.href + "&sp="+document.Form1.utilizatori.value;
}


function validareLinkPopup(href, listID) {


var inputtext = document.getElementById("elementTipTag3Value" + listID);

popupwindow = window.open("" ,'validare', 'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=650,height=450');
popupwindow.moveTo(screen.width/2-275, screen.height/2-225);
popupwindow.focus();

popupwindow.location = href+"&sp=S"+encodeURL(inputtext.value);

if (popupwindow == null) popupwindow.opener = self;
return false;
}

function createPop(href) {

	popupwindow = window.open("" ,"detaliiInregistrare", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=657,height=465");
	popupwindow.moveTo(screen.width/2-325, screen.height/2-235);
	popupwindow.focus();

	popupwindow.location = href;

	if (popupwindow == null) popupwindow.opener = self;

	return false;


//	if(navigator.appName.indexOf("Microsoft")!=-1){
//		var ieDialog = window.showModalDialog(href,"name","dialogWidth:657px; dialogHeight:465px; center:yes");
//	}
}

function createMiniPop(href) {


popupwindow = window.open("" ,"detaliiInregistrare", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=200,height=250");
popupwindow.moveTo(screen.width/2-325, screen.height/2-235);
popupwindow.focus();

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;

}


function createPayPop(href) {


popupwindow = window.open("" ,"payPopup", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=0,width=350,height=300");
popupwindow.moveTo(screen.width/2-175, screen.height/2-150);
popupwindow.focus();

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;

}




function createPopEdit(href) {

popupwindow = window.open("" ,"MeniuCatalogare", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1,width=870,height=600");
popupwindow.moveTo(screen.width/2-435, screen.height/2-300);
popupwindow.focus();

popupwindow.location = href;

if (popupwindow == null) popupwindow.opener = self;
return false;

}

function createPopupFullParentBody(href) {

	var w = document.body.clientWidth;
	var h = document.body.clientHeight;
	popupwindow = window.open("" ,"PopupFullParentBody", "status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1,width="+w+",height="+h);
	popupwindow.moveTo(1, 1);
	popupwindow.focus();

	popupwindow.location = href;

	if (popupwindow == null) popupwindow.opener = self;
	return false;

	}


function updateParentPayLater(){

parent.opener.parent.document.Form1._linkSubmit.value = 'payLater';

parent.opener.parent.document.Form1.submit();
parent.self.close();

}


function updateParentEditLink(valFieldAfisare, valFieldA, valFieldB, id, manifestareID){

				   //aici tb. copiat si linkul de la inregistrare intr-o valoare ascunsa
if (valFieldB!='') {
		parent.opener.parent.document.getElementById("elementTipTag3Value" + id).value = valFieldA;
		parent.opener.parent.document.getElementById("elementTipTag3Value" + (id+1)).value = valFieldB;
}
else parent.opener.parent.document.getElementById("elementTipTag3Value" + id).value = valFieldAfisare;

parent.opener.parent.document.getElementById("idLinkValue" + id).value = manifestareID;

parent.self.close();

}

function updateParentEdit(valFieldAfisare, valFieldA, valFieldB, id){


if (valFieldB!='') {
		parent.opener.parent.document.getElementById("elementValue" + id).value = valFieldA;
		parent.opener.parent.document.getElementById("elementValue" + (id+1)).value = valFieldB;
}
else parent.opener.parent.document.getElementById("elementValue" + id).value = valFieldAfisare;


parent.self.close();

}


function updateParent1(valField){
parent.opener.parent.document.searchForm.criteriul1.value=document.formList.criteriul.value;
parent.opener.parent.document.searchForm.field1.value = valField;
parent.opener.parent.document.searchForm.submit();
parent.self.close();
}

function updateParent2(valField){
parent.opener.parent.document.searchForm.criteriul2.value=document.formList.criteriul.value;
parent.opener.parent.document.searchForm.field2.value = valField;
parent.opener.parent.document.searchForm.submit();
parent.self.close();
}

function updateParent3(valField){

parent.opener.parent.document.searchForm.criteriul3.value=document.formList.criteriul.value;
parent.opener.parent.document.searchForm.field3.value = valField;
parent.opener.parent.document.searchForm.submit();
parent.self.close();
}

function updateParent4(valField){
parent.opener.parent.document.searchForm.criteriul4.value=document.formList.criteriul.value;
parent.opener.parent.document.searchForm.field4.value = valField;
parent.opener.parent.document.searchForm.submit();
parent.self.close();
}



function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
    return false;
   }
else
   return true;
}
