/* used for login*/
var TARGET_HOST = "http://shuru.qq.com/skin/";

var do_login = function(url){
    document.domain = "qq.com";
	var login_frame = document.getElementById("login_frame");
	//s_url为登录后跳转地址	
	s_url = encodeURIComponent(TARGET_HOST + url);
	var frame_src = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=567008303&reset_text=%D6%D8%D6%C3&f_url=loginerroralert&s_url=" + s_url;

	login_frame.src = frame_src;
};

var do_logout = function(){
	removeCookie("uin", "/", "qq.com");
	removeCookie("skey", "/", "qq.com");
    removeCookie("pt2gguin", "/", "qq.com");

	removeCookie("shuru_uname", "/", "shuru.qq.com");

	redirectTo("");
};
var ptlogin2_onResize = function(width, height) {
	//获得浮动Div对象
	login_wnd = document.getElementById("login_div");
	
	if (login_wnd)	{
		//重新设置大小注意，一定要加px，否则firefox下有问题
		login_wnd.style.width = width + "px";
		login_wnd.style.height = height + "px";
		//最好重新调整登录框的位置， 这儿略....
		//先隐藏，在显示，这样可以避免滚动条的出现
		login_wnd.style.visibility = "hidden";
		login_wnd.style.visibility = "visible";
	}
};

var ptlogin2_onClose = function(){
	//弹出Iframe方式的范例
	login_wnd = document.getElementById("login_div");
    login_wnd.style.visibility = "hidden";
};

var upload_redirect = function(){
	if(checkLogin()){
		redirectTo("garden_upload_page");
	}else{
		do_login('');
	}
};
var checkLogin = function(){
	var skey = getCookie("skey");
	var uin = getCookie("uin");
	var shuru_uname = getCookie("shuru_uname");

	if(skey != null && uin != null && shuru_uname != null){
		if(skey!=""&&uin!=""&&shuru_uname!=""){
			return true;
		}
	}
	return false;
};

var redirectTo = function(target){
	window.location.href= TARGET_HOST + target;
};
/* used for login END*/
/*==============cookie============*/
var trimStr = function(str) {
   str = str.replace(/^\s*/,"");
   str = str.replace(/\s*$/,"");
   return str;
};

var getCookie = function(name){
    var cookies = document.cookie;
    cookies = cookies.split(";");
    var length = cookies.length;
    for(i=0;i<length;i++){
        var tmp = cookies[i].split("=");
        if(tmp.length == 2){
            key = trimStr(tmp[0]);
            value = trimStr(tmp[1]);
            if(key == name){
                return trimStr(value);
            }
        }
    }

    return null;
};

var setCookie = function(c_name, value, path, domain, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	//document.cookie = c_name + "=" +escape(value) +
	//	((expiredays === null) ? "" : ";path=" + path + ";domain=" + domain+ ";expires=" + exdate.toGMTString());
    var cookie_str = c_name + "=" + escape(value)+ ";";
    if(path){
        cookie_str += "path=" + path + ";";
    }
    if(domain){
        cookie_str += "domain=" + domain + ";";
    }
    if(expiredays){
        cookie_str += "expires=" + exdate.toGMTString() + ";";
    }
    document.cookie = cookie_str;
};

var removeCookie=function(name, path, domain){
	setCookie(name,'',path, domain, {expireHours:-1});
};

/******************************************************************** 
  非IE返回false
  如果是IE，则返回具体的IE版本，包括5、6、7、8、9
********************************************************************/
var isIE = function () {
    var v = 3, 
        div = document.createElement('div'),
        i = div.getElementsByTagName('i');
    do {
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->';
    } while (i[0]);
    return v > 4 ? v : false; 
};
var ieVersion = isIE();

/* 【皮肤花园】点击"未通过"显示未通过的原因，参数str为要现实的未通过原因，obj为点击的<a>对象 */
var show_msg = function(str, obj){
	//根据点击的链接所在表格中的行，来确定显示的窗口距外部div的位移
	var row = obj.parentNode.parentNode.parentNode;
	var positiont = (row.rowIndex-1) * 99 + 260;
	var positionl = 949;
	
	//对IE进行特别处理
	if(ieVersion){ 
  		positionl = 944;
	}
	if(ieVersion == 7){//对IE7进行特别处理
		positionl = 984;
	}
	//创建一个div对象（提示框层） 
	var msgObj=document.createElement("div")  
	msgObj.setAttribute("id","msgDiv" + row.rowIndex); //为id添加行号，以防止用户点开多个不同链接时造成页面上存在多个id相同的窗口    
	msgObj.style.position = "absolute"; 
	msgObj.style.textAlign = "left";    
	msgObj.style.width = "146px"; 
	msgObj.style.paddingBottom = "18px"; 
	msgObj.style.zIndex = "10001";   
	
	//创建提示文字div
	var wordone = document.createElement("div");  
	wordone.setAttribute("id","onetext"+row.rowIndex);//为id添加行号，以防止用户点开多个不同链接时造成页面上存在多个id相同的窗口    
	wordone.innerHTML = str;
	wordone.style.color="#249F94";
	wordone.style.padding =  "5px";
	if(ieVersion == 6){//对IE6进行特别处理
		wordone.style.marginBottom =  "1px";
	}
	wordone.style.background = "#FFF";  
	wordone.style.border =  "1px solid #249F94";  
	
	//创建窗口底部的装饰三角，以便形成提示框的样式
	var decoration = document.createElement("div");
	decoration.setAttribute("id", "decorationDiv"+row.rowIndex);//为id添加行号，以防止用户点开多个不同链接时造成页面上存在多个id相同的窗口    
	decoration.style.width = "24px";
	decoration.style.height = "19px";
	decoration.style.background = "url(css/images/tip_popup_box_bottom.jpg) no-repeat";
	decoration.style.position = "absolute";
	decoration.style.bottom = "0";
	decoration.style.right = "48px";
	   
	document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj   
	document.getElementById("msgDiv"+row.rowIndex).appendChild(wordone); //添加第一块文字
	document.getElementById("msgDiv"+row.rowIndex).appendChild(decoration); //添加尖角装饰

	msgObj.style.left = positionl +"px";
	msgObj.style.top = (positiont - msgObj.offsetHeight)+"px";
	
	obj.onmouseout=function(){//点击标题栏触发的事件     
		document.body.removeChild(msgObj);//删除提示框层 
	}
} 

/* 搜索框 */
$(document).ready(function(){
	function initSearchBar() {
		var searchbar = $('#search_skin_textbox');
		if (!searchbar.size()) return;
		searchbar.blur(function(e){
			if (!this.value) this.value = '搜皮肤';
		}).focus(function(e){
			if (this.value === '搜皮肤') this.value = '';
			else this.select();
		});
	}
	initSearchBar();
});

