
//BROWSER DETECTION
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
 
function DetectBrowser(){ //Detectarea browserului folosit
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new DetectBrowser();

//FIELDS
function imgField(field, img){
	//bgcolor
		if(img == "over"){
			//bgcolor = "#FFFFFF";
			border_color = "#CCCCCC";
		}else {
			//bgcolor = "#FFFBFF";
			border_color = "#E0E1E0";
		}
		field.style.borderColor = border_color;
		//field.style.backgroundColor = bgcolor;
}

//BUTS
function imgBut(but, img){
	but.src = img;
}


//Reset Form
function resetForm(formName){
	if(ns6) form = eval("document.getElementById('"+formName+"')");
	else if(ns4) form = eval("document."+formName);
	else form = eval("document.all."+formName);
	form.reset();
}



function focus2(field){
	if(field.value == 0) field.value = '';
}	


function blur2(field){
	if(field.value == '') field.value = '0';
}	


function fieldValue(field_name){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field.value;
}

function setFieldValue(field_name, val){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field.value;
	field.value = val;
}

function writeIn(field_name, val){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	field.innerHTML = val;
}



function formatNR(nr, dec)
{
str = "" + Math.round(eval(nr) * Math.pow(10,dec));
while(str.length < dec)
	str = "0" + str;
decidx = str.length - dec;
tmp = str.substring(0,decidx);
if(tmp == '')
	tmp = '0';
if(dec > 0)
	tmp = tmp + '.' + str.substring(decidx, str.length);
return(tmp);
}



function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}


function goodchars(e, goods)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();

// check goodkeys
if (goods.indexOf(keychar) != -1)
	return true;

// control keys
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   return true;

// else return false
return false;
}



function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function
  

