function Set_Image_Src(id_img,src_img)
{
	$('#'+id_img).attr("src",src_img);
}

function Clear_Input(id_input,default_value)
{
	if($('#'+id_input).val() == "")
		$('#'+id_input).val(default_value);
	else if($('#'+id_input).val() == default_value)
		$('#'+id_input).val("");
}

function Modal_Message(message) {
	$('#modalmessage').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'modalmessage-overlay',
		containerId:'modalmessage-container', 
		overlayClose:true,
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);
		}
	});
}

function count( mixed_var, mode ) {
    // Count the number of elements in a variable (usually an array)  
    // 
    // version: 812.316
    // discuss at: http://phpjs.org/functions/count
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Waldo Malqui Silva
    // *     example 1: count([[0,0],[0,-4]], 'COUNT_RECURSIVE');
    // *     returns 1: 6
    // *     example 2: count({'one' : [1,2,3,4,5]}, 'COUNT_RECURSIVE');
    // *     returns 2: 6
    var key, cnt = 0;

    if( mode == 'COUNT_RECURSIVE' ) mode = 1;
    if( mode != 1 ) mode = 0;

    for (key in mixed_var){
        cnt++;
        if( mode==1 && mixed_var[key] && (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object) ){
            cnt += count(mixed_var[key], 1);
        }
    }

    return cnt;
}

function explode (delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}


function Modal_Loading() {
	$.modal(
			'<img src="images/loadingAnimation.gif">',
			{
				opacity:50,
				overlayCss: {backgroundColor:"#eeeeee"}
			}
			);
}

function Modal_Close() {
	
	$.modal.close();
}

function Select_Checkbox_All(selectbox_name)
{
	$('input[name='+selectbox_name+']').attr('checked', true);
}

function UnSelect_Checkbox_All(selectbox_name)
{
	$('input[name='+selectbox_name+']').attr('checked', false);
}

function isValidEmail(email)
{
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if(!filter.test(email))
    return false;
  return true;
}

function validateEmail(){
	if (regexEmailValidate('sender_email'))
		hideWarning('error_email');
	else {
		setWarning('error_email', 'Please enter a valid e-mail address.');
		return false;
	}
}

function existsInSelectBox(selectbox_id,option_value) {
	if($("#"+selectbox_id+" option[value='"+option_value+"']").length > 0)
			return true;
	return false;	
}


function CheckHierarchy(parent_categories, prename)
{
	var parents = [];
	parents=explode(',',parent_categories);
	for(var i=0;i<count(parents)-1;i++)
	{
		var theElement=document.getElementById(prename+parents[i]);
		if( (theElement!=null) && (theElement.checked==false))
		theElement.checked=true;
	}
}