/* 皮肤分类，手机皮肤下载时，如果没有登录的提示框 */
$(document).ready(function(){
	if(true){//这里是判断登录的代码，如果用户已经登录了，那么以下的代码就不需要执行了
		var outerDivCss = {
				'position': 'absolute',
				'width': '185px',
				'height': '114px',
				'background': 'url(css/images/mobile_skin_sigin_bg.png) no-repeat',
				'visibility': 'hidden'
			};
		var $outerDiv = $("<div/>").css(outerDivCss);
		var $textWord = $('<p>登录以后我们才能把漂亮的皮肤发送到你的手机哦</p>').css('margin', '15px 25px 12px 25px');
		var $loginLink = $('<a herf="#">[立即登录]</a>').css({'marginLeft': '25px', 'cursor': 'pointer'});
	
		$textWord.appendTo($outerDiv);
		$loginLink.appendTo($outerDiv);
		$outerDiv.bind('mouseover', function(){
			$(this).css('visibility', 'visible');
		});	
		$outerDiv.bind('mouseout', function(){
			$(this).css('visibility', 'hidden');
		});	
		
		$('.cdb-download-link').bind('mouseover', function(){
			var position = $(this).position();
			$outerDiv.css({'top': position.top - 105, 'left': position.left - 20, 'visibility': 'visible'});
			$outerDiv.appendTo($(this).parent());
		});
		$('.cdb-download-link').bind('mouseout', function(){
			$outerDiv.css('visibility', 'hidden');
		});
	}
});
//手机皮肤发送结果反馈
var showResult = function(response){
	if(ieVersion == 6){
		if(response){
			alert('发送成功！');
		}
		else{
			alert('发送失败！');
		}
	}
	else{
		var left = document.body.clientWidth * 0.51;
		var top = document.body.clientHeight * 0.2;
		var resultDivCss = {
			'width': '186px',
			'height': '78px',
			'position': 'fixed',
			'left': left + 'px',
			'top': top +'px'
		}
		if(response){
			resultDivCss.background = 'url(css/images/response_successfully_sent.png) no-repeat';
		}
		else{
			resultDivCss.background = 'url(css/images/response_failed_sending.png) no-repeat';
		}
		$('<div />').css(resultDivCss).appendTo($('#all-wrapper')).delay(3000).hide(0);
	}
	
};


/* 顶部通栏，消息中心气泡，str为消息内容，url为'快去看看'的link */
var msgBubble = function(str, url){
	var msgBoxCss = {
			'width': '253px',
			'visibility': 'hidden',
			'position': 'absolute',
			'top': '22px',
			'right': '-28px'
		};
	var topCss = {
			'width': '253px',
			'height': '27px',
			'background': 'url(css/images/message_box_up.png) no-repeat'
		};
	var middleCss = {
			'width': '217px',
			'padding': '0 18px',
			'background': 'url(css/images/message_box_middle.png) repeat-y'
		};
	var downCss = {
			'width': '253px',
			'height': '22px',
			'background': 'url(css/images/message_box_down.png) no-repeat'
		};
	if(ieVersion == 6){
		topCss = {
			'width': '241px',
			'height': '27px',
			'background': 'url(css/images/message_box_up_for_ie6.jpg) no-repeat'
		};
		middleCss = {
			'width': '217px',
			'padding': '0 12px',
			'background': 'url(css/images/message_box_middle_for_ie6.jpg) repeat-y'
		};
		downCss = {
			'width': '241px',
			'height': '12px',
			'background': 'url(css/images/message_box_down_for_ie6.jpg) no-repeat'
		};
		msgBoxCss.top = "25px";
	}
	var $msgBox = $("<div/>").css(msgBoxCss);
	var $boxTop = $("<div/>").css(topCss);
	var $boxMiddle = $("<div/>").css(middleCss);
	var $boxDown = $("<div/>").css(downCss);
	var $msg = $('<p>' + str + '，<a href="'+url+'" style="color:#1187D1;">快去看看</a>吧</p>');
	var $knownLink = $('<a herf="#" style="">我知道啦</a>').css({'display': 'block', 'cursor': 'pointer', 'color': '#1187D1', 'textAlign': 'right'}).click(function(){
		$msgBox.fadeTo('fast', 0, function(){$(this).remove()});
	});
	
	$boxMiddle.append($msg).append($knownLink);
	$msgBox.append($boxTop).append($boxMiddle).append($boxDown);
	
	if(true){//这里应该是判断是不是有新消息的JS
		$msgBox.appendTo($('#all-wrapper')).css('visibility', 'visible');
	}
};


var overlap = function(){
	var overlapboxcss = {
		'width': '360px',
		'height': '280px'
	};
	var $overlapbox = $("<div/>").css(overlapboxcss);
}


/* 皮肤平台首页【下载排行】的"周 月 日"切换 */
$(document).ready(function(){
	$('.download-part ul.time-scope li.ts-week a').bind('click', function(){
		$('.download-part ul.time-scope li').removeClass('time-current');
		$(this).parent().addClass('time-current');
		$('#day_rank').css('display', 'none');
		$('#month_rank').css('display', 'none');
		$('#week_rank').css('display', 'block');
		return false;
	});
	$('.download-part ul.time-scope li.ts-month a').bind('click', function(){
		$('.download-part ul.time-scope li').removeClass('time-current');
		$(this).parent().addClass('time-current');
		$('#day_rank').css('display', 'none');
		$('#week_rank').css('display', 'none');
		$('#month_rank').css('display', 'block');
		return false;
	});
	$('.download-part ul.time-scope li.ts-day a').bind('click', function(){
		$('.download-part ul.time-scope li').removeClass('time-current');
		$(this).parent().addClass('time-current');
		$('#week_rank').css('display', 'none');
		$('#month_rank').css('display', 'none');
		$('#day_rank').css('display', 'block');
		return false;
	});
});

/* 皮肤平台首页【优秀皮肤】的tab切换 
$(document).ready(function(){
	var shiftTab = function(targetTab, $currentTabObj){
		$('.es-tag-link a').removeClass('esb-current');
		$currentTabObj.addClass('esb-current');
		for(var i = 1; i <= 4; i++){
			$('#esb-tab' + i).css('display', 'none');
		}
		$('#esb-tab' + targetTab).css('display', 'block');
	};
	$('.es-tag-link a.esb-link1').bind('mouseenter', function(){
		shiftTab(1, $(this));
		return false;
	});
	$('.es-tag-link a.esb-link2').bind('mouseenter', function(){
		shiftTab(2, $(this));
		return false;
	});
	$('.es-tag-link a.esb-link3').bind('mouseenter', function(){
		shiftTab(3, $(this));
		return false;
	});
	$('.es-tag-link a.esb-link4').bind('mouseenter', function(){
		shiftTab(4, $(this));
		return false;
	});
});
*/
 /* 皮肤平台首页【官方精品系列】的tab切换 */
