//add..............
$(document).ready(function(){


tab();
//stopsubmit();
editmenuother();
fefilepreviewimg();
selectTOinput();
//popup();
/**/
$('.bgmask').click(function(event) {
	      //$('.bgmask').hide();
           // $('.popcontent').hide();
		     $(this).hide();//bgmask
             $(this).prev().hide();

});
$('.popclose,.popclosebelow').click(function(){

   $(this).closest('.popcontent').hide();
    $('.bgmask').hide();

});


	$('.formtabhovertr tr').hover(function(){
	   $(this).addClass('hovertr');
	},function(){
	    $(this).removeClass('hovertr');
	});

$('.needpopup').click(function(e) {
	 e.preventDefault();
	  //alert($(this).attr('href'));
	 popupneed($(this).attr('href'));
	 return false;
});



$('.clicknextshow').click(function(event) {
	 $(this).next().toggle();//slideToggle
});

if($('.iframeparentlink')){
var src = $(window.parent.document).find("#iframepage").attr('src');
$('.iframeparentlink').attr('href',src);
}


jscopyblockid();
//---------end ready----------------------------------------
}); //end ready



function jscopyblockid(){
	$('.jscopyblockid').click(function () {
		 var v = $(this).prev().text();
		//alert(v);
		clipboard.writeText(v);
	})
	 

}



function selectTOinput(){
	 $('.selectTOinput select').change(function(){
	       var optionv = $(this).children('option:selected').val();
		   //console.log(optionv);
		   $(this).parent().children('input').val(optionv);
	 });

}


function fefilepreviewimg(){
	 $('.fefilepreviewimg .img1').hover(function(){
	  $(this).next().show();
	},function(){
	   $(this).next().hide();
	});

}
function editmenuother(){
		   $(".editmenuother").click(function(){
			  $(".editmenuother_cnt").slideToggle();
			});
}

function stopsubmit(){
     $('input[type=submit]').click(function(){

       // alert(0);

     });
}//end func



function tab(){
$(".tab span").click(function(){
thisindex =$(this).index()+1;
$(".tab span").toggleClass('cur');
$(".tabarea>div").hide();
$(".tabarea .tab"+thisindex).show();


});
//
}//end func




function SeIframeHeight() {
		var iframeHeight = $("#iframepage").contents().find("body").height()+100;
        $("#iframepage").height(iframeHeight);
}
 

 function  confirmaction(action,ifdel,backurl,textv){
        if(ifdel=='del') var textv ='<span style="color:red"> '+title + '</span> <br />确定删除?不能恢复! ';
	    backurl = backurl+'&act='+action;
		popupconfirm(textv,backurl);

}

 

function  del(actgo2,pidname,backpage,title){
    //if (confirm("确定删除?不能恢复")){
      golink  = backpage+'&act='+actgo2+'&pidname='+pidname;
	var textv ='<span style="color:red"> '+title + '</span> <br />确定删除?不能恢复! ';
		popupconfirm(textv,golink);
}
function  del2(actgo2,pidname,pidname2,backpage){  //when del region sub
    //if (confirm("确定删除?不能恢复")){
      golink  = backpage+'&act='+actgo2+'&pidname='+pidname+'&pidname2='+pidname2;
	//alert(golink);
      // window.location=golink;
    //}
	var textv ='确定删除?不能恢复!';
		popupconfirm(textv,golink);
}
function  delid(actgo2,id,backpage,title){
    //if (confirm("确定删除?不能恢复")){
      golink  = backpage+'&act='+actgo2+'&tid='+id;
	//alert(golink);
      // window.location=golink;
    //}
	var textv ='<span style="color:red"> '+title + '</span> <br />确定删除?不能恢复! ';
		popupconfirm(textv,golink);

}

function  comfirmid(actgo2,id,backpage,title){
    //if (confirm("确定删除?不能恢复")){
      golink  = backpage+'&act='+actgo2+'&tid='+id;
	//alert(golink);
      // window.location=golink;
    //}

	var textv ='<span style="color:red;font-size:25px"> '+title + '</span>   ';
		popupconfirm(textv,golink);

}


