/*--------------------------------------------------------------------------*/
/* chenge image size for default
/*--------------------------------------------------------------------------*/
function changeImageSize(id, neededSize)
{
	var imgObj = document.getElementById(id);
	var imageWidth = imgObj.width;
	var imageHeight = imgObj.height;
	var coefficient = '1';

	if (imageWidth > neededSize) {
		coefficient = neededSize/imageWidth;
	}
	if (imageHeight > neededSize) {
		coefficient = neededSize/imageHeight;
	}
	imageWidth = imageWidth*coefficient;
	imageHeight = imageHeight*coefficient;

	document.getElementById(id).width = imageWidth;
	document.getElementById(id).height = imageHeight;
}

/*--------------------------------------------------------------------------*/
/* 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.body.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;
}



/*                                     
Make highlighted  row
*/
function markPreview(element_id){

	$("row"+element_id).className = "altRowMark";
	$("img"+element_id).style.background = "#e9e9e9";
}

/*                                     
clear highlighted  row
*/
function clearPreview(element_id, set_class){

	$("row"+element_id).className = set_class;
	$("img"+element_id).style.background = "";
}


/*                                     
Repalce innerHTML Text  
*/
function changePreview(fieldName, caller){
	if ($(fieldName)) {
		$(fieldName).innerHTML = caller.value;
	}
}


/*                                     
Repalce innerHTML Text  
*/
function breakProcessIfNoSelected(element_id) {

	var $selected_array = getSelectedById(element_id);
	var element_value = $selected_array["value"];
 	
	if(element_value==0) {
		alert("Please Select Ad");
		return false;
	}

	return true;
}