$(document).ready(function(){
	$('li.osb-li1 a').bind('click', function(){
		$('ul#osb-tab-nav li').removeClass('os-current');
		$(this).parent().addClass('os-current');
		$('#osb-tab2').css('display', 'none');
		$('#osb-tab3').css('display', 'none');
		$('#osb-tab1').css('display', 'block');
		$('h3#osb-title').text($(this).text());
		return false;
	});
	$('li.osb-li2 a').bind('click', function(){
		$('ul#osb-tab-nav li').removeClass('os-current');
		$(this).parent().addClass('os-current');
		$('#osb-tab1').css('display', 'none');
		$('#osb-tab3').css('display', 'none');
		$('#osb-tab2').css('display', 'block');
		$('h3#osb-title').text($(this).text());
		return false;
	});
	$('li.osb-li3 a').bind('click', function(){
		$('ul#osb-tab-nav li').removeClass('os-current');
		$(this).parent().addClass('os-current');
		$('#osb-tab1').css('display', 'none');
		$('#osb-tab2').css('display', 'none');
		$('#osb-tab3').css('display', 'block');
		$('h3#osb-title').text($(this).text());
		return false;
	});
});

/* 处理皮肤下载链接，调用CGI接口，统计下载次数 */
function initDownloadLink() {
	$('.download-link-btn').click(function(e){
		var target = $(this),
			skinId = this.getAttribute('skinid');
		if (!skinId) return;
		e.preventDefault();
		download(skinId, target);
	});
}
var download = function(skin_id, sourceBtn){
	var download_callback = function(data){
		if(data.err < 0){
		}
		else{
			var downloadStr = "http://pc5.gtimg.com/btr/shuru/skin/"+data.download_url+skin_id+".qpys";
			location.href = downloadStr;
			//更新下载按钮上的数字
			var downloadTimes = parseInt(data.download_times);
			if(downloadTimes < 9999){
				sourceBtn.attr('value', downloadTimes + 1);
				
			}
			else if(downloadTimes == 9999){
				sourceBtn.attr('value', '1.0万');
			}
			//详情页下载次数改变
			var detaildl =  downloadTimes + 1;
			document.getElementById("detaildownload").innerHTML= "下载量："+detaildl;					
		}
		return false;
	};
	$.ajax({
		url:"/skin/download", 
		data:		({skin_id:skin_id}),
		dataType:	"json",
		success:	download_callback
	});
	
};

$(document).ready(function(){
	initDownloadLink();
});

/* 为皮肤打分的动态星星 */
$(document).ready(function(){
	var scoreAvailable = true;
	var $markStars = $('span.marking-aera');
	var $tenPos = $('span.ten-pos');
	var $point = $('span.point');
	var $gePos = $('span.ge-pos');
	
	var markStarsPosition = $markStars.css('backgroundPosition');
	var tenPosText = $tenPos.text();
	var gePosText = $gePos.text();
	
	//恢复原分数状态
	var goBackStatus = function(){
		$markStars.css('backgroundPosition', markStarsPosition);
		$tenPos.text(tenPosText);
		$point.css('display', 'block');
		$gePos.text(gePosText).css('display', 'block');
	};
	
	$('.skin-mark-big a.grades-2').bind('mouseover', function(){
		$markStars.css('backgroundPosition','0 0');
		$tenPos.text('2');
		$point.css('display', 'block');
		$gePos.text('0').css('display', 'block');
	});
	$('.skin-mark-big a.grades-4').bind('mouseover', function(){
		$markStars.css('backgroundPosition','0 -26px');
		$tenPos.text('4');
		$point.css('display', 'block');
		$gePos.text('0').css('display', 'block');
	});
	$('.skin-mark-big a.grades-6').bind('mouseover', function(){
		$markStars.css('backgroundPosition','0 -52px');
		$tenPos.text('6');
		$point.css('display', 'block');
		$gePos.text('0').css('display', 'block');
	});
	$('.skin-mark-big a.grades-8').bind('mouseover', function(){
		$markStars.css('backgroundPosition','0 -78px');
		$tenPos.text('8');
		$point.css('display', 'block');
		$gePos.text('0').css('display', 'block');
	});
	$('.skin-mark-big a.grades-10').bind('mouseover', function(){
		$markStars.css('backgroundPosition','0 -104px');
		$tenPos.text('10');
		$point.css('display', 'none');
		$gePos.text('0').css('display', 'none');
	});
	$('.skin-mark-big a').bind('mouseout', goBackStatus);
	/* 点击后打分 */
	$('.skin-mark-big a').click(function(){
		//check login
		if(checkLogin()){
			//已登录，可以执行打分操作, 分数为百分制
			var grade = $(this).attr('class').split('-')[1] * 10;
			
			if (!scoreAvailable) return false;
			
			//异步发送打分
			$.post('/skin/set_skin_grade', 
				{
					skin_id: $markStars.attr('skinid'),
					point: grade
				}, 
				function(ret){
					if (ret.err < 0) {
						alert('您已经成功打分，请勿重复打分。');
						goBackStatus();
					}
					else{
						alert('打分成功！');
						var avgGrade = parseInt(ret.cur_point);
						var starNum = Math.floor(avgGrade / 20);
						$markStars.css('backgroundPosition','0 -'+(Math.floor(avgGrade / 20)*26 -26)+'px');
						$tenPos.text(Math.floor(avgGrade / 10));
						$point.css('display', 'block');
						$gePos.text(avgGrade % 10).css('display', 'block');
						$('span.marking-num').text(ret.user_num + '人评分');
						scoreAvailable = false;
					}
				}, 
				'json'
			);
		}
		else{
			//没有登录，弹出登录窗口
			skin_id = $markStars.attr('skinid')
			url = 'skin_detail?skin_id=' + skin_id
			do_login(url);
		}
		return false;
	});
});

//以下至本文件最后全部拷贝到tsts.js文件中

function getFileSize1(filePath){
/*	if(window.ActiveXObject)//判断条件也可以改为navigator.userAgent.indexOf("MSIE")!=-1
		{
	//IE浏览器
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var size = fso.GetFile(filePath).size;
		if(size > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_skin_file").value="";
		}
		else
			return;
		}
	else 
	if(navigator.userAgent.indexOf("Firefox")!=-1){ */
		//火狐浏览器
		var size1 = document.getElementById("scpf_skin_file").files[0].fileSize;
		if(size1 > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_skin_file").value="";
			} 
		
		else{
			return;
		}
		
//	}
	
}
function getFileSize2(filePath){
	if(window.ActiveXObject)//判断条件也可以改为navigator.userAgent.indexOf("MSIE")!=-1
		{
	//IE浏览器
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var size = fso.GetFile(filePath).size;
		if(size > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_skin_pic").value="";
		}
		else
			return;
		}
	else 
	if(navigator.userAgent.indexOf("Firefox")!=-1){
		//火狐浏览器
		var size2 = document.getElementById("scpf_skin_pic").files[0].fileSize;
		if(size2 > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_skin_pic").value="";
			}
		
		else{
			return;
		}
		
	}
	
}
function getFileSize3(filePath){
	if(window.ActiveXObject)//判断条件也可以改为navigator.userAgent.indexOf("MSIE")!=-1
		{
	//IE浏览器
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var size = fso.GetFile(filePath).size;
		if(size > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_cover_pic").value="";
		}
		else
			return;
		}
	else 
	if(navigator.userAgent.indexOf("Firefox")!=-1){
		//火狐浏览器
		var size3 = document.getElementById("scpf_cover_pic").files[0].fileSize;
		if(size3 > 512000){
			alert("上传图片太大！");
			document.getElementById("scpf_cover_pic").value="";
			}
		else{
			return;
		}
		
	}
	
}

