/*--------------------------------------------------------------------------*/
/* Select and Focus  on object                                    
/*--------------------------------------------------------------------------*/

function selectText(obj) {
	obj.focus(); 
	obj.select();
}

/*--------------------------------------------------------------------------*/
/* Delete Confirmation Modal window                                    
/*--------------------------------------------------------------------------*/

function delRow() {
	return confirm("Delete, are you sure?");
}

/*--------------------------------------------------------------------------*/
/* copy Text To Clipboard for the IE ONLY                            */
/*--------------------------------------------------------------------------*/
function copyTextToClipboard(text) {
	if (window.clipboardData) {
		// Internet Explorer
		window.clipboardData.setData("Text", text);
		return true;
	} else {
		return false;
	}
}


/*--------------------------------------------------------------------------*/
/* Common '$' extensions                                                    */
/*--------------------------------------------------------------------------*/
function $F(element) {
	var value = $(element).getValue();
	if (typeof(value) == 'string') {value = value.trim();}
	return value;
}

function $show(element) {
//alert(element);
	return $(element).style.display = '';
}

function $hide(element) {
	return $(element).style.display = 'none';
}

function $toggle(element) {
    element = $(element);
	if (element.style.display == 'none') {
		return $show(element);
	} else {
		return $hide(element);
	}		
}

/*--------------------------------------------------------------------------*/
/* Hide/Show indicator functions
/*--------------------------------------------------------------------------*/
function showLoadingIndicator() {
	var top = document.documentElement.scrollTop ;
	$('loading_bar').style.top = top + 300 + "px";
	$show('loading_bar');
}

function hideLoadingIndicator() {
	$hide('loading_bar');
}

/*--------------------------------------------------------------------------*/
/* Send Ajax Request with the Form data                                     */
/*--------------------------------------------------------------------------*/
function SendFormByAjax(process, form_id, callback_func) {
   	showLoadingIndicator();
	var aj = new Ajax('process.php?process='+process, {
		method: 'post',
		data: $(form_id),
		onSuccess: function(o) {
			hideLoadingIndicator();
			var ret = Json.evaluate(o);  
   			callback_func(ret);
		},
		onFailure: function(o) {
			alert(Langs.ajax_error); //  o.status + o.statusText  
   			hideLoadingIndicator();
		} 
	}).request();
}


/*----------------------------------------------------------------*/
/* Send Ajax Request with the Form data                           */
/*----------------------------------------------------------------*/
function SendRequestByAjax(script_url, params, callback_func) {

   	showLoadingIndicator();
	var aj = new Ajax(script_url, {
		method: 'post',
		data: params,
		onSuccess: function(o){
			var ret = Json.evaluate(o);
			callback_func(ret);
		 	hideLoadingIndicator();
		},
		onFailure: function(o) {
			alert(Langs.ajax_error); //  o.status + o.statusText  
   			hideLoadingIndicator();
		} 
	}).request();

}

/*--------------------------------------------------------------------------*/
/* Load content into the block                                              */
/*--------------------------------------------------------------------------*/
function $ld(script_url, div_name){
	showLoadingIndicator();  
//	$(div_name).innerHTML = '' ;

	var AJ = new Ajax(script_url, 
		{update: $(div_name),
		method: 'get',
		onComplete: function(o) {hideLoadingIndicator();},
		onFailure: function(o) {
			alert(Langs.ajax_error);
   			hideLoadingIndicator();
		} 
		}).request();
}

/*--------------------------------------------------------------------------*/
/* get selected element data from dropdown menu                       		*/
/*--------------------------------------------------------------------------*/
function getSelectedById(elemID){

	var elem = document.getElementById(elemID);
	var selected_arr =[];

	if (elem) {
		for (var i=0; i < elem.length; i++) {
			if (elem.options[i].selected == true) {
				selected_arr['text']  = elem.options[i].text ;
				selected_arr['value'] = elem.options[i].value ;
  				return selected_arr;
			}
		}
	}
	return false;
}
/*--------------------------------------------------------------------------*/
/* Check login form fields                                                  */
/*--------------------------------------------------------------------------*/
function checkLoginField() {
     $('login_error').innerHTML = '';
     if(!$F('user_login')){
          $('login_error').innerHTML = "Please enter the Login";
          $('user_login').focus();
          return false;
     }

     if(!$F('user_password')){
          $('login_error').innerHTML = "Please enter the Password";
          $('user_password').focus();
          return false;
     }
     return true;
}
