

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function changeColour(ident,trValue)
{
	ident.style.background = trValue;
}

function acDetailsCheck(){
	//alert (document.accountDetailsForm.payment_method.options.selectedIndex.value)
	// Check which tab is selected
	// Check for errors on this tab only
	// If no errors, check next tab ........
	// If error, display tab error is on and change style to show where error is
	var sortCodeError=0;
	var error = "";
	var currentTab=0;
	account2RequiredFields = new Array('data[nume]','data[adresa]','data[codpostal]','data[tara]','data[email]');
	account2RequiredFieldTitles = new Array('Nume de contact','Adresa','Cod poştal','Ţara','Email');
	payment1RequiredFields = new Array('data[cont_moneyb]');
	payment1RequiredFieldTitles = new Array('Contul MoneyBookers.ro');
	site1RequiredFields=  new Array('data[numesite]','data[urlsite]','data[metoda_promo]');
	site1RequiredFieldTitles= new Array('Nume site','URL site','Modalitatea de promovare');

	//Regular password
	password1RequiredFields= new Array();
	password1RequiredFieldTitles= new Array();

	var myTabProcessed;

	tabList = new Array('account2','payment1','site1','password1');
	sectionList = new Array('account','payment','site','password');



	//check if NORMAL PASSWORD has been submitted
	if (document.accountDetailsForm['data[old_password]'].value!='')
	{

		if (document.accountDetailsForm['data[new_password1]'].value=='')
		{
			error += "Introduceti noua parolă pt a o putea modifica  ";
			document.accountDetailsForm['data[new_password1]'].style.border='solid 2px red';
		}
		if (document.accountDetailsForm['data[new_password1]'].value!='')
		{
			password1RequiredFields[password1RequiredFields.length]='data[new_password2]';
			password1RequiredFieldTitles[password1RequiredFieldTitles.length]='Confirmaţi noua parolă';
		}
		else if (document.accountDetailsForm['data[new_password2]'].value!='')
			{
				password1RequiredFields[password1RequiredFields.length]='data[new_password1]';
				password1RequiredFieldTitles[password1RequiredFieldTitles.length]='Noua parolă';
			}
		if (document.accountDetailsForm['data[new_password1]'].value != document.accountDetailsForm['data[new_password2]'].value)
		{
		    error += "Parolele nu corespund  ";
			document.accountDetailsForm['data[new_password1]'].style.border='solid 2px red';
			document.accountDetailsForm['data[new_password2]'].style.border='solid 2px red';
		}

	}

	else if (document.accountDetailsForm['data[new_password1]'].value!='')
	{
		error += "Introduceti vechea parolă pt a o putea modifica  ";
		document.accountDetailsForm['data[old_password]'].style.border='solid 2px red';
	}
	else if (document.accountDetailsForm['data[new_password2]'].value!='')
	{
		error += "Introduceti vechea parolă pt a o putea modifica  ";
		document.accountDetailsForm['data[old_password]'].style.border='solid 2px red';
	}

	//do current tab
	for(var ii=0; ii<tabList.length; ii++)
	{
		myTab = findObj(tabList[ii]);
		if(myTab && myTab.style.display == '')// Currently Displayed Tab
		{
			//alert ("current tab="+sectionList[ii]);
			myArray = eval(tabList[ii]+'RequiredFields');
			myTitlesArray  = eval(tabList[ii]+'RequiredFieldTitles');

			for(var n=0; n<myArray.length; n++)
			{

				if(document.accountDetailsForm[myArray[n]].value =='')
				{

						document.accountDetailsForm[myArray[n]].style.border='solid 2px red';
						error += myTitlesArray[n]+" este un câmp necesar.  ";

				}
				else
				{
						document.accountDetailsForm[myArray[n]].style.border='';
				}

			}
			//alert(tabList[ii]+' is showing');
		}
	}
	//finish current tab
	if (error=="")
	{
		//alert("no error on first tab");
		currentTab=1;
	}
	//loop through rest of tabs
	for(var ij=0; ij<tabList.length; ij++)
	{
		myTab = findObj(tabList[ij]);
		if(myTab && myTab.style.display == 'none')// Currently Not Displayed Tabs
		{
			//alert ("hidden tab="+sectionList[ij]);
			myArray = eval(tabList[ij]+'RequiredFields');
			myTitlesArray  = eval(tabList[ij]+'RequiredFieldTitles');
			for(var n=0; n<myArray.length; n++)
			{
				//Add dependancies
				if(document.accountDetailsForm[myArray[n]].value =='')
				{
				    //do all text fields
				    document.accountDetailsForm[myArray[n]].style.border='solid 2px red';
				    error += myTitlesArray[n]+" este un câmp necesar. ";
				}
				else
				{
				    //take off all correct red outlines
				    document.accountDetailsForm[myArray[n]].style.border='';
				}
			}

		}
		//check there is an error and that the currently displayed tab doesn't have an error
		if(error!="" && currentTab==1)
		{
			//alert(sectionList[ij]);
			showAccountDetails(sectionList[ij],2);
			break;
		}
	}
	//end hidden tab loop


	if (error!=""){
		alert(error);
		//return (false);
	}
	else
	{
		//alert ("Required Fields completed. Submit the form");
		document.accountDetailsForm.submit();
	}
}

