//************************************************************************************
//获得写字板的内容
//参数：写字板字段名称
function getWordContent(field,wordframe){
	//field.value=window.WordContent.getHTML();
	var value = wordframe.getHTML();
	//window.alert(value+"\n"+isAllBlankEx(value));
	/*if(isAllBlank(value)){
		window.alert("不能全部输入空格符！");
		value = "";
	}*/
	if(isAllBlankEx(value)){
		window.alert("不能全部输入空格符！");
		value = "";
	}
    else{
	  field.value=value;
	}
	//window.alert(field.value);
}

//设置写字板的内容
//参数：写字板字段名称
function setWordContent(field,wordframe){
	//window.WordContent.insertHTML(field.value);
	wordframe.insertHTML(field.value);
}

//检查是否字符串全是空格符(&nbsp;&nbsp;&nbsp;&nbsp;)
//参数：字符串
//若全是空格符返回true
function isAllBlankEx(content){
    var regEx=new RegExp("^[&nbsp;]+$","gi");
	return regEx.test(content);
}

//检查输入的字串是否全为空格符
//参数：字段名
function checkAllBlank(field){
	var obj = document.all.item(field);
	//window.alert(obj);
	if(isAllBlank(obj.value)){
	  window.alert("不能全部输入空格符！");
	  obj.value = "";
	  obj.focus();
	}
}

//加入收藏夹
//页面使用：<a href=javascript:addBookmark('天极网网页陶吧','http://homepage.yesky.com/')>添加到收藏</a>
function addme(title,url) {
  window.external.AddFavorite(url,title); 
}

//自动调整图像大小
function autoPicResize(i,MaxW,MaxH){
  var o=new Image();
  o.src=i.src;
  var w=o.width;
  var h=o.height;
  var t;

  if(w>MaxW){
    t=MaxW;
  }
  else{
    t=w;
  }

  if((h*t/w)>MaxH){
    i.height=MaxH;i.width=MaxH/h*w;
  }
  else{
    i.width=t;i.height=t/w*h;
  }
}

//***************************************************************************************
 /* Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name,value,expires,path,domain,secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name,path,domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//打开日历选择框
function openCalendar(value) {
    var url = "../calendar.htm?field=" + value;
    window.showModelessDialog(url, window, "dialogHeight:230px;dialogWidth:200px;center:yes;help:no;resizable:no;scroll:no;");
}

/*  
*函数功能:从href获得参数 
*sHref: http://www.yesky.com/arg.htm?arg1=d&arg2=re  
*sArgName:arg1, arg2  
*return: the value of arg. d, re  
*/
function GetArgsFromHref(sHref, sArgName) {
    var args = sHref.split("?");
    var retval = "";
    if (args[0] == sHref) /*参数为空*/
    {
        return retval; /*无需做任何处理*/
    }
    var str = args[1];
    args = str.split("&");
    for (var i = 0; i < args.length; i++) {
        str = args[i];
        var arg = str.split("=");
        if (arg.length <= 1) continue;
        if (arg[0] == sArgName) retval = arg[1];
    }
    return retval;
}

//查看投票结果
function openVoteResult(url) {
    window.showModelessDialog(url, window, "dialogHeight:400px;dialogWidth:450px;center:yes;help:no;resizable:no;scroll:yes;");
}

//删除新闻图片
function delpic(t1,t2,t3){

   if(t1.checked){//删除图片
     t2.value = "";
   }
   else{
     t2.value = t3.value;
   }
   //window.alert(t2.value);
 }

 /*************************************************************************************************************************************/
 //使用FLASH广告
 function guanggao(width,height,pic,links,text){
    var focus_width=width
	var focus_height=height
	var text_height=0
	var swf_height = focus_height+text_height
	var pics=pic
	var links=links
	var texts=text
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='"+ focus_width +"' height='"+ swf_height +"'>");
	document.write("<param name='allowScriptAccess' value='sameDomain'><param name='movie' value='./images/playswf.swf'><param name=wmode value=transparent><param name='quality' value='high'>");
	document.write("<param name='menu' value='false'><param name='wmode' value='opaque'>");
	document.write("<param name='FlashVars' value='pics="+pics+"&links="+links+'&texts='+texts+"&borderwidth="+focus_width+"&borderheight="+focus_height+'&textheight='+text_height+"'>");
	document.write("<embed src='./images/playswf.swf' wmode='opaque' FlashVars='pics="+pics+"&links="+links+'&texts='+texts+"&borderwidth="+focus_width+"&borderheight="+focus_height+'&textheight='+text_height+"' menu='false' bgcolor='#DADADA' quality='high' width='"+ focus_width +"' height='"+ swf_height +"' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");	
}

//保存到购物车
function save2car(id){
  //setCookie("dmwcar","");
  var str = getCookie("dmwcar");
  //window.alert(str+","+id);
  if(str==null||str==""){
    str = id;
	setCookie("dmwcar",str);
	window.alert("商品已保存到购物车！");
  }
  else{
	var a = checkbuy(str,id);
	//window.alert(a);
	if(a){
		str = id+"#"+str;
		setCookie("dmwcar",str);
		window.alert("商品成功放入购物车！");
	}
	else{
		window.alert("该商品已经放进购物车了,不能重复放同样的商品。");
	}
  }
  //window.alert(str);
}

//检查是否购物车已经存在了该商品
function checkbuy(str,id){
	var a = false;
	var s = str.split("#");
	if(s.length>0){
	  for(var i=0;i<s.length;i++){
        if(s[i] == id){
			//break;
			a = false;
			break;
			//window.alert(a);
		}
		else{
			a = true;
		}
	  }//end for i
	}//end if s

	return a;
}

//从购物车删除
function delbuycar(id){
	var str = getCookie("dmwcar");
	if(str!=null&&str!=""){
        var s = str.split("#");
		if(s.length>0){
		   var nstr = "";
           for(var i=0;i<s.length;i++){
              if(s[i]!=null&&s[i]!=""&&s[i]!=id){
				  nstr =s[i]+"#"+nstr;
			  }
		   }

		   //window.alert(nstr);
           setCookie("dmwcar",nstr);
		   window.location.replace("buycar.asp");
		}//end if s
	}
	else{
		window.alert("购物车没有商品，不需删除。");
	}
}

function gotoPhotos(t){
	var url = "newsAction.asp?t="+t;
	XMLHttp.sendReqEx(url,photozone);
}

//分页跳转到指定页码
function gotoThePage(obj, url, maxpage) {
    if (window.event.keyCode == 13) {
        var the = obj.value;
        if (the == 0 || the == "") {
            window.alert("请输入需要跳转的页码，且页码不能为0。");
            obj.select();
        }
        else if (the > maxpage) {
            window.alert("不能超过最大页数！");
            obj.select();
        }
        else {

            if (url.indexOf("?") > 0) {
                if (url.lastIndexOf("&") > 0) {
                    url = url + "curpage=" + the;
                }
                else {
                    url = url + "&curpage=" + the;
                }
            }
            else {
                url = url + "?curpage" + the;
            }
            //window.alert(url);
            //gotoListShow(url);
            window.location.replace(url);
        }
    }
}

