//搜索框商品分类选中后时覆值

function select_t(id){
document.getElementById('tclassid').innerHTML = '第' + id + '类';
$("#tid").attr('value', id);
catalog.style.display = 'none';
}
function checkq(){
	if($("#tid").val()!='' && $("#q").val()=='请输入查询关键词...'){
	$("#q").attr('value','');
	}
	if(($("#q").val()=='请输入查询关键词...' || $("#q").val()=='') && $("#tid").val()==''){
		alert('请输入查询关键字');
		$("#q").focus();
		return false;
	}
	

}


function menu(){
	
	var lis=document.getElementById('other-nav').getElementsByTagName('li');
	var url=top.location.href.split('/');
	var str=url[url.length-1];
	var str1="";
	for(var i=0,j=lis.length;i<j;i++){

		str1=str.split('?');
		if(str1[0]=='auth.php' || str1[0]=='auth_view.php'){
			lis[1].className='on';
		}else if(str1[0]=='buy.php' || str1[0]=='buy_view.php'){
			lis[2].className='on';
		}else if(str1[0]=='trademark.php' || str1[0]=='trademark_view.php'){
			lis[3].className='on';
		}else if(str1[0]=='news.php' || str1[0]=='news_list.php' || str1[0]=='news_view.php'){
			lis[4].className='on';
		}else if(str1[0]=='user.php' || str1[0]=='user_account.php' || str1[0]=='user_auth.php' || str1[0]=='user_auth_add.php' || str1[0]=='user_auto.php' || str1[0]=='user_bbs.php' || str1[0]=='user_buy.php' || str1[0]=='user_buy_add.php' || str1[0]=='user_company.php' || str1[0]=='user_face.php' || str1[0]=='user_fav.php' || str1[0]=='user_feedback.php' || str1[0]=='user_info.php' || str1[0]=='user_notice.php' || str1[0]=='user_notice_view.php' || str1[0]=='user_pm.php' || str1[0]=='user_pwd.php' || str1[0]=='user_question.php' || str1[0]=='user_tm.php' || str1[0]=='user_tm_add.php' || str1[0]=='user_tm_batch.php' || str1[0]=='user_update.php'){
			lis[5].className='on';
		}else{
			lis[0].className='on';
		}

	}
}

$(document).ready(function() {
	menu();
	//顶部广告
	//var Len=$('#head_pic_change a').length;
	//oShow(Len);
	//window.setInterval('oShow('+Len+')',3000);


	//示例1，默认弹出层
	//new PopupLayer({trigger:"#tclassid",popupBlk:"#tlist",closeBtn:"a",offsets:{x:-400,y:7}});

	/*另一种效果
	var t4 = new PopupLayer({trigger:"#tclassid",popupBlk:"#tlist",closeBtn:"#close",closeBtn:"a",offsets:{x:-400,y:7},useFx:true});
	t4.doEffects = function(way){
		 way == "open"?this.popupLayer.slideDown("slow"):this.popupLayer.slideUp("slow");
	} 
	*/

});


//城市下拉菜单更改
function region_change(obj, region_type, selobj){

		$.ajax({
			type: "get",
			url: "/source/ajax.php?act=region&region_id=" + $.trim(obj.value) + "&region_type=" + region_type,
			data: "",
			dataType: 'json', //会把传回的值自动转成json对象
			beforeSend: function(XMLHttpRequest){
			//ShowLoading();
			},
			success: function(msg){


				var sel = document.getElementById(selobj);
				sel.length = 0;
				sel.selectedIndex = 0;


				for (i = 0; i < msg.length; i ++ ){
				  var opt = document.createElement("OPTION");
				  opt.value = msg[i].region_id;
				  opt.text  = msg[i].region_name;
				  sel.options.add(opt);
				}

			},
			complete: function(XMLHttpRequest, textStatus){
				//HideLoading();
			},
			error: function(){
				//请求出错处理
				alert( "error");
			}
		});


}

function $$(o,node){
	return o=(typeof(o)=='object')?o.getElementsByTagName(node):$(o).getElementsByTagName(node);
}
function addByAttachment(t,n){
	var t=document.getElementById("pupload");
	var inputObj=document.getElementById("pupload").getElementsByTagName("p");
	if(!n){
		if(inputObj.length>5){
			t.removeChild(inputObj[inputObj.length-1]);
		}else{
			alert('可以不上传附件,但不能再删！');
		}
	}else{
		if(inputObj.length<10){

			document.getElementById("pupload").innerHTML+='<p><input type="text" name="regno[]" id="regno[]" class="inputbox" size="16" /> <font color=red>*</font> <span style="margin:0 0 0 8px;"></span> <input type="text" name="name[]" id="name[]" class="inputbox" size="16" /> <span style="margin:0 0 0 8px;"></span> <input id="pic[]" name="pic[]" type="file" class="inputbox" size="20" /></p>';
		}else{
			alert('上传数量已达极限,不能再加！');
		}
	}
}


//顶部广告
var i=0;
function oShow(Len){
	if(i<Len){
		$('#a'+i).show();
		$('#a'+i).siblings().hide();
	}
	i++;
	if(i==Len){ i=0; }
}




/**
* 新增一个图片
*/
function addImg(obj)
{
  var src  = obj.parentNode.parentNode;
  var idx  = rowindex(src);

  var tbl  = document.getElementById('gallery-table');
  var row  = tbl.insertRow(idx + 1);
  var cell = row.insertCell(-1);

  cell.innerHTML = tbl.cells[1].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
}

/**
* 删除图片上传
*/
function removeImg(obj)
{
  var row = rowindex(obj.parentNode.parentNode);
  var tbl = document.getElementById('gallery-table');

  tbl.deleteRow(row);
}
/**
* 检查第几行
*/
function rowindex(o){
return o.parentElement.rowIndex;
}
function delpic(o,id,pic){
	o.parentNode.parentNode.removeChild(o.parentNode);
	odelete('act=del_alum&id='+id+'&pic='+pic);
}

function odelete(url, type1, back1){
		if(type1==''){type1='GET';}
		if(back1==''){back1='';}

		$.ajax({
			type: type1,
			url: "/source/ajax.php?" + url ,
			data: "" ,
			beforeSend: function(XMLHttpRequest){

			},
			success: function(msg){
				if(back1!=''){ $("#"+back1).attr("value",''); }
			},
			complete: function(XMLHttpRequest, textStatus){

			},
			error: function(){
				//请求出错处理
				alert( "error");
			}
		});

}


//*********************************************************
// 目的：    图片自动缩小 点击放大
// 输入：    无
// 返回：    无
//*********************************************************
function ResizeImage(objImage,maxWidth) {
try{
  if(maxWidth>0){
   var objImg = $(objImage);
   if(objImg.width()>maxWidth){
    objImg.width(maxWidth).css("cursor","pointer").click(function(){
     try{showModelessDialog(objImage.src);}catch(e){window.open(objImage.src);}
    });
   }
  }
}catch(e){};
}

function tabTT(obj, sel_on, count){
	for(i=1;i<=count;i++){
		$("#tab_"+obj+'_'+i).hide();
		$("#t_"+obj+'_'+i).removeClass('news_on');
		$("#t_"+obj+'_'+i).addClass('news_off');
	}
	$("#tab_"+obj+'_'+sel_on).show();
	$("#t_"+obj+'_'+sel_on).addClass('news_on');
}


function ___get_comments(id, page){
	$.ajax({
		url:"comment.php?act=get_comment&id=" + id + "&page=" + page + "&rand" + Math.random(),
		type:'GET',
		success:function(){
			$('#comment').html(arguments[0]);
		}
	});
}