// used to show different tabs in account details of publishers
function showAccountDetails(name,num)
{
	//alert (name,num);
	myElements = new Array("account","payment","site","password");

	for(iii=0; iii<myElements.length; iii++)
	{
		//alert ("Doing "+myElements[iii]);
		for(var ii=num; ii>0; ii--)
		{
			myName = myElements[iii]+ii;
			//alert(myName);
			myObject = findObj(myName);
			if(myObject)
			{
				if(myElements[iii] == name)
				{
					//alert ("Show "+name);
					myObject.style.display = '';
				}
				else
				{
					//alert ("Hide "+name);
					myObject.style.display = 'none';
				}
			}
			else alert ("Can't find object");
		}
	}
}

function colorRow(theRow, action)
{
	var td1= 'reportdata';
	var td1h= 'reportdatahover';
	var td1hs= 'reportdatahighlight';

	var td2= 'reportdataconfirmed';
	var td2h= 'reportdataconfirmedhover';
	var td2hs= 'reportdataconfirmedhighlight';

	var td3= 'reportdatapending';
	var td3h= 'reportdatapendinghover';
	var td3hs= 'reportdatapendinghighlight';

	var td4= 'reportdatadecline';
	var td4h= 'reportdatadeclinehover';
	var td4hs= 'reportdatadeclinehighlight';

	var td5= 'reportdatatotal';
	var td5h= 'reportdatatotalhover';
	var td5hs= 'reportdatatotalhighlight';



		if (typeof(document.getElementsByTagName) != 'undefined')
		{
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined')
    {
       theCells = theRow.cells;
    }
    else
    {
			return false;
    }

	cellsCnt= theCells.length;

	orgClassName= theCells[0].className;

	// mouseOver
	if ( action=='in' && orgClassName!= td1hs && orgClassName!= td2hs && orgClassName!= td3hs && orgClassName!= td4hs && orgClassName!= td5hs) // mouseOver
	{

		for (i= 0; i< cellsCnt; i++)
		{
			orgClassName= theCells[i].className;

			if(orgClassName== td1)
			{
				hClass= td1h;
			}
			else if(orgClassName== td2)
			{
				hClass= td2h;
			}
			else if(orgClassName== td3)
			{
				hClass= td3h;
			}
			else if(orgClassName== td4)
			{
				hClass= td4h;
			}
			else if(orgClassName== td5)
			{
				hClass= td5h;
			}

			theCells[i].className= hClass;
		}
	}
	// mouseOut
	else if ( action=='out' && orgClassName!= td1hs && orgClassName!= td2hs && orgClassName!= td3hs && orgClassName!= td4hs && orgClassName!= td5hs && orgClassName!= td1 && orgClassName!= td2 && orgClassName!= td3 && orgClassName!= td4 && orgClassName!= td5 )
	{
		for (i= 0; i< cellsCnt; i++)
		{
			orgClassName= theCells[i].className;

			if(orgClassName== td1h)
			{
				hClass= td1;
			}
			else if(orgClassName== td2h)
			{
				hClass= td2;
			}
			else if(orgClassName== td3h)
			{
				hClass= td3;
			}

			else if(orgClassName== td4h)
			{
				hClass= td4;
			}

			else if(orgClassName== td5h)
			{
				hClass= td5;
			}

			theCells[i].className= hClass;
		}
	}
	// onClick
	else if (action=='click')
	{

		for (i= 0; i< cellsCnt; i++)
		{
			orgClassName= theCells[i].className;

			// select
			if(orgClassName== td1 || orgClassName== td1h)
			{
				hClass= td1hs;
			}
			else if(orgClassName== td2 || orgClassName== td2h)
			{
				hClass= td2hs;
			}
			else if(orgClassName== td3 || orgClassName== td3h)
			{
				hClass= td3hs;
			}
			else if(orgClassName== td4 || orgClassName== td4h)
			{
				hClass= td4hs;
			}
			else if(orgClassName== td5 || orgClassName== td5h)
			{
				hClass= td5hs;
			}


			// unselect
			if(orgClassName== td1hs)
			{
				hClass= td1;
			}
			else if(orgClassName== td2hs)
			{
				hClass= td2;
			}
			else if(orgClassName== td3hs)
			{
				hClass= td3;
			}
			else if(orgClassName== td4hs)
			{
				hClass= td4;
			}
			else if(orgClassName== td5hs)
			{
				hClass= td5;
			}
			theCells[i].className= hClass;
		}

	}
	return false;
}
// end colorRow


//report submit orrder by and page
function reportSubmit(Item){//not used
	document.reportForm['data[start]'].value = Item;
	document.reportForm.submit();
}

function reportSubmitPagination(Item){
	document.reportForm['data[pagination]'].value = Item;
	document.reportForm.submit();
}

function reportSubmitOrderby(Item){
    if (document.reportForm['data[orderby]'].value == Item){
		if ( document.reportForm['data[ascdesc]'].value == 'asc' ){
				document.reportForm['data[ascdesc]'].value = 'desc';
		}else{
				document.reportForm['data[ascdesc]'].value = 'asc';
		}
	}
	document.reportForm['data[orderby]'].value = Item;
	document.reportForm.submit();
}


function initializareTinyMCE( type ){
  //alert(type);
  if (type=='full'){
	tinyMCE.init({
	  theme : 'advanced',
	  mode : 'textareas',
	  convert_urls : false,

	  plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

	  // Theme options
	  theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
	  theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	  theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	  theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
	  theme_advanced_toolbar_location : "top",
	  theme_advanced_toolbar_align : "left",
	  theme_advanced_statusbar_location : "bottom"
	  //theme_advanced_resizing : true,
	});

  }

  if (type=='standard'){
	tinyMCE.init({
	  theme : 'advanced',
	  mode : 'textareas',
	  convert_urls : false
	});
  }

  if (type=='simple'){
	tinyMCE.init({
	  theme : 'simple',
	  mode : 'textareas',
	  convert_urls : false
	});
  }

  if (type=='tichet'){
	tinyMCE.init({
	  theme : 'advanced',
	  mode : 'textareas',
	  convert_urls : false,
	  force_br_newlines : true,
      forced_root_block : '',

	  plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

	// Theme options
	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect|,forecolor,backcolor",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,fullscreen",
	theme_advanced_buttons3 : ""
	//theme_advanced_toolbar_location : "top",
	//theme_advanced_toolbar_align : "left",
	//theme_advanced_statusbar_location : "bottom",
	//theme_advanced_resizing : true,

	});
  }

}


function close_tichet(){

  var myStr=new String('<p>Tichetul a fost închis ca urmare a necontinuării discuţiei</p>');

  $obj = findObj('data[closetichet]');
  var myFrame = document.getElementById("data[detalii]_ifr");
  var doc = myFrame.contentDocument;
  if (doc == undefined || doc == null)
		doc = myFrame.contentWindow.document;
  var actualval = new String( doc.body.innerHTML );
  if ($obj.checked){
	newval = myStr + actualval;

  }else{
	newval = actualval.replace(myStr,"");
  }

  doc.open();
  doc.write(newval);
  doc.close();
}


function sendByButton(){

	obj = findObj('data[submit_by_button]');
	obj.value = 1;
	//alert( 'help: ' + obj.value );
}

