

var changes=0;

function setfancy() 
{

			$j("a.zoom").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF',
				'hideOnContentClick': false,
				 'frameWidth':625,
   				'frameHeight':455,
				callbackOnClose:function(){CSBfleXcroll('mycustomscroll');setfancy();tinyMCE.execCommand('mceRemoveControl',false,'headline');tinyMCE.execCommand('mceRemoveControl',false,'content');tinyMCE.execCommand('mceRemoveControl',false,'text');	
				if(changes==1){window.location.reload();}}
				
			});

			$j("a.zoom2").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF',
				'hideOnContentClick': false,
				 'frameWidth':370,
   				'frameHeight':180,
				callbackOnClose:function(){CSBfleXcroll('mycustomscroll');setfancy();tinyMCE.execCommand('mceRemoveControl',false,'headline');tinyMCE.execCommand('mceRemoveControl',false,'content');tinyMCE.execCommand('mceRemoveControl',false,'text');	
				if(changes==1){window.location.reload();}}
				
			});
			
			$j("a.zoom3").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF',
				'hideOnContentClick': false,
				 'frameWidth':370,
   				'frameHeight':350,
				callbackOnClose:function(){CSBfleXcroll('mycustomscroll');setfancy();tinyMCE.execCommand('mceRemoveControl',false,'headline');tinyMCE.execCommand('mceRemoveControl',false,'content');tinyMCE.execCommand('mceRemoveControl',false,'text');	
				if(changes==1){window.location.reload();}}
			
			});
			
			$j("a.zoom4").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF',
				'hideOnContentClick': false,
				 'frameWidth':500,
   				'frameHeight':420,
				callbackOnClose:function(){CSBfleXcroll('mycustomscroll');setfancy();tinyMCE.execCommand('mceRemoveControl',false,'headline');tinyMCE.execCommand('mceRemoveControl',false,'content');tinyMCE.execCommand('mceRemoveControl',false,'text');	
				if(changes==1){window.location.reload();}}
			

})};
$j(document).ready( function() { 
	

		setfancy();
		if($j('.green_box').attr("class")=="green_box")
		{
			setColor();
		}		
		
		var object;
		
		$j("#sddm ul li a ").mouseover( function() {
			
			object=$j("#sddm ul li a.active"); 
			
			object.removeClass("active");
			
			$j(this).addClass("active");
			
		});
		
		$j("#sddm ul li a").mouseout( function() {
			
			$j(this).removeClass("active");
			
			object.addClass("active");
		});
		
		$j("#m1 ,#m2 ,#m3 ,#m4 ,#m5").mouseover( function() {
			
			$j("#sddm ul li a").removeClass("active");
			
			var id=	$j(this).attr("id");
			
			temp=id.split("m");
			
			id=temp[1];
			
			$j("#li_"+id+" a:first").addClass("active");
			
		});
		
		$j("#m1 ,#m2 ,#m3 ,#m4 ,#m5").mouseout( function() {
			
			$j("#sddm ul li a").removeClass("active");
			
			object.addClass("active");
			
		});

	var extended=false;
	
	$j("#slider-button").click( function() {
		
		if(!extended) {
			$j("#slider-div").animate({width: [180, 'swing']},800);
			extended=true;
		}
		else {
			$j("#slider-div").animate({width: [30, 'swing']},800);
			extended=false;
		}
		
	});
		
		
		
});

function setTinySimple()
{
	
tinyMCE.init({
		// General options
		
		mode: "textareas",
		
    	editor_selector:"simple_editor",
    	
		theme : "advanced",
		
		plugins : "safari",
 
		// Theme options
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
		
		theme_advanced_buttons1 : "fontselect,fontsizeselect,bold,italic,underline,bullist,numlist,outdent,indent,link,removeformat",
		
		theme_advanced_toolbar_location : "bottom",
		
		theme_advanced_toolbar_align : "left",
		
		theme_advanced_resizing : false,
		
		auto_reset_designmode : true,
		
 		width : "300",
 		
 		height : "100"
		// Drop lists for link/image/media/template dialogs
		
});

}


