/****************************
* slide menu (left & right)
*****************************/
function ns_slide_left(setcookie)
{
	if (setcookie) setCookie('ns_slide_status',0);

	// change leftmenu and icon css class
	$('#ns_left').removeClass("ns_left_1");
	$('#ns_left').addClass("ns_left_0");
	$('#ns_mh_right div').removeClass("ns_mh_icon_1");
	$('#ns_mh_right div').addClass("ns_mh_icon_0");
	// hide menu header title
	$('#ns_mh_left').hide();
	// hide menu tabs title
	$('.ns_mt_left').hide();
}

function ns_slide_right(setcookie)
{
	if (setcookie) setCookie('ns_slide_status',1);

	// change leftmenu and icon css class
	$('#ns_left').removeClass("ns_left_0");
	$('#ns_left').addClass("ns_left_1");
	$('#ns_mh_right div').removeClass("ns_mh_icon_0");
	$('#ns_mh_right div').addClass("ns_mh_icon_1");
	// show menu header title
	$('#ns_mh_left').show();
	// show menu tabs title
	$('.ns_mt_left').show();
}

function ns_slide(status)
{
	var slide = getCookie('ns_slide_status');

	// if click on icon
	if (status==1)
	{
		if (slide==1)
		{
			ns_div_slide('ms','mt',2); ns_div_slide('as','mt',2); ns_div_slide('mis','mt',2);  ns_div_slide('qs','mt',2);
			ns_slide_left(1);
		}
		else
		{
			ns_div_slide('ms','mt',3); ns_div_slide('as','mt',3); ns_div_slide('mis','mt',3); ns_div_slide('qs','mt',3);
			ns_slide_right(1);
		}
	}
	// when document is ready
	else
	{
		if (slide==1) ns_slide_right();
		else ns_slide_left();

		$('#ns_left').show();
	}
}

/****************************
* slide tabs (up & down)
*****************************/
function ns_tab_down(id,slide,tab,style,cookie)
{
	if (cookie==1) setCookie('ns_'+id+'_status',1);
	if (slide==1) $('.ns_'+id+'_mc_tr').show();
	$('.ns_'+id+'_tr').show();
	$('#ns_'+id+' div').removeClass("ns_"+style+"_icon_0");
	$('#ns_'+id+' div').addClass("ns_"+style+"_icon_1");
}

function ns_tab_up(id,slide,tab,style,cookie)
{
	if (cookie==1) setCookie('ns_'+id+'_status',0);
	$('.ns_'+id+'_mc_tr').hide();
	$('.ns_'+id+'_tr').hide();
	$('#ns_'+id+' div').removeClass("ns_"+style+"_icon_1");
	$('#ns_'+id+' div').addClass("ns_"+style+"_icon_0");
}

function ns_div_slide(div,style,status)
{
	var slide = getCookie('ns_slide_status');
	var tab = getCookie('ns_'+div+'_status');

	// if click on icon
	if (status==1)
	{
		if (slide==1)
		{
			if (tab==1) ns_tab_up(div,slide,tab,style,1);
			else ns_tab_down(div,slide,tab,style,1);
		}
		else
		{
			if($(".ns_"+div+"_tr").attr('class'))
			{
				if (tab==1) ns_tab_up(div,slide,tab,style,1);
				else ns_tab_down(div,slide,tab,style,1);
			}
		}
	}
	// if click on hide slidemenu icon (<<)
	else if (status==2)
	{
		$('.ns_'+div+'_left').hide();
		$('.ns_'+div+'_title').hide();
		$('.ns_'+div+'_mc_tr').hide();
	}
	// if click on show slidemenu icon (>>)
	else if (status==3)
	{
		$('.ns_'+div+'_left').show();
		$('.ns_'+div+'_title').show();
		if (tab==1) $('.ns_'+div+'_mc_tr').show();
	}
	// when document is ready
	else
	{
		if (tab==1) ns_tab_down(div,slide,tab,style,0);
		else ns_tab_up(div,slide,tab,style,0);

		if (slide!=1) $('.ns_'+div+'_title').hide();
		if (slide!=1) $('.ns_'+div+'_left').hide();
		if (slide!=1) $('.ns_'+div+'_mc_tr').hide();
	}
}

/* Additional settings function */
function ns_click(param)
{
	if (param=='refresh')
	{
		parent.location='index.php';
	}
	if (param=='titles')
	{
		toggle_object_titles();
	}
	if (param=='logout')
	{
		$('#showModalDialogDivIframe').attr('src','admin/logout.php');
		jdc_hgray_show();
	}
	if (param=='back')
	{
		change_page('index_page');
	}
	if (param=='users')
	{
		change_page('user_register');
	}
	if (param=='layout')
	{
		change_page('layout');
	}
	if (param=='key')
	{
		change_page('meta_page');
	}
	if (param=='shop')
	{
		change_page('shop_settings_page');
	}
	if (param=='stats')
	{
		change_page('statistics_page');
	}
	if (param=='bme')
	{
		$('.ns_as_title span').css('font-weight','normal');
		$('#ns_bme_text').css('font-weight','bold');
		$('#ns_right').html('<form action=index.php id=page_change_form method=post><input name=page id=page_change_to type=hidden></form><iframe src=http://www.admi.lv/test/andrejs width=100% height=100% align=left frameborder=0></iframe>');
	}
	if (param=='teb')
	{
		$('.ns_as_title span').css('font-weight','normal');
		$('#ns_teb_text').css('font-weight','bold');
		$('#ns_right').html('<form action=index.php id=page_change_form method=post><input name=page id=page_change_to type=hidden></form><iframe src=http://admi.lv/test/andrejs/nob/bms/?id=126 width=100% height=100% align=left frameborder=0></iframe>');
	}
	if (param=='helpdoc')
	{
		window.open('http://www.admi.lv/index.php?site=help');
		return false;
	}
}