var upload = function(str){
	var T=true;
	var skintitle=document.getElementById("scpf_skin_name");
	 extArray = new Array(".jpg");
	 extArray2 = new Array(".qpys");
	 var pic=document.getElementById("scpf_cover_pic");
	 var picvalue= pic.value;
	 var pic2=document.getElementById("scpf_skin_pic");
	 var pic2value= pic2.value;
	 var skinfile=document.getElementById("scpf_skin_file");
	 var skinfilevalue= skinfile.value;
	 var kinds = document.getElementById("scpf_skin_class");
	 kindsselect = false;
	 allowSubmit = false;
	 allowSubmit2 = false;
	 allowSubmit3 = false;
	 
	 var canupload = true;
	 

     if(!skintitle.value){
        alert("皮肤名称不能为空");
		canupload = false;
        skintitle.focus();
        return;
     }
	
	 for(i=1;i<kinds.options.length;i++){
		 if(kinds.options[i].selected==true){
			kindsselect = true;
			break;
		 }
	 }

	 if(!kindsselect){
		alert("皮肤类型未选择！");
		return;
	 }
	 
	 if (!picvalue) {alert("首页皮肤缩略图未上传！");canupload = false;return};
	 
	while (picvalue.indexOf("\\") != -1)
		picvalue = picvalue.slice(picvalue.indexOf("\\") + 1);
		ext = picvalue.slice(picvalue.indexOf(".")).toLowerCase();
		
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (allowSubmit){
	}
	 
	else{
		alert("首页肤缩略图格式出错！");
		canupload = false;
		return;
	 }
	 
	 
	if (!pic2value) {alert("皮肤缩略图未上传！");canupload = false;return;}
	 
	while (pic2value.indexOf("\\") != -1)
		pic2value = pic2value.slice(pic2value.indexOf("\\") + 1);
		ext2 = pic2value.slice(pic2value.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext2) { allowSubmit2 = true; break; }
	}
	if (allowSubmit2){
	}
	 
	else{
		alert("上传皮肤缩略图格式出错！");
		canupload = false;
		return;
	 }
	 
	 if (!skinfilevalue) {alert("皮肤文件未上传！");canupload = false;return;}
	 
	while (skinfilevalue.indexOf("\\") != -1)
		skinfilevalue = skinfilevalue.slice(skinfilevalue.indexOf("\\") + 1);
		ext3 = skinfilevalue.slice(skinfilevalue.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray2.length; i++) {
		if (extArray2[i] == ext3) { allowSubmit3 = true; break; }
	}
	if (allowSubmit3){
	}
	 
	else{
		alert("皮肤文件格式出错！");
		canupload = false;
		return;
	 }
	 
    if(canupload=true){
		document.getElementById('skin_upload_form').submit();
	}
	else{
		alert("请检查是否满足上传条件！");
		return;
	}
}