function setTinyAdvanced() 
{
	
	tinyMCE.init({
		
		mode: "textareas",
		
    	editor_selector:"advanced_editor",
    	
		theme : "advanced",
 
		// Theme options
		plugins : "filemanager,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
		
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect,moveforward,movebackward,absolute,",

		theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,image,code,|,forecolor,backcolor",

		theme_advanced_buttons3 : "tablecontrols,|,removeformat,|,sub,sup,|,charmap,iespell,media,advhr,|,print,",

		theme_advanced_toolbar_align : "left",

		theme_advanced_toolbar_location : "top",
		
		theme_advanced_toolbar_align : "left",
		
		theme_advanced_resizing : false,
		
		auto_reset_designmode : true,
		
	
 
		// Example content CSS (should be your site CSS)

 		width : "400",
 		
 		height : "300"
 		
		// Drop lists for link/image/media/template dialogs
		
	});
}

function setTinyExtraSimple()
{
	
tinyMCE.init({
		// General options
		
		mode: "textareas",
		
    	editor_selector:"extra_simple_editor",
    	
		theme : "advanced",
		
		plugins : "safari",
 
		// Theme options
		
		plugins : "safari,paste,nonbreaking,xhtmlxtras,wordcount",
		
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough",
		
		theme_advanced_toolbar_location : "bottom",
		
		theme_advanced_toolbar_align : "left",
		
		theme_advanced_resizing : false,
		
		auto_reset_designmode : true,
		
 		width : "480",
 		
 		height : "50"
		// Drop lists for link/image/media/template dialogs
		
});

}

function reload() {

	$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=reload&id="+$j("#current").val(),
			
			success: function(data) 
    		{	
    			
    			temp=data.split(";;;");
    			$j("#text_header").attr("src",temp[0]);
    			$j("#content").html(temp[1]);
    			$j("#testimonial_widget").css("display",(temp[2]=="1"?"inline":"none"));
    			$j("#more_info").css("display",(temp[3]=="1"?"block":"none"));
    			CSBfleXcroll('mycustomscroll');
    			
    			
    			setfancy();
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
});			
	
}

function closefancy() {

	$j.fn.fancybox.close();

}

function  IsEmail(email) 

{


	var reg = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$j/);
  
   
   
   if(reg.test(email) == false) 
   
   
   {
   	
   	
      return false;
      
      
   }
   
   
   return true;
   
   
}

function check_email (data)

{
	var re = new RegExp("successfully", "gi");
	
  if (data.match(re)) {
    return true;
  } else {
    return false;
  }
	
}



function logout()
{

	$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=logout",
			
			success: function(data) 
    		{	
    			
    			window.location.reload();
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});	
}


function setinfo(id){
	
	$j("#name").val($j('.span_'+id).html());
	
	$j("#submenu_id").val(id);
	
	$j("#submit").val("Save");
}

function clear_selected() {
	
	$j("#name").val("");
	
	$j("#submenu_id").val("");

	$j("#submit").val("Add");
}	
	

function delete_page(id) {
	
	if(confirm("Do you really want to remove this page ?"))
	{
		$j.fn.fancybox.showLoading();
		
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=delete_page&id="+id,
			
			success: function(data) 
    		{	
    			
    			changes=1;
    			
    			$j('#order_list').html(data);
    			
    			$j("#fancy_loading").hide();
    			
    			 set_page_order();
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});	
	}
}
	

function set_page_order() {

	        $j("#order_ul").sortable({ opacity: 0.6, cursor: 'move', update: function() 
            {
            	
            $j.fn.fancybox.showLoading();
            
			var order = $j(this).sortable("serialize") + '&action=order_submenu'; 
			
			$j.post("libs/ajax.php", order, function(theResponse){changes=1;$j("#fancy_loading").hide();}); 	
																	 
			}								  
			});
}

function SetLang(obj)
{
	object_class=obj.className;
	
	name=object_class.split("lang");
	
	id=name[1];
	
	if($j('.'+object_class).is(':checked')){
	checked=1;
	$j('#link'+id).removeClass("lang_hidden");
	}
	else {
	checked=0;
	$j('#link'+id).addClass("lang_hidden");
	}
	
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=set_lang&id="+id+"&checked="+checked,
			
			success: function(data) 
    		{	
    			
    			//window.alert(data);
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});	
	
}