function  delimg(actgo2,tid,imgv,backpage){
    //if (confirm("确定删除?不能恢复")){
     golink  = backpage+'&act='+actgo2+'&tid='+tid+'&v='+imgv;//imgv no use
	//alert(golink);
      // window.location=golink;
   // }
	var textv ='确定删除?不能恢复!';
	 popupconfirm(textv,golink);

}

function  delnew(name,link){
     var textv ='<span style="color:red"> '+name + '</span> <br />确定删除?不能恢复! ';
	 popupconfirm2(textv,'linkdo',link);

}



function  isnum(v){  //alert(v);
    if(!isNaN(v)){return true;
  			// alert("是数字");
		}
	else{return false;
		   //alert("不是数字");
		}

	/*
	    var pos=thisForm.pos.value;
    //正则表达式，需要注意的是这里并没有引号，而是用//
    var reg=/^[0-9]*$/;
    if(!reg.test(pos)){
	   alert("pos必须是数字");
		thisForm.pos.focus();
		return (false);

   }
   */

}

// gosele
function gosele(sobj,can,jumpv) {
	var thevalue =sobj.options[sobj.selectedIndex].value;
	if (thevalue != "") {
	//alert(docurl);
	var gov =  jumpv+can+'='+thevalue;
	//alert(gov);
	 location.href=gov;
	  // open(docurl,'_blank');
	  // sobj.selectedIndex=0;
	  // sobj.blur();
	}
}




function popupneed(iframeSrc){
	if(iframeSrc=='') var iframeSrc = '../mod_common/iframeblank.php';
	 $('#popiframe').attr('src',iframeSrc);
	 popup_go('need','.popcontent');
 }

 function popupconfirm(textv,linkv){
 	textv='<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>'+textv;
     $('.popconfirm1 .popcontentinc p').html(textv);
	 $('.popconfirm1 .link a').attr('href',linkv);

	 popup_go('confirm','.popconfirm1');

  //alert(opentext);
  //var opentext2 = '<div class="message popcontentconfirm"><span class="h3hd">确定操作吗？</span><p><span style="color:red"><i class="fa fa-exclamation-circle"></i> 如果取消</span>，请点击右上角关闭窗口。<span class="link"><a href="'+linkv+'" class="but2"><i class="fa fa-trash-o"></i> 确定删除</a></span></p></div>';
 // $.fancybox.open(opentext2);
  // $.fancybox.open('<div class="message"><h2>Hello!</h2><p>You are awesome!</p></div>');

 }

  function popupconfirm2(name,type,link){
  	//use ck img del...
  	 
  	if(name=='')  v='确定删除？删除后不能恢复。';
  	else v=name;

  	v='<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>'+v;

  	 if(type=='jsdo') $('.popconfirm2 .pop_jsdo').show();
  	 if(type=='linkdo') {
  	 	 $('.popconfirm2 .pop_linkdo').show();
  	 	 $('.popconfirm2 .link a').attr('href',link);
  	 }

     $('.popconfirm2 .popcontentinc p').html(v);
	 
	 popup_go('confirm2','.popconfirm2');
 
 }



function popup_go(type,v){
   popupName = $(v);
 var _scrollHeight = $(window).scrollTop(),
     _windowH = $(window).height(),
     _windowW = $(window).width(),
     _popupH = popupName.height(),
     _popupW = popupName.width()+40;

     if(type=='confirm')  _posiTop = (_windowH - _popupH)/2 + _scrollHeight;
	 else   _posiTop = _scrollHeight+50;

	 // console.log('_scrollHeight:'+_scrollHeight);
	 // console.log('_windowH:'+_windowH);
	 // console.log('_popupH:'+_popupH);
	 // console.log('_posiTop:'+_posiTop);

    // if(type=='confirm') _posiTop = _posiTop-150;

	//if(type=='confirm') _posiTop = 100;
	//else _posiTop = 50;



     _posiLeft = (_windowW - _popupW)/2+10;
 popupName.css({"left": _posiLeft + "px","top":_posiTop + "px"});

  bgH = $(document).height();
  $('.bgmask').css({height:bgH+'px'});

			if(type=='need')   {
					$('.bgmaskneed').show();
					$('.popcontentneed').show();
			}
			if(type=='confirm')   {
					$('.bgmaskconfirm1').show();
					$('.popconfirm1').show();
			}
			if(type=='confirm2')   {
					$('.bgmaskconfirm2').show();
					$('.popconfirm2').show();
			}




}