/* 投诉弹出框, 【第二个参数是skinid】, 在绑定“我要投诉”的click事件时传入 */
var tousu = function(str, skinid, skinname){
	var   complaint = window.location.href;
	var   msgw,msgh,bordercolor;   
	msgw=712;//提示窗口的宽度   
	msgh=592;//提示窗口的高度   
	titleheight=25   //提示窗口标题高度   
	bordercolor="#336699";//提示窗口的边框颜色   
	titlecolor="#99CCFF";//提示窗口的标题颜色   
  
	var   sWidth,sHeight;   
	sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度   
	sHeight=document.body.offsetHeight;//浏览器工作区域内页面高度   
	


	
  
	//背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）   
	var   bgObj=document.createElement("div");//创建一个div对象（背景层）     
	bgObj.setAttribute("id","bgDiv");  
	bgObj.style.position="absolute";   
	bgObj.style.top="0";   
	bgObj.style.background="#777";   
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";   
	bgObj.style.opacity="0.6";   
	bgObj.style.left="0";   
	bgObj.style.width=sWidth   +  "px";   
	bgObj.style.height=sHeight   +  "px";   
	bgObj.style.zIndex   =  "1000";   
	document.body.appendChild(bgObj);//在body内添加该div对象   
    
	
	
	var   msgObj=document.createElement("div")//创建一个div对象（提示框层）    
	msgObj.setAttribute("id","msgDiv");   
	msgObj.setAttribute("align","center");   
	msgObj.style.background="url(css/images/tousu_bg.png) 0 0 no-repeat";    
	msgObj.style.position   =  "absolute";   
	msgObj.style.left   =  "41%";   
	msgObj.style.top   =  "30%";   
	msgObj.style.font="12px/1.6em   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	msgObj.style.marginLeft   =  "-225px"   ;   
	msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+"px";   
	msgObj.style.width   =   msgw   +  "px";   
	msgObj.style.height   =msgh   +  "px";   
	msgObj.style.textAlign   =  "center";   
	msgObj.style.lineHeight   ="25px";   
	msgObj.style.zIndex   =  "10001";   

	var   title=document.createElement("h4");//创建一个h4对象（提示框标题栏）      
	title.setAttribute("id","msgTitle");   
	title.setAttribute("align","right");   
	title.style.marginRight="27px";  
	title.style.marginLeft="28px";
	title.style.marginTop="28px";
	title.style.padding="3px"; 
	title.style.borderBottom="1px solid #E1E1E1";	
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);";   
	title.style.opacity="0.75";     
	title.style.height="35px";   
	title.style.font="12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	title.style.color="white"; 
	title.style.background="url(css/images/ws_line_fgx2.png) 28px 35px no-repeat"; 
	
	var titleword=document.createElement("img");  //创建标题
	titleword.setAttribute("id","titleid");
	titleword.style.float="left";
	titleword.setAttribute("src","css/images/itousu.png");
	titleword.style.position   =  "absolute"; 
	titleword.style.top="45px";
	titleword.style.left="44px";
	
	var close=document.createElement("img");  //创建关闭按钮
	close.setAttribute("id","closeimg");  
	close.setAttribute("src","css/images/tousu_close.png");
	close.style.cursor="pointer";
	close.style.position   =  "absolute"; 
	close.style.top="28px";
	close.style.right="27px";
	close.onclick=removeObj;
	
	var formarea=document.createElement("form");//创建表单
	formarea.setAttribute("id","uploadForm");
	formarea.setAttribute("enctype","multipart/form-data");
	formarea.setAttribute("method","post");
	formarea.setAttribute("action","/skin/complaint");
	formarea.style.float="left";
	

	var area1=document.createElement("div");  //创建第一块区域的key
	area1.setAttribute("id","areaone");
	area1.innerHTML="皮肤名称:";
	area1.style.float="left";
	area1.style.position   =  "absolute"; 
	area1.style.top="89px";
	area1.style.left="60px";
	area1.style.color="#000000"; 
	area1.style.fontFamily="宋体";
	area1.style.fontSize="12px";
	area1.style.fontWeight="bold";
	
	//var skinName = this.getAttribute('skinname');
	
	
	var hide=document.createElement("input");  //创建第二块区域的value
	hide.setAttribute("type","text");
	hide.setAttribute("name","skin_id");
	hide.setAttribute("id","skin_id");
	hide.setAttribute("value",skinid);
	hide.style.visibility="hidden";
	
	var area11=document.createElement("div");  //创建第一块区域的value
	area11.setAttribute("id","areaoneone");
	area11.innerHTML= skinname;
	area11.style.float="left";
	area11.style.position   =  "absolute"; 
	area11.style.top="89px";
	area11.style.left="134px";
	area11.style.color="#000000"; 
	area11.style.fontFamily="宋体";
	area11.style.fontSize="12px";
	
	var area2=document.createElement("div");  //创建第二块区域的key
	area2.setAttribute("id","areatwo");
	area2.innerHTML="投诉类型:";
	area2.style.float="left";
	area2.style.position   =  "absolute"; 
	area2.style.top="121px";
	area2.style.left="60px";
	area2.style.color="#000000"; 
	area2.style.fontFamily="宋体";
	area2.style.fontSize="12px";
	area2.style.fontWeight="bold";
	
	var area21=document.createElement("input");  //创建第二块区域的value
	area21.setAttribute("type","radio");
	area21.setAttribute("name","complaint_type");
	area21.setAttribute("value","1");
	area21.setAttribute("id","areatwoone");
	area21.style.float="left";
	area21.style.position   =  "absolute"; 
	area21.style.top="126px";
	area21.style.left="134px";
	
	var area211=document.createElement("div");  //创建第二块区域的value
	area211.innerHTML="使用未授权卡通/人物形象"
	area211.style.position   =  "absolute"; 
	area211.style.top="120px";
	area211.style.left="157px";
	area211.style.color="#000000"; 
	area211.style.fontFamily="宋体";
	area211.style.fontSize="12px";
	
	var area22=document.createElement("input");  //创建第二块区域的value
	area22.setAttribute("type","radio");
	area22.setAttribute("name","complaint_type");
	area22.setAttribute("value","2");
	area22.setAttribute("id","areatwotwo");
	area22.style.float="left";
	area22.style.position   =  "absolute"; 
	area22.style.top="150px";
	area22.style.left="134px";
	
	var area221=document.createElement("div");  //创建第二块区域的value
	area221.innerHTML="盗用按键或其他皮肤素材"
	area221.style.position   =  "absolute"; 
	area221.style.top="144px";
	area221.style.left="157px";
	area221.style.color="#000000"; 
	area221.style.fontFamily="宋体";
	area221.style.fontSize="12px";
	
	var area23=document.createElement("input");  //创建第二块区域的value
	area23.setAttribute("type","radio");
	area23.setAttribute("name","complaint_type");
	area23.setAttribute("value","3");
	area23.setAttribute("id","areatwothree");
	area23.style.float="left";
	area23.style.position   =  "absolute"; 
	area23.style.top="174px";
	area23.style.left="134px";
	
	var area231=document.createElement("div");  //创建第二块区域的value
	area231.innerHTML="盗用整套皮肤"
	area231.style.position   =  "absolute"; 
	area231.style.top="168px";
	area231.style.left="157px";
	area231.style.color="#000000"; 
	area231.style.fontFamily="宋体";
	area231.style.fontSize="12px";
	
	var area24=document.createElement("input");  //创建第二块区域的value
	area24.setAttribute("type","radio");
	area24.setAttribute("name","complaint_type");
	area24.setAttribute("value","4");
	area24.setAttribute("id","areatwofour");
	area24.style.float="left";
	area24.style.position   =  "absolute"; 
	area24.style.top="198px";
	area24.style.left="134px";
	
	var area241=document.createElement("div");  //创建第二块区域的value
	area241.innerHTML="色情/反动内容"
	area241.style.position   =  "absolute"; 
	area241.style.top="192px";
	area241.style.left="157px";
	area241.style.color="#000000"; 
	area241.style.fontFamily="宋体";
	area241.style.fontSize="12px";
	
	var area3=document.createElement("div");  //创建第三块区域的key
	area3.setAttribute("id","areathree");
	area3.innerHTML="投诉理由:";
	area3.style.float="left";
	area3.style.position   =  "absolute"; 
	area3.style.top="226px";
	area3.style.left="60px";
	area3.style.color="#000000"; 
	area3.style.fontFamily="宋体";
	area3.style.fontSize="12px";
	area3.style.fontWeight="bold";
	
	var area31=document.createElement("textarea");  //创建第三块区域的value
	area31.setAttribute("id","areathreeone");
	area31.setAttribute("name", "complaint_reason");
	area31.style.float="left";
	area31.style.position   =  "absolute"; 
	area31.style.top="230px";
	area31.style.left="134px";
	area31.style.width="380px";
	area31.style.height="110px";
	
	var area32=document.createElement("div");  //创建第三块区域的value
	area32.setAttribute("id","areathreetwo");
	area32.innerHTML="1200字以内";
	area32.style.float="left";
	area32.style.position   =  "absolute"; 
	area32.style.top="344px";
	area32.style.left="134px";
	area32.style.color="#979797"; 
	area32.style.fontFamily="宋体";
	area32.style.fontSize="12px";
	