//Email Validation
function emailValid(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function formSubmit(form, act){
	document.forms[form].action = act;
	document.forms[form].submit();
}

function fieldOb(field_name){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field;
}

function changeRowColor(row, color){
	rOb = fieldOb(row);
	rOb.bgColor = color;  
}

//Validates a field
function ValidateField(elem, name){
	if((elem.value == ''))	{ // ||(elem.value == 0)
			alert('Warning: Not all mandatory fields (*) have been filled!');
    		elem.focus();
   	 		return(false);
   	}
	else if(name.indexOf('Email') != -1){
			 	if(!emailValid(elem.value)){
					alert('Invalid E-mail address !');
					elem.focus();
   	 				return(false);
				}
	}
	return(true);
}

//Just Validates a field without (alert & focus)
function JustValidateField(elem){
	if((elem.value == '')||(elem.value == 0))	return(false);
	else if(name.indexOf('Email') != -1){
			 	if(!emailValid(elem.value)){
   	 				return(false);
				}
	}
	return(true);
}


//Validate form for Mandatory fields to be filled properly
function Validate(form, fields){
   	mandatory_fields = fields.split(',');
	for(i=0; i<mandatory_fields.length; i++){
		
		if(mandatory_fields[i].indexOf('|')){
			//groupped fields (at least one of them must be filled/selected)
			mandatory_group_fields = mandatory_fields[i].split('|');
			valid = 0;
			for(j=0; j<mandatory_group_fields.length; j++){
				elem = eval('form.' + mandatory_group_fields[j]);
				if(ValidateField(elem, mandatory_group_fields[j]) ) valid = 1;
				else return(false);
			}
			if(!valid){
				//no fields filled
				elem = eval('form.' + mandatory_group_fields[0]);
				if(!ValidateField(elem, mandatory_group_fields[0])) return(false);
			}
			
		}else{
			//single field
			elem = eval('form.' + mandatory_fields[i]);
			if(!ValidateField(elem, mandatory_fields[i])) return(false);
		}
		
	}//for
	return(true);
}

//Login Form Check
function checkLogin(form){
   	if(form.login_user.value == '')	{
    		alert('Insert Username');
    		form.login_user.focus();
   	 	return(false);
   	}
   	if(form.login_pass.value == '')	{
    		alert('Insert Password');
    		form.login_pass.focus();
   	 	return(false);
   	}
	return(true);
}

function checkFormPass(form){
   	if(form.pass_veche.value == '')	{
    		alert('Enter current password!');
    		form.pass_veche.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_1.value == '')	{
    		alert('Enter new password!');
    		form.pass_noua_1.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_2.value == '')	{
    		alert('Reenter new password!');
    		form.pass_noua_2.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_1.value != form.pass_noua_2.value)	{
    		alert('Error! You have reentered a different new password!');
    		form.pass_noua_1.focus();
   	 	return(false);
   	}

	return(true);
}

function hide_er(){
	ob = fieldOb('tab_er');
	ob.style.display = "none";
}

function GotoPage(pag, GET){
	form = eval("document.forms['frms']");
	form.action = PHP_SELF + "?"+GET+"&pag="+pag;
	form.submit();
}

function changeBg(color,where){
	ob = new fieldOb(where);
	ob.style.backgroundColor = color;
}

function LoadEditor(txtName) {
	var oFCKeditor = new FCKeditor(txtName) ;
	oFCKeditor.BasePath = "_layouts/_editor/" ;
	oFCKeditor.Height = 300;
	oFCKeditor.Width = 550;
	oFCKeditor.ToolbarSet = 'Default';
	oFCKeditor.ReplaceTextarea();
}

function SelectBoxes(type, ids){
	arr_ids = ids.split(',');
	for(i = 0; i < arr_ids.length; i++){
		x = MM_findObj('select_' + arr_ids[i]);
		if (x) if (type=='all') x.checked = true; else x.checked = false;
	}
}

function DeleteMultiple(what) {
	document.forms['frm'].action = what; 
	document.forms['frm'].submit();	
}

function SiteSearch(){
	search_url = HTTP + 'auctions/browse_auctions/clear/';
	keyword = document.forms['form_search'].keyword.value;
	if(keyword == '') alert('Please enter your keyword');
	else{
		search_url += 'keyword=' + keyword;
		document.location = search_url;
	}
}

function changeRowBG(row, bg){
	rOb = fieldOb(row);
	//rOb.style.background = 'url('+HTTP+'_layouts/images/site_header_click_09.jpg)';
	rOb.style.background = 'url('+HTTP+'_layouts/images/' + bg + ')';
}




function Action(actionlink){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Please install the newest version for your browser!");
	  return;
	} 
	
	var url=HTTP + actionlink;
	url=url + "/sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=getDiv;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function GetXmlHttpObject(){
	var xmlHttp=null;
	try { xmlHttp=new XMLHttpRequest(); }
	catch (e) {
	  try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function getDiv(){
	if (xmlHttp.readyState==4){
		response=xmlHttp.responseText;	
		var update = new Array();
		update = response.split('|~@*!|');
		//alert(response);
				
		/*if(ie && (document.forms['formAssign'] != null)){
			document.forms['formAssign'].cc_type.className = 'comboclass';
			document.getElementById("combo").className = 'comboclass2';
		}
		if(update[0] != 'null') document.getElementById("perdea").innerHTML = update[0];
		else {
			document.getElementById("perdea").innerHTML = '';
			document.getElementById("perdea").style.display = 'none';
			if(ie && (document.forms['formAssign'] != null)){
				document.forms['formAssign'].cc_type.className = 'comboBox1';
				document.getElementById("combo").className = '';
			}
		}
		document.getElementById("perdea").style.display = 'inline';*/
		
		len = update.length;
		if(len > 1){
			var i;
			for(i = 1; i < len; i++)
				if(i % 2 != 0) {
					if(update[i] == 'getdesc'){
						mypic = fieldOb("description");
						mypic.innerHTML = update[i + 1];
					}
				}
		}
	}
}
function showHideTable(tb_name){
	ob = fieldOb(tb_name);	
	if(ob.className == '') ob.className = 'ascuns';
	else ob.className = ''; 
}

function BookHotel(id, ref){
	popup(HTTP+'book_hotel/'+id+'/', 900, 700, 'yes');
}

function BackMain(){
	document.getElementById("perdea").innerHTML = '';
	document.getElementById("perdea").style.display = 'none';
}