//add..............
$(document).ready(function(){
   
   if($('body').width()>800)  {
	   
  xiala_show(); 
  
   }
   else {
	    xiala_showmobile(); 
		
   }
   
	 
	 treearr_select();  
	 treearr_catelist();
	 treenodeeditcate();
	  
	 jscopytoalias();
//---------end ready----------------------------------------
}); //end ready


function xiala_show(){
$(".navblock").hover(
	  function () {  
		//$(".navlang ul").addClass("hover");
		$(this).children(".xialabox").show();
	  },
	  function () {
		//$(".navlang ul")removeClass("hover");
		$(this).children(".xialabox").hide();
	  }
	);
//
}//end func


function xiala_showmobile(){
	
$(".navdm_mob .navbar-toggle").click(function(){
  $(".navdm").slideToggle();
});

 
}//end func

function treearr_catelist(){
	
 $('.treearr_catelist li .line').hover(function(){ $(this).addClass('bghover');},function(){$(this).removeClass('bghover');});
   $('.treearr_catelist li .line').last().addClass('lastline');
 
}//end func



function treearr_select(){
	
$(".jstreearr_select span").click(function(){ 


//------------------- 
        var idv = $(this).attr('id');
		canclickname = true;
		//------hasmulticate---cureditparent--------- 
		if($('.hasmulticate').length){
				if($('.cureditparent').length){
				$('.cureditparent  span').each(function(){
					if($(this).attr('id')==idv)  {
						alert('出错，不能选择 当前级 或 子级 为 父级。');
						canclickname = false;
						return false;	
 						
					}
				  }); 
				}
		}		
		//---------------nomulticate-----
		if($('.nomulticate').length){			
			if($('.activecur').next().hasClass('tree')){
				alert('出错，当前级 还有子级，请先移走它的子级。');
				canclickname = false;
				return false;
			}
			if($(this).hasClass('level_2')) {
				alert('因为这是最后一级，所以不能选择它为父级。');
				canclickname = false;
				return false;
			}
		}
		//-----------------
		//alert(idv);
		//alert(canclickname);
	 if(canclickname){
		  $('.mysubmit').show();
		var namev = $(this).text();
		$('.treearr_select_input').val(idv);
		$('.treearr_select_input_catename span').text(namev);
	 }else { 
	    $('.mysubmit').hide();
	 }
	 
		 
});
//--------
$(".treearr_select_go").click(function(){  
         $(".treearr_select").slideToggle();
});
 
 
}//end func

//----------- 

function treenodeeditcate(){	
 
$(".treenodeeditcate input").click(function(){ 
   var parid =  $(this).data('parid');
   // console.log(parid);
   v = false; 
 $(this).parent().parent().siblings().find('input').each(function(){ 
		 if($(this).is(':checked')) v = true;		 
				 
	});
	 
	 
   if(!v) {
	     if($(this).is(':checked'))  treenodeeditcate2(parid,true);
		 else   treenodeeditcate2(parid,false); 
   }
});
     
 
 
}//end func

 


function treenodeeditcate2(curid,beal){ 
         
	 $(".treenodeeditcate input").each(function(){	
         	 
		 if($(this).val() == curid) {   //console.log(curid);
			  $(this).prop("checked", beal); 
				var parid =  $(this).data('parid');
				 treenodeeditcate2(parid,beal);
				
		 } 	
	});

 
}//end func

function jscopytoalias(){ 
	$('.jscopytoalias').click(function(){
	 
		v = $('.copytoaliasfrom').text().toLowerCase();
		$('.copytoaliasto').val(v);
	});
}//end func

