//var triggerMCE= false;
vs = {
	get:function(act, id) {
	
	(jQuery("div[id]").each(function(){
		if(this.id.indexOf('subForm')!= -1)
			jQuery("#"+this.id).html('');
	}));
	//********************************************
	var params = { vs: act, ajax:1};

		if(!noimage && id!='')
			jQuery("#"+id).html('<img src="'+imgurl+image+'"/>');
		
		jQuery.get(ajaxfile,params,function(data){
			if(id!='') {
				if(ajaxfile=='admin.php')
				{
					jQuery("#"+id).html(data).css('display','none').fadeIn('slow');
					jQuery('#obj_tabs').tabs();
				}else
				{
					jQuery("#"+id).html(data);
				}
			}
		});
	},

	submitForm:function(obj,act,id) {
		if(typeof(tinyMCE) != "undefined") tinyMCE.triggerSave();

		jQuery("#"+id).html('<img src="'+imgurl+'loader.gif"/>');
		var params = {
			vs:act,
			ajax: 1
		};
		
		var count = 0;
		obj
		.find("input[type='radio']:checked, input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
		.each(function() {
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		$.post(ajaxfile,params,function(data) {
			if(ajaxfile=='admin.php')
			{
				jQuery("#"+id).html(data).css('display','none').fadeIn('slow');
				jQuery('#obj_tabs').tabs();
			}else
			{
				jQuery("#"+id).html(data);
			}
		});
	},
	
	upload:function(act_add_image, name_filed_image){
		var data, errorMessage="";
		$.ajaxFileUpload
		(
			{
				url: "admin.php?vs=products/addimage/&ajax=1",
				secureuri: false,
				fileElementId : 'file_0',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							errorMessage = errorMessage + data.error;
							alert(errorMessage);
						}
						else	alert("s");
					}
				},
				error: function (data, status, e)
				{
					alert(errorMessage);
					errorMessage = errorMessage + e;
				}
			}
	);	
		
		return errorMessage;
	},
	
	isDefined:function(obj) {
    	return (typeof(obj) == "undefined")?  false: true;
	},
	
	removeForm:function(id){
		jQuery("#"+id).html('');
	},
	select_switch:function (status ,object) {
		if(!object)
			return;
		for (i = 0; i < object.length; i++) {
			object.elements[i].checked = status;
		}
	},
	
	checkbox:function (the_value,the_list){
		if(!the_list)
			return;
		if (the_value==the_list.value){
			the_list.checked=true;
			return true;
		}
	},	
	radio:function (the_value,the_list){
		if(!the_list)
			return;
		var name_count = the_list.length;	
		for (i=0;i<name_count;i++){
			if (the_value==the_list[i].value){
				the_list[i].checked=true;
				return true;
			}
		}
	},	
	select:function (the_value,the_list){
		if(!the_list)
			return;
		var option_count = the_list.options.length;	
		for (i=0;i<option_count;i++){
			if (the_value==the_list.options[i].value){
				the_list.options[i].selected=true;
				return true;
			}
		}
	}
}