var area4=document.createElement("div");  //创建第四块区域的key
	area4.setAttribute("id","areafour");
	area4.innerHTML="图片举证:";
	area4.style.float="left";
	area4.style.position   =  "absolute"; 
	area4.style.top="380px";
	area4.style.left="60px";
	area4.style.color="#000000"; 
	area4.style.fontFamily="宋体";
	area4.style.fontSize="12px";
	area4.style.fontWeight="bold";
 	area4.style.paddingRight="5px";
	area4.style.background="url(css/images/icon_must.png) no-repeat scroll right center transparent";
	
	var area4input1=document.createElement("input"); 
	area4input1.setAttribute("type","file");
	area4input1.setAttribute("id","input1");
	area4input1.setAttribute("name","input1");
	area4input1.style.float="left";
	area4input1.style.position   =  "absolute"; 
	area4input1.style.top="383px";
	area4input1.style.left="134px";
	
	var area4input2=document.createElement("input"); 
	area4input2.setAttribute("type","file");
	area4input2.setAttribute("id","input2");
	area4input2.setAttribute("name","input2");
	area4input2.style.float="left";
	area4input2.style.position   =  "absolute"; 
	area4input2.style.top="408px";
	area4input2.style.left="134px";
	
	var area4input3=document.createElement("input"); 
	area4input3.setAttribute("type","file");
	area4input3.setAttribute("id","input3");
	area4input3.setAttribute("name","input3");
	area4input3.style.float="left";
	area4input3.style.position   =  "absolute"; 
	area4input3.style.top="433px";
	area4input3.style.left="134px";	
	
	var area511=document.createElement("input");  //创建第五块区域
	area511.setAttribute("id","idBtnupload");
	area511.setAttribute("type","submit");
	area511.setAttribute("onclick","uptousu(''); return false;");
	area511.setAttribute("value","");
	area511.style.background   =  "url(css/images/tousu_submit.png)"; 
	area511.style.position   =  "absolute"; 
	area511.style.cursor   =  "hand"; 
	area511.style.width="104px";
	area511.style.height="40px"; 
	area511.style.top="484px";
	area511.style.left="134px";

	var area52=document.createElement("a");  //创建第五块区域
	area52.setAttribute("id","idBtndel");
	area52.setAttribute("href","#");
	area52.innerHTML="取消投诉";
	area52.style.float="left";
	area52.style.position   =  "absolute"; 
	area52.style.top="487px";
	area52.style.left="254px";
	area52.style.color="#1187D1"; 
	area52.style.fontFamily="宋体";
	area52.style.fontSize="12px"; 
	area52.onclick=removeObj;
	
	var hideurl=document.createElement("input");  //创建第二块区域的value
	hideurl.setAttribute("type","text");
	hideurl.setAttribute("name","hideurl");
	hideurl.setAttribute("id","hide_url");
	hideurl.setAttribute("value",complaint);
	hideurl.style.visibility="hidden";
	
	function   removeObj(){//点击标题栏触发的事件   
		document.body.removeChild(bgObj);//删除背景层Div   
		document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏   
		document.body.removeChild(msgObj);//删除提示框层   
	}   
	document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj   
	document.getElementById("msgDiv").appendChild(title);
	document.getElementById("msgDiv").appendChild(close);//在标题中添加关闭按钮   
	document.getElementById("msgTitle").appendChild(titleword); //在标题中添加文字标题
	document.getElementById("msgDiv").appendChild(formarea);
	document.getElementById("uploadForm").appendChild(hide);
	document.getElementById("uploadForm").appendChild(area1);
	document.getElementById("uploadForm").appendChild(area11);
	document.getElementById("uploadForm").appendChild(area2);
	document.getElementById("uploadForm").appendChild(area21);
	document.getElementById("uploadForm").appendChild(area211);
	document.getElementById("uploadForm").appendChild(area22);
	document.getElementById("uploadForm").appendChild(area221);
	document.getElementById("uploadForm").appendChild(area23);
	document.getElementById("uploadForm").appendChild(area231);
	document.getElementById("uploadForm").appendChild(area24);
	document.getElementById("uploadForm").appendChild(area241);
	document.getElementById("uploadForm").appendChild(area3);
	document.getElementById("uploadForm").appendChild(area31);
	document.getElementById("uploadForm").appendChild(area32);
	document.getElementById("uploadForm").appendChild(area4);
	document.getElementById("uploadForm").appendChild(area4input1);
	document.getElementById("uploadForm").appendChild(area4input2);
	document.getElementById("uploadForm").appendChild(area4input3);
	/*document.getElementById("uploadForm").appendChild(area41);
	document.getElementById("uploadForm").appendChild(area411);
	document.getElementById("uploadForm").appendChild(area412);
	document.getElementById("areafouronetwo").appendChild(area4121);
	document.getElementById("uploadForm").appendChild(area413);*/
	//document.getElementById("uploadForm").appendChild(area51);
	document.getElementById("uploadForm").appendChild(area511);
	document.getElementById("uploadForm").appendChild(area52);
	document.getElementById("uploadForm").appendChild(hideurl);
	
	var   txt=document.createElement("p");//创建一个p对象（提示框提示信息）   
	txt.style.margin="1em   0"   ;
	txt.setAttribute("id","msgTxt");   
	txt.innerHTML=str;//来源于函数调用时的参数值   
	document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt   	
}


var uptousu = function(str){
	var cantousu = true;
	var radiosflag = false;
	var fileflag = true;
	var radios = document.getElementsByName("complaint_type");
	for(var i=0;i<radios.length;i++)
			{

				if(radios[i].checked)
				{	
					radiosflag = true;
					break;
				}
			}
	if(!radiosflag){
		alert("请选择投诉类型！");
		cantousu = false;
		return;
	}
	var input1 = document.getElementById("input1");
	var input2 = document.getElementById("input2");
	var input3 = document.getElementById("input3");
	var input1value = input1.value;
	var input2value = input2.value;
	var input3value = input3.value;
	if(!input1.value&!input2value&!input3value){
		fileflag = false;
	}
	if(!fileflag){
		alert("请选择图片举证");
		cantousu = false;
		return;
	}
	 if(cantousu=true){
		document.getElementById('uploadForm').submit();
	}
	else{
		alert("请检查是否满足投诉条件！");
		return;
	}
	
	
}
/* 绑定我要投诉事件 */
$(document).ready(function(){
	$('.popup-tousu-link').click(function(){
		if(checkLogin()){
			tousu('', $(this).attr('skinid'),$(this).attr('skinname'));
		}
		else{
			//没有登录，弹出登录窗口
			skin_id = $(this).attr('skinid')
			url = 'skin_detail?skin_id=' + skin_id
			do_login(url);
		}
		return false;
	});
});


/*$(document).ready(function(){
	$('.popup-tousu-link').click(function(){

		tousu('', $(this).attr('skinid'),$(this).attr('skinname'));
		do_login('');
		return false;
	});
}); */

function douhao(strDouhao){
	var three=strDouhao.split(","); 
	if (three.length<4)
	return true;
	else 
	alert("标签数不能超过3个！");
}

function zishu(strZishu){
	if(window.navigator.userAgent.indexOf("Chrome") !== -1 )
	{
	}
	else{
		if (strZishu.length<21)
		return true;
		else {
		alert("皮肤名称字符数不能超过20个！");
		document.getElementById("scpf_skin_name").value=strZishu.substring(0,20);
		}
	}
}

function zishu2(strZishu){
	if (strZishu.length<21)
	return true;
	else {
	if(window.navigator.userAgent.indexOf("Chrome") !== -1 )
	{
		alert("皮肤名称字符数不能超过20个！");
	}
	document.getElementById("scpf_skin_name").value=strZishu.substring(0,20);
	}
}

function searchzishu(strZishu){
	if (strZishu.length<21)
	return true;
	else {
	alert("搜索字符数不能超过20个！");
	document.getElementById("search_skin_textbox").value=strZishu.substring(0,20);
	}
}	

