﻿d = document;
w = window;
function getid(id){
    return d.getElementById(id); 
}
function getname(name){
    return d.getElementsByName(name); 
}
function addfav(){
	w.external.AddFavorite(location.href, d.title);
}
function tsize(n, who){
	if(who == null){who = 'content';}
	$("#" + who).css({"font-size": n + "px"});
}
function loadjs(name){
	d.write('<script src="/js/' + name + '.js"></script>');
}
function openwin(url, w, h){
	w = w == null ? 800:w;
	h = h == null ? 600:h;
	window.open(url, 'title', 'height=' + h + ', width=' + w + ', top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');
}
var showing = 1;
function show(id){
	
	$('#c' + showing).hide();
	$('#c' + id).show();	
	
	$('#b' + id).attr('src','/img/products/nav/1/' + id + '.png');
	
	var src = $('#b' + showing).attr('src');
	src = src.replace(/\/1\//g, '/0/');
	$('#b' + showing).attr('src', src);
	
	var src = $('#b' + id).attr('src');
	src = src.replace(/\/0\//g, '/1/');
	$('#b' + id).attr('src', src);
	
	showing = id;
}

loadjs('jq');
loadjs('jscroll');
loadjs('timers');
loadjs('easing');
loadjs('galleryview');

//loadjs('fancybox');

loadjs('flash');

loadjs('ui/ui.datepicker');

d.write('<script src="/editor/FckEditor/fckeditor.js"></script>');
d.write('<script src="/Scripts/swfobject_modified.js"></script>');

//登录
loadjs('ck');
loadjs('base64');

function account(){
	if(!getCK('id')){
		d.write('<span class="white"><a href="/account/login/">登录</a></span>');
	}
	else{
		var uname = $.base64Decode(getCK('uname'));
		d.write('<span class="orange">您好，' + uname + '</span>&nbsp;&nbsp;<span class="white"><a href="/u/">个人设置</a> <a href="/account/logout/">退出登录</a></span>');
	}
}

//列表
function checkall(form, prefix) {
    for(var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if(e.name != 'chkall' && (!prefix || (prefix && e.name.match(prefix)))) {
        e.checked = form.chkall.checked;
        }
    }
}
function op(op,value){
	//删除
	if(op == 'del'){
		var s = confirm("真的要删除选中的记录吗?");
		if(s){
			getid('form').action = op;
			getid('form').submit();
		}
	}
	//清空
	else if(op == 'clean'){
		var s = confirm("真的要删除所有记录吗?");
		if(s){
			getid('form').action = op;
			getid('form').submit();
		}
	}
	//增加显示
	else if(op == 'ps'){
		var ps = prompt('每页显示多少条记录?','10');
		getid('p').value = 1;
		getid('ps').value = ps;
		getid('form').submit();
	}
	//改排序 order
	if(op == 'order'){
		if(getid('order').value == value){
			//改升降顺
			if(getid('by').value == 'ASC'){getid('by').value = 'DESC';}
			else{getid('by').value = 'ASC';}
		}else{
			//改order边个
			getid('order').value = value;
			getid('by').value = 'ASC';
			getid('p').value = 1;
		}
		getid('form').submit();
	}
	//开关制
	else if(op == 'onoff'){
		getid('form').action = op;
		getid('value').value = value;
		getid('form').submit();
	}
	//换页 page
	else if(op == 'page'){
		var page = value.split(",");
		if(page[0] == '+'){
			if(Number(page[1])+1 <= page[2]){
				getid('p').value = Number(page[1])+1;
				getid('form').submit();
			}
		}
		else if(page[0] == '-'){
			if(page[1] != 1){
				getid('p').value = Number(page[1])-1;
				getid('form').submit();
			}
		}else{
			if(Number(page[0]) <= Number(page[1])){
				getid('p').value = page[0];
				getid('form').submit();
			}
		}
	}
	//转到
	else if(op == 'goto'){
		var p = prompt('要转到第几页? (1-'+value+')','');
		if(p>0 && p<=value){
			getid('p').value = p;
			getid('form').submit();
		}
	}
	//进入目录
	else if(op == 'gotolv'){
		var lv = Number(getid('lv').value);
		if(lv == 4){
			alert('不能再进入');
		}else{
			getid('kw').value = '';
			getid('p').value = 1;
			getid('fid').value = value;
			getid('lv').value = lv + 1;
			getid('form').submit();
		}
	}
	//返回上级目录
	else if(op == 'backlv'){
		var lv = Number(getid('lv').value);
		getid('kw').value = '';
		getid('p').value = 1;
		getid('act').value = op;
		getid('lv').value = lv - 1;
		getid('form').submit();
	}
	else{
		getid('form').action = getid('form').action+'/'+op;
		getid('form').submit();
	}
}

//view
function add(){
	var s = confirm("真的要再次添加吗?");
	if(s){
		getid('id').value = '';
		getid('form').submit();
	}
}
function fill(who,value,add){
	if(add==1){
		if(getid(who).value.indexOf(value)==-1){
			value = $('#'+who).val() + value;
		}
		else{
			alert('已存在输入框中');
			return false;
		}
	}
	$('#'+who).val(value);
}

function fillss(fr,to){
	
	var obj = getid(fr + fr + '1');
	if (obj.options[obj.selectedIndex].value!=''){
		var v1 = obj.options[obj.selectedIndex].value;
	}else{
		var v1 = obj.options[obj.selectedIndex].innerText;
	}
	
	if (v1 == '请选择'){
		v1='';
	}
	
	if (v1 != ''){
		
		var v = v1;

		var obj = getid(fr + fr + '2');
		if (obj != null){
			if (obj.options[obj.selectedIndex].value!=''){
				var v2 = obj.options[obj.selectedIndex].value;
			}else{
				var v2 = obj.options[obj.selectedIndex].innerText;
			}
			
			if (v2 != '请选择'){
				v += ',' + v2;
			}
		}

		fill(to, v + '\r\n', 1);
	}
}

function sortList(id, lv, is_onload){

	var obj;
	var path = '';
	//var id = Number(id.substring(2));

	//清除
	if (is_onload != 1){
		for ( i=Number(lv)+1; i<10; i++){
			$('#' + id + i).val('');
			$('#' + id + id + i).remove();
		}
	}
	
	//换值
	obj = getid(id + id + lv);
	if ( obj != null && is_onload != 1){
		if (obj.options[obj.selectedIndex].value!=''){
			var v = obj.options[obj.selectedIndex].value;
		}else{
			var v = obj.options[obj.selectedIndex].innerText;
		}
		$('#' + id + lv).val(v);
	}
	
	//数目录
	for (i=0; i <= lv; i++){
		obj = getid(id + id + i);
		if (obj != null){
			path += obj.options[obj.selectedIndex].innerText;

			if (obj.options[obj.selectedIndex].value != obj.options[obj.selectedIndex].innerText){
				path += ',' + obj.options[obj.selectedIndex].value
			}

			path += '|';
		}
	}

	url =  "/adminiii.php/sort/aj_sort";
	url += "/id/" + id;
	url += "/lv/" + lv;
	//alert(url);

	if ( $('#' + id + (lv+1)).val() != '' ){
		url += "/check/"+ $('#' + id + (lv+1)).val();
	}
	if (path != ''){
		url += "/dir/" + path;
	}
	url += "/rd/" + Math.random();
	
	//alert(url);
	//return false;
	
	$.get(url,function(txt){
		//alert(txt);
		if (txt!=''){
			$('#' + id + id + lv).after(txt);
			sortList ( id, lv+1, 1);
		}
	});

	if ( is_onload == 1 ){
		
	}
}

// FireFox innerText 支持
try{
        HTMLElement.prototype.__defineGetter__
        (
        "innerText",
        function ()
        {
            var anyString = "";
            var childS = this.childNodes;
            for(var i=0; i<childS.length; i++)
            {
                if(childS[i].nodeType==1)
                    anyString += childS[i].tagName=="BR" ? '"n' : childS[i].innerText;
                else if(childS[i].nodeType==3)
                    anyString += childS[i].nodeValue;
            }
            return anyString;
        }
    ); 
}
catch(e){}