/* Quick settings bg change */
function ns_qs_bg_change(value)
{
	//alert(value);
	//return false;
	if (value==' ')
	{
		$('#page_border_table').css('background-image','none');
		$('#ns_back_clear').hide();
		$('#ns_back_repeat').hide();
		$('#ns_back_position').hide();
		$('#ns_back_clear_layout').hide();
		$('#ns_back_repeat_layout').hide();
	}
	else
	{
		$('#page_border_table').css('background-image',"url('"+value+"')");
		$('#ns_back_clear').show();
		$('#ns_back_repeat').show();
		$('#ns_back_position').show();
		$('#ns_back_clear_layout').show();
		$('#ns_back_repeat_layout').show();
	}

	ns_ajax('change_background_report','template','change','site_bg',value);
}

function ns_qs_bg_repeat(value)
{
	$('#page_border_table').css('background-repeat',value);
	ns_ajax('','template','change','site_bg_repeat',value);
}

function ns_qs_bg_position(value)
{
	$('#page_border_table').css('background-position',value);
	ns_ajax('','template','change','site_bg_position',value);
}


/*
ns_ajax('','newmenu','save','<?=$object['type'];?>');

*/

function ns_save_article(param1,param2,param3){
	//type,id
	
	var par = "module=newmenu&action=save";
	par += "&param1="+param1;
	par += "&param2="+param2;
	par += "&param3="+param3;

	//alert(par);

	$.ajax(
	{
		type: "POST",
		url: "index.php",
		data: par,
		beforeSend: function()
		{
			
		},
		success: function(html)
		{
			//alert(html);
			if(document.getElementById('type_flag_radio')!=null){
				//alert('Transferring shop settings!')
				if (document.getElementById('type_flag_radio').value=='product' ||
					document.getElementById('type_flag_radio').value=='oneliner' ||
					document.getElementById('type_flag_radio').value=='seminar')
				{
					if (document.getElementById('article_product_id_new_menu') && document.getElementById('article_product_id')) document.getElementById('article_product_id').value = document.getElementById('article_product_id_new_menu').value;
					if (document.getElementById('article_product_price_new_menu') && document.getElementById('article_product_price')) document.getElementById('article_product_price').value = document.getElementById('article_product_price_new_menu').value;
					if (document.getElementById('article_product_stock_new_menu') && document.getElementById('article_product_stock')) document.getElementById('article_product_stock').value = document.getElementById('article_product_stock_new_menu').value;
				};
			
				if (document.getElementById('type_flag_radio').value=='video')
				{
					//alert('Transferring video settings!')
					document.getElementById('article_video_file').value = document.getElementById('article_video_file_new_menu').value;
					document.getElementById('article_video_width').value = document.getElementById('video_width').value;
					document.getElementById('article_video_height').value = document.getElementById('video_height').value;
				};
			}
			checkTextFields();
			
			
			//В этой переменной храниццо - какую форму надо засубмитить - no eto sdelajem v SaveArea funkcii
			//alert('Must eval:'+param1);
			//eval(param1);
			//alert('Saving area: '+param2);
			saveArea(param2,param1);
			
			
			if(document.getElementById('ifrm3')!=null){
				sumbit_article(param2,param3);
				if ((document.getElementById('ifrm3').contentWindow.document.forms['extra_doc_upload'])!=undefined){
					document.getElementById('ifrm3').contentWindow.document.forms['extra_doc_upload'].submit();
				} else {
					//alert("extra_doc_upload is undefined!");
				}
			} else {
				//alert("ifr3 is null!");
			}
			
			
			
			
			
			/*
			if(document.getElementById('ifrm3')!=null){
				if (!document.getElementById('ifrm3').contentWindow.document.forms['extra_doc_upload'].submit()){
					sumbit_article(param2,param3);
				}
				document.getElementById('ifrm3').contentWindow.document.forms['extra_doc_upload'].submit();
			}
			*/
			
			
		}
	});
}

function ns_save_article2(param,param1,param2)
{
	//type,id
	var par = "module=newmenu&action=save";
	par += "&param1="+param1;
	par += "&param2="+param2;
	//alert(par);
	$.ajax(
	{
		type: "POST",
		url: "index.php",
		data: par,
		beforeSend: function() { },
		success: function(html)
		{
			alert(html);
			alert(param);
			eval(param);
		}
	});
}
/*
param:
1 - onmouseover
2 - onmouseout
3 - onclick
*/
function jdc_change_border(id,param)
{
	if (param==1)
	{
		$('#'+id).addClass('art_click');
	}
	else if (param==2)
	{
		if ($('#art_active').val()!=id)
		{
			$('#'+id).removeClass('art_click');
		}
	}
	else if (param==3)
	{
		if ($.browser.msie && $.browser.version.substr(0,1)=='6')
		{
			$('.jdc_border_div').css('border-color','#00044F');
			$('.jdc_border_div').css('filter','chroma(color=#00044F)');
		}
		else $('.jdc_border_div').css('border','1px solid transparent');
		
		$('#'+id).css('border','1px dotted red');
	}
	else if (param==4)
	{
		if ($.browser.msie && $.browser.version.substr(0,1)=='6')
		{
			$('#'+id).css('border-color','#00044F');
			$('#'+id).css('filter','chroma(color=#00044F)');
		}
		else $('#'+id).css('border','1px solid transparent');
	}
}