var tishi = function(str){
	var   tsmsgw,tsmsgh,bordercolor;   
	tsmsgw=552;//提示窗口的宽度   
	tsmsgh=259;//提示窗口的高度   
	titleheight=25   //提示窗口标题高度   
	bordercolor="#336699";//提示窗口的边框颜色   
	titlecolor="#99CCFF";//提示窗口的标题颜色   
  
	var   tsWidth,tsHeight;   
	tsWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度   
	tsHeight=document.body.offsetHeight;//浏览器工作区域内页面高度   
  
  
  
	//背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）   
	var   bgObj=document.createElement("div");//创建一个div对象（背景层）   
	  
	//定义div属性，即相当于   
	// <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>   
	bgObj.setAttribute("id","bgDiv");  
	//alert("***********")  
	bgObj.style.position="absolute";   
	bgObj.style.top="0";   
	bgObj.style.background="#777";   
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";   
	bgObj.style.opacity="0.6";   
	bgObj.style.left="0";   
	bgObj.style.width=tsWidth   +  "px";   
	bgObj.style.height=tsHeight   +  "px";   
	bgObj.style.zIndex   =  "1000";   
	document.body.appendChild(bgObj);//在body内添加该div对象   
  
  
  
	var   msgObj=document.createElement("div")//创建一个div对象（提示框层）   
	//定义div属性，即相当于   
	// <div   id="msgDiv"   align="center"   style="background-color:white;   border:1px   solid   #336699;   position:absolute;   left:50%;   top:50%;   font:12px/1.6em   Verdana,Geneva,Arial,Helvetica,sans-serif;   margin-left:-225px;   margin-top:npx;   width:400px;   height:100px;   text-align:center;   line-height:25px;   z-index:100001;"> </div>   
	msgObj.setAttribute("id","msgDiv");   
	msgObj.setAttribute("align","center");   
	msgObj.style.background="url(css/images/ts_bg.png) 0 0 no-repeat";    
	msgObj.style.position   =  "absolute";   
	msgObj.style.left   =  "41%";   
	msgObj.style.top   =  "30%";   
	msgObj.style.font="12px/1.6em   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	msgObj.style.marginLeft   =  "-225px"   ;   
	msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+"px";   
	msgObj.style.width   =   tsmsgw   +  "px";   
	msgObj.style.height   = tsmsgh   +  "px";   
	msgObj.style.textAlign   =  "center";   
	msgObj.style.lineHeight   ="25px";   
	msgObj.style.zIndex   =  "10001";   
	//alert("***********")  
	var   title=document.createElement("h4");//创建一个h4对象（提示框标题栏）   
	//定义h4的属性，即相当于   
	// <h4   id="msgTitle"   align="right"   style="margin:0;   padding:3px;   background-color:#336699;   filter:progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);   opacity:0.75;   border:1px   solid   #336699;   height:18px;   font:12px   Verdana,Geneva,Arial,Helvetica,sans-serif;   color:white;   cursor:pointer;"   onclick=""> 关闭 </h4>   
	title.setAttribute("id","msgTitle");   
	title.setAttribute("align","right");   
	title.style.marginRight="27px";  
	title.style.marginLeft="28px";
	title.style.marginTop="28px";
	title.style.padding="3px"; 
	title.style.borderBottom="1px solid #E1E1E1";	
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);";   
	title.style.opacity="0.75";     
	title.style.height="35px";   
	title.style.font="12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	title.style.color="white"; 

	title.style.background="url(css/images/ws_line_fgx2.png) 28px 35px no-repeat"; 

	
	var titleword=document.createElement("img");  //创建标题
	titleword.setAttribute("id","titleid");
	titleword.style.float="left";
	titleword.setAttribute("src","css/images/ts_tishi.png");
	titleword.style.position   =  "absolute"; 
	titleword.style.top="45px";
	titleword.style.left="44px";
	
	
	var close=document.createElement("img");  //创建关闭按钮
	close.setAttribute("id","closeimg");  
	close.setAttribute("src","css/images/tousu_close.png");
	close.style.cursor="pointer";
	close.style.position   =  "absolute"; 
	close.style.top="28px";
	close.style.right="27px";
	close.onclick=removeObj;
	

	var tswords=document.createElement("div");  //创建提示信息
	tswords.setAttribute("id","tishiwords");
	//tswords.setAttribute("src","css/images/ts_words.png");
	tswords.innerHTML = str;
	//tswords.innerHTML = "皮肤已经上传，请勿重复提交！！！";
	tswords.style.position   =  "absolute"; 
	tswords.style.top="103px";
	tswords.style.left="130px";
	tswords.style.width="300px";
	tswords.style.height="50px";
	tswords.style.color="#000000"; 
	tswords.style.fontFamily="微软雅黑";
	tswords.style.fontSize="18px";
	
	var confirm=document.createElement("img");  //创建确定按钮
	confirm.setAttribute("id","confirmimg");  
	confirm.setAttribute("src","css/images/ts_confirm.png");
	confirm.style.cursor="pointer";
	confirm.style.position   =  "absolute"; 
	confirm.style.top="176px";
	confirm.style.left="222px";
	confirm.onclick=removeObj;
	
	/*var cancel=document.createElement("img");  //创建取消按钮
	cancel.setAttribute("id","closeimg");  
	cancel.setAttribute("src","css/images/ts_cancel.png");
	cancel.style.cursor="pointer";
	cancel.style.position   =  "absolute"; 
	cancel.style.top="176px";
	cancel.style.left="295px";
	cancel.onclick=removeObj;*/
	
	function   removeObj(){//点击标题栏触发的事件   
		document.body.removeChild(bgObj);//删除背景层Div   
		document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏   
		document.body.removeChild(msgObj);//删除提示框层   
	}   
	document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj   
	document.getElementById("msgDiv").appendChild(title);
	document.getElementById("msgDiv").appendChild(close);//在标题中添加关闭按钮   
	document.getElementById("msgTitle").appendChild(titleword); //在标题中添加文字标题
	document.getElementById("msgDiv").appendChild(tswords);
	document.getElementById("msgDiv").appendChild(confirm);
	//	document.getElementById("msgDiv").appendChild(cancel);
	var   txt=document.createElement("p");//创建一个p对象（提示框提示信息）   
	//定义p的属性，即相当于   
	// <p   style="margin:1em   0;"   id="msgTxt"> 测试效果 </p>   
	txt.style.margin="1em   0"   ;
	txt.setAttribute("id","msgTxt");   
	//txt.innerHTML=str;//来源于函数调用时的参数值   
	document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt      
	
}