function delete_page(id) {
	
	if(confirm("Do you really want to remove this page ?"))
	{
		$j.fn.fancybox.showLoading();
		
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=delete_page&id="+id,
			
			success: function(data) 
    		{	
    			
    			changes=1;
    			
    			$j("#order_list").html(data);
    			
    			$j("#fancy_loading").hide();
		
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});	
	}
}

function setColor() {
	
content = GetHex($j('.green_box').css('backgroundColor'));

$j('div #colorSelector').ColorPicker({
	color: "#"+content,
	onShow: function (colpkr) {
		$j(colpkr).fadeIn(500);
		return false;
	},
	onHide: function (colpkr) {
		$j(colpkr).fadeOut(500);
		return false;
	},
	onChange: function (hsb, hex, rgb) {
		$j('.green_box').css('backgroundColor', '#' + hex);
	},
	onSubmit: function (hsb, hex, rgb) {
		
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=change_color&id="+$j("#current").val()+"&color="+hex+"&lang="+$j("#lang").val(),
			
			success: function(data) 
    		{	
					
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});		
	}
});

}

function GetHex(color) {
var parts = color.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
// parts now should be ["rgb(0, 70, 255", "0", "70", "255"]

delete (parts[0]);
for (var i = 1; i <= 3; ++i) {
    parts[i] = parseInt(parts[i]).toString(16);
    if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
var hexString = parts.join('');	
return hexString;
}

function DeleteUser(id) {

	if(confirm("Are you sure that you want to delete this user ?"))
	
	{
		
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=delete_user&id="+id,
			
			success: function(data) 
    		{		window.alert(data);
					changes=1;
					closefancy();
					
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});				
		
	}
	
}

function validate_title() {

	var title=$j("#pagename").val();
	if(title.length<3)
	{
			$j("#pagename").focus();
			window.alert("Please use only letters and numbers( minimum 3 )");
			return false;
	}
	else {
		
			return true;	
	}
	
	
}

function switch_visibility() {
	
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=visibility",
			
			success: function(data) 
    		{		
    			data=data.split(";");
    			
    			id=data[1];
    			
    			if(parseInt(data[0])==1)
    			{
    				$j("#switcher").val("Show This Page");	
    				
    				$j("a#menu_"+id+", .prod_"+id).addClass("lang_hidden");
  
    			}
    			else {
    				$j("#switcher").val("Hide This Page");	
    				
    				$j("a#menu_"+id+", .prod_"+id).removeClass("lang_hidden");

    			}
					
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});	
			
}

function Delete_Item(id){

	if(confirm("Do you really want to delete this item ?")) {
		
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=delete_download_item&id="+id,
			
			success: function(data) 
    		{		
    			
				$j("#row_"+id).remove();
				
				closefancy();	
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});			
		
	}
}

function load_add_item(id) {
	
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Interface.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=load_add_item&id="+id,
			
			success: function(data) 
    		{		
    			
				$j("#download_items").html(data);
				
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});				
	
}

function load_edit_category(id) {
	
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Interface.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=load_edit_item&id="+id,
			
			success: function(data) 
    		{		
    			
				$j("#download_items").html(data);
				
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});				
	
}

function load_add_category() {

		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Interface.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=load_add_download_category",
			
			success: function(data) 
    		{		
    			
				$j("#download_items").html(data);
				
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});		
	
}


function delete_category(id) {
	
	if(confirm(" Do you want to delete this category ?")) {
		if(confirm("All subcategories will be deleted too! Do you still want to delete this category ?")) {
		$j.ajax({
			type:"GET",
			
			url:   "libs/ajax.Actions.php",
			
			contentType:   "text/html; charset=iso-8859-1",
			
			dataType:   "html",
			
			data: "action=delete_download_category&id="+id,
			
			success: function(data) 
    		{		
    			
				$j("#body_"+id).remove();
				
				closefancy();	
    			
   			},
   	
    		error: function (XMLHttpRequest, textStatus, errorThrown) 
    		{
    	
        		window.alert(XMLHttpRequest.responseText);
    		}
		});			
		}
	}	
}
