﻿// JavaScript Document
function copyToClipBoard(urlname)
{
	var clipBoardContent=urlname;
	clipBoardContent+='\r\n' + window.document.location.href;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！\r\n\r\n内容如下：\r\n" + clipBoardContent);
}

String.prototype.Trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() { 
	return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() { 
	return this.replace(/(\s*$)/g, ""); 
} 

function position(thisobj, targetid){
        var posInfo = getPosition(thisobj);
        var tarObj = $(targetid);
        tarObj.style.top = posInfo.top + 'px';
        tarObj.style.left = posInfo.left + 'px';
        tarObj.style.display = 'block';
}

function getPosition(o)
{
   var temp={};
   temp.left=temp.right=temp.top=temp.bottom=0;
   var oWidth=o.offsetWith,oHeight=o.offsetheight;
   while(o!=document.body)
   {
       temp.left+=o.offsetLeft;
       temp.top+=o.offsetTop;
       o=o.offsetParent;
   }
   temp.right=temp.left+oWidth;
   temp.bottom=temp.top+temp.oHeight;
   return temp;
}

function dosearch(){
	if ($('skeyword').value.Trim() == ''){
		alert('请输入要搜索的关键字');
	}else	if ($('skeyword').value.Trim().length < 2){
		alert('关键字长度必须大于2');
	}else{
	self.location = "http://www.tyloo.com/search/"+$('skeyword').value.Trim()+"/"+$('smethod').value+"-1"
	}
}

function bbslogin(form){
	form.action = "http://bbs.tyloo.com/logging.php?action=login&amp;";
	form.submit();
}

function checkComment(){
	if ($('authorid').value==0 && $('email').value.Trim() == ''){
		alert("您若没有登录，请务必填写Email地址，以便我们联系您。\n天禄网绝对不会以任何方式泄露您的Email地址。");
		$('email').focus();
		return false;
	}
	if ($('content').value.length == 0){
		alert('您还没有输入任何评论');
		$('content').focus();
		return false;
	}
	xajax_checkVerify_js($('verify').value, $('checkverify').value);
	if ($('checkResult').value == 'false'){
		alert('验证码不正确');
		return false;
	}
	return true;
}

function showAndHide(objid){
	var object = $(objid);
	if (object != null && object != 'undifined'){
		if (object.style.display == 'none')
			object.style.display = 'block';
		else
			object.style.display = 'none';
	}
}
//
function showImages(imgname, imgurl, imgintro, imgwidth, imgheight, maxwidth, maxheight){
	var html = '';
	var newwidth = 0;
	var newheight = 0;
	newwidth = imgwidth;
	newheight = imgheight;
	if (newwidth >= maxwidth){
		newwidth = maxwidth;
		newheight = (imgheight / imgwidth) * newwidth;
	}
	if (newheight >= maxheight){
		newheight = maxheight;
		newwidth = (imgwidth / imgheight) * newheight;
	}
	document.getElementById(imgname).src = '/uploadfile/'+imgurl;
	document.getElementById(imgname).alt = imgintro;
	document.getElementById(imgname).width = newwidth;
	document.getElementById(imgname).height = newheight;
}

//预览杂志全屏窗口
function popFullMain(url){
	if(window.navigator.appName=="Microsoft Internet Explorer"){
		window.open(url, 'newwindow', 'channelmode=1,resizable=1');
	} else if(window.navigator.appName=="Netscape" || window.navigator.appName=="Opera"){
		//window.open(url, 'newwindow', "left=0,top=0,height="+screenY+",width="+screenX+",menubar=no,location=no,resizable=yes,scrollbars="+condScroll+",status=no");
		window.open(url, 'newwindow', 'channelmode=1,resizable=1');
	}
}

//最大化窗口
function maximizeWindow(){
	var offset = (navigator.userAgent.indexOf("Mac") !=-1|| navigator.userAgent.indexOf("Gecko") !=-1||navigator.appName.indexOf("Netscape") !=-1) ?0 : 4;
	window.moveTo(-offset, -offset);
	window.resizeTo(screen.availWidth + (2* offset), screen.availHeight + (2* offset));
}

//设置获取页面元素方法
function $(id){
	return document.getElementById(id);
}

function showList(listid, listcount){
	var tmp_lists;
	for (var x = 0; x < listcount; x++){
		tmp_lists = document.getElementsByName('hidden_'+x);
		if (tmp_lists.length > 0){
			for (var y = 0; y < tmp_lists.length; y++){
				tmp_lists[y].style.display = 'none';
			}
		}
	}
	
	var lists = document.getElementsByName('hidden_'+listid);
	for (var i = 0; i < lists.length; i++){
		lists[i].style.display = 'block';
	}
}

//Title: mouseover infomation
//Author: Liukang
//Date: 20070720
var s_defaultInfo;
function showMouseoverInfomation(s_info){
	if (s_info != null && s_info != "undifined")
		document.getElementById("mouseoverinfomation").innerText = s_info;
	else{
		if (s_defaultInfo != null && s_defaultInfo != "undifined")
			document.getElementById("mouseoverinfomation").innerText = s_defaultInfo;
		else
			return false;
	}
	if(!document.all) {
		x = document.body.scrollLeft + e.pageX; 
		y = document.body.scrollTop + e.pageY;
	}else{
		x = document.documentElement.scrollLeft + event.clientX;
		y = document.documentElement.scrollTop + event.clientY;
	}
	document.getElementById("mouseoverinfomation").style.left = String(x + 10) + "px";
	document.getElementById("mouseoverinfomation").style.top = y + "px";
	document.getElementById("mouseoverinfomation").style.display = "block";
	
	document.onmousemove = followMouse;
}

function hiddenMouseoverInfomation(){
	document.getElementById("mouseoverinfomation").style.display = "none";
	document.onmousemove = null;
	s_defaultInfo = null;
}

function followMouse(e){
	if(!document.all) {
		x = document.body.scrollLeft + e.pageX; 
		y = document.body.scrollTop + e.pageY;
	}else{
		x = document.documentElement.scrollLeft + event.clientX;
		y = document.documentElement.scrollTop + event.clientY;
	}
	document.getElementById("mouseoverinfomation").style.left = String(x + 10) + "px";
	document.getElementById("mouseoverinfomation").style.top = y + "px";
}

function setNewInfomation(s_info){
	if (s_info != null && s_info != "undifined")
		document.getElementById("mouseoverinfomation").innerText = s_info;
	else
		return false;
}

//Title: roll banner code
//Author: Liukang
//Date: 20070720
var a_imag = new Array();
var a_href = new Array();
var a_text = new Array();
var divname, imgname, pagename;
var i_num = 0;
var i_timeOut = 5000;
var timer;

var i_width = 800;
var i_height = 300;

function preloadImage(){
	var a_preloadedImage = new Array();
	for (var i = 0; i < a_imag.length; i++){
		a_preloadedImage[i] = new Image();
		a_preloadedImage[i].src = a_imag[i];
	}
}

function getPageNum(){
	var s_html = "<div style='width: " + String(i_width - a_imag.length * 30) + "px; height: 18px; display: block; float: left;'></div>";
	for (var i = 0; i < a_imag.length; i++){
		if (i != i_num)
			s_html += "<div id='page" + i + "' class='pagenumunselected' onclick='rollImageByHand(" + i + ");'>" + String(i + 1) + "</div>";
		else
			s_html += "<div id='page" + i + "' class='pagenumselected' onclick='rollImageByHand(" + i + ");'>" + String(i + 1) + "</div>";
	}
	document.getElementById(pagename).innerHTML = s_html;
}

function gotoImage(n){
	document.getElementById(imgname).src = a_imag[n];
	document.getElementById(imgname).onmouseover = showMouseoverInfomation_rollBanner;
	//单独为banner做的鼠标提示更新内容
	if (document.getElementById("mouseoverinfomation").style.display == "block")
		setNewInfomation(a_text[n]);
}

//单独为banner做的鼠标提示更新方法
function showMouseoverInfomation_rollBanner()
{
	showMouseoverInfomation(a_text[i_num-1]);
}

function rollImage(){
	if (i_num >= a_imag.length) i_num = 0;
	for (var i = 0; i < a_imag.length; i++){
		if (i != i_num)
			document.getElementById("page" + i).className = "pagenumunselected";
		else
			document.getElementById("page" + i).className = "pagenumselected";
	}
	setTransition();
	gotoImage(i_num);
	playTransition();
	i_num++;
	timer = setTimeout("rollImage()", i_timeOut);
}

function rollImageByHand(n){
	i_num = n;
	clearTimeout(timer);
	rollImage();
}

function gotourl(){
	var t_url = a_href[i_num - 1];
	var t_urltarget = "_blank";
	if (t_url != ""){
		if (t_urltarget == "_blank")
			window.open(t_url, t_urltarget);
		else
			location.href = t_url;
	}
}

function setTransition(){
	if (document.all){
		document.getElementById(imgname).filters.revealTrans.Transition=6;
		document.getElementById(imgname).filters.revealTrans.apply();
	}
}

function playTransition(){
	if (document.all)
	{
		document.getElementById(imgname).filters.revealTrans.play();
	}
}

function initBanner(){
	preloadImage();
	gotoImage(0);
	getPageNum();
	document.getElementById(divname).style.width = i_width;
	document.getElementById(divname).style.height = i_height;
	document.getElementById(imgname).style.width = i_width;
	document.getElementById(imgname).style.height = i_height;
	rollImage();
}


var http_request=false;
function send_request(url){//初始化，指定处理函数，发送请求的函数
  http_request=false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest){//Mozilla浏览器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//设置MIME类别
  http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE浏览器
try{
  http_request=new ActiveXObject("Msxml2.XMLHttp");
}catch(e){
  try{
  http_request=new ActiveXobject("Microsoft.XMLHttp");
  }catch(e){}
}
  }
if(!http_request){//异常，创建对象实例失败
window.alert("创建XMLHttp对象失败！");
return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式，URL，及是否同步执行下段代码
  http_request.open("GET",url,true);
http_request.send(null);
}
//处理返回信息的函数
  function processrequest(){
  if(http_request.readyState==4){//判断对象状态
  if(http_request.status==200){//信息已成功返回，开始处理信息
  document.getElementById(reobj).innerHTML=http_request.responseText;
}
else{//页面不正常
  alert("您所请求的页面不正常！");
}
  }
}
function checkfourm(obj){
  var f=document.fourm;
  var newfourm=f.newfourm.value;
  var username=f.username.value;
  var id=f.id.value;
  if(username==""){
      document.getElementById(obj).innerHTML="<img src=images/false.gif> <font color=red>您必须先登录！</font>";
  return false;
  }
  else if(newfourm==""){
  document.getElementById(obj).innerHTML="<img src=images/false.gif> <font color=red>您还没填写评论内容！</font>";
  return false;
  }
  else{
  document.getElementById(obj).innerHTML="正在发送数据...";
  send_request('sendnewfourm.php?username='+username+'&newfourm='+newfourm+'&id='+id);
  reobj=obj;
  }
}
function addhtml(obj,str){
	if(str == 'brand'){
		var row = '<div><input type="file" name="img_a[]" />  一句话简介：<input type="text" name="intro_a[]" size="40" />';
	}
	obj.innerHTML += row;
}