var succeed = function(str){
	var   msgw,msgh,bordercolor;   
	msgw=712;//提示窗口的宽度   
	msgh=340;//提示窗口的高度   
	titleheight=25   //提示窗口标题高度   
	bordercolor="#336699";//提示窗口的边框颜色   
	titlecolor="#99CCFF";//提示窗口的标题颜色   
  
	var   sWidth,sHeight;   
	sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度   
	sHeight=document.body.offsetHeight;//浏览器工作区域内页面高度   
  
  
  
	//背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）   
	var   bgObj=document.createElement("div");//创建一个div对象（背景层）   
	  
	//定义div属性，即相当于   
	// <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>   
	bgObj.setAttribute("id","bgDiv");  
	//alert("***********")  
	bgObj.style.position="absolute";   
	bgObj.style.top="0";   
	bgObj.style.background="#777";   
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";   
	bgObj.style.opacity="0.6";   
	bgObj.style.left="0";   
	bgObj.style.width=sWidth   +  "px";   
	bgObj.style.height=sHeight   +  "px";   
	bgObj.style.zIndex   =  "1000";   
	document.body.appendChild(bgObj);//在body内添加该div对象   
  
  
  
	var   msgObj=document.createElement("div")//创建一个div对象（提示框层）   
	//定义div属性，即相当于   
	// <div   id="msgDiv"   align="center"   style="background-color:white;   border:1px   solid   #336699;   position:absolute;   left:50%;   top:50%;   font:12px/1.6em   Verdana,Geneva,Arial,Helvetica,sans-serif;   margin-left:-225px;   margin-top:npx;   width:400px;   height:100px;   text-align:center;   line-height:25px;   z-index:100001;"> </div>   
	msgObj.setAttribute("id","msgDiv");   
	msgObj.setAttribute("align","center");   
	msgObj.style.background="url(css/images/tousu_success_bg.png) 0 0 no-repeat";    
	msgObj.style.position   =  "absolute";   
	msgObj.style.left   =  "41%";   
	msgObj.style.top   =  "30%";   
	msgObj.style.font="12px/1.6em   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	msgObj.style.marginLeft   =  "-225px"   ;   
	msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+"px";   
	msgObj.style.width   =   msgw   +  "px";   
	msgObj.style.height   =msgh   +  "px";   
	msgObj.style.textAlign   =  "center";   
	msgObj.style.lineHeight   ="25px";   
	msgObj.style.zIndex   =  "10001";   
	//alert("***********")  
	var   title=document.createElement("h4");//创建一个h4对象（提示框标题栏）   
	//定义h4的属性，即相当于   
	// <h4   id="msgTitle"   align="right"   style="margin:0;   padding:3px;   background-color:#336699;   filter:progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);   opacity:0.75;   border:1px   solid   #336699;   height:18px;   font:12px   Verdana,Geneva,Arial,Helvetica,sans-serif;   color:white;   cursor:pointer;"   onclick=""> 关闭 </h4>   
	title.setAttribute("id","msgTitle");   
	title.setAttribute("align","right");   
	title.style.marginRight="27px";  
	title.style.marginLeft="28px";
	title.style.marginTop="28px";
	title.style.padding="3px"; 
	title.style.borderBottom="1px solid #E1E1E1";	
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);";   
	title.style.opacity="0.75";     
	title.style.height="35px";   
	title.style.font="12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";   
	title.style.color="white"; 

	title.style.background="url(css/images/ws_line_fgx2.png) 28px 35px no-repeat"; 

	
	var titleword=document.createElement("img");  //创建标题
	titleword.setAttribute("id","titleid");
	titleword.style.float="left";
	titleword.setAttribute("src","css/images/itousu.png");
	titleword.style.position   =  "absolute"; 
	titleword.style.top="45px";
	titleword.style.left="44px";
	
	
	var close=document.createElement("img");  //创建关闭按钮
	close.setAttribute("id","closeimg");  
	close.setAttribute("src","css/images/tousu_close.png");
	close.style.cursor="pointer";
	close.style.position   =  "absolute"; 
	close.style.top="28px";
	close.style.right="27px";
	close.onclick=removeObj;
	
    var successwords=document.createElement("div");
	successwords.setAttribute("id","sw");
	successwords.style.position = "absolute";
	successwords.style.top="125px";
	successwords.style.left="150px";
	successwords.style.width="373px";
	successwords.style.height="46px";
	successwords.style.background="url(css/images/sw.png) no-repeat scroll left center transparent";
	
	var closebutton=document.createElement("img");  //创建关闭按钮
	closebutton.setAttribute("id","closedown");  
	closebutton.setAttribute("src","css/images/tousu_close_07.png");
	closebutton.style.cursor="pointer";
	closebutton.style.position   =  "absolute"; 
	closebutton.style.top="210px";
	closebutton.style.left="295px";
	closebutton.onclick=removeObj;
	

	function   removeObj(){//点击标题栏触发的事件   
		document.body.removeChild(bgObj);//删除背景层Div   
		document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏   
		document.body.removeChild(msgObj);//删除提示框层   
	}   
	document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj                                                  
	document.getElementById("msgDiv").appendChild(title);
	document.getElementById("msgDiv").appendChild(close);//在标题中添加关闭按钮   
	document.getElementById("msgTitle").appendChild(titleword); //在标题中添加文字标题
	document.getElementById("msgDiv").appendChild(successwords);
	document.getElementById("msgDiv").appendChild(closebutton);
	var   txt=document.createElement("p");//创建一个p对象（提示框提示信息）   
	//定义p的属性，即相当于   
	// <p   style="margin:1em   0;"   id="msgTxt"> 测试效果 </p>   
	txt.style.margin="1em   0"   ;
	txt.setAttribute("id","msgTxt");   
	txt.innerHTML=str;//来源于函数调用时的参数值   
	document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt   
	
}
	
/* 创建每个网页顶部top_menu */
var init_top_menu = function(need_latest_msg, is_garden_page){
    var menu_div = document.getElementById("top-menu");
	var div_str = "";
	var skey = getCookie("skey");
	var uin = getCookie("uin");
	if (is_garden_page == "1"){
		div_str = "<a href=\"/\" class=\"go-home-link\" title=\"点击返回QQ输入法官网首页\">QQ输入法官网</a>";
	}
	/* 如果已经通过ptlogin登录，ajax请求个人信息 */
    if (skey != null && uin != null && skey != "" && uin != ""){        
		var page_header_callback = function(data){
            if (data.err < 0){
                menu_div.innerHTML = div_str + "<a href=\"javascript:do_login('');\">登录</a>&nbsp;|&nbsp;<a href=\"http://zc.qq.com/chs/index.html\">注册</a>";
            }
            /* 在标签上设置返回的值 */
            else{
				if (need_latest_msg == "1"){
					menu_div.innerHTML = div_str + "Hi, " + data.user_name + "&nbsp;|&nbsp;<a href=\"/skin/garden_uploaded_skins\">我的皮肤库</a>&nbsp;|&nbsp;<a href=\"/ucenter/msg_center\">消息盒子<span class=\"red\">(" + data.unread_msg_num + ")</span></a>&nbsp;|&nbsp;<a href=\"javascript:do_logout();\">退出</a>";
					if (data.latest_msg_content !=""){
						/* 最新消息页面弹出提示框 */
						msgBubble(data.latest_msg_content, 'http://shuru.qq.com/ucenter/msg_center');
					}
				}
				else{					
					menu_div.innerHTML = div_str + "Hi, " + data.user_name + "&nbsp;|&nbsp;<a href=\"/ucenter/msg_center\">消息盒子<span class=\"red\">(" + data.unread_msg_num + ")</span></a>&nbsp;|&nbsp;<a href=\"javascript:do_logout();\">退出</a>";
				}
            }
        };
        
        $.ajax({
        url:"/index/page_header?need_latest_msg=" + need_latest_msg,
        dataType:"json",
        success:page_header_callback
        });
    }
    else{
        menu_div.innerHTML = "<a href=\"javascript:do_login('');\">登录</a>&nbsp;|&nbsp;<a href=\"http://zc.qq.com/chs/index.html\">注册</a>";        
    }
};

/* 页面初始化时执行init_top_menu */
$(document).ready(function(){
	var top_menu = $('div#top-menu');
	if (!top_menu.size()) return;
	var is_garden_page = top_menu.attr('is_garden_page');
	var need_latest_msg = top_menu.attr('need_latest_msg');	
	init_top_menu(need_latest_msg, is_garden_page);
});


