﻿/**
 * 清除字符串中的HTML
 */
String.prototype.stripHTML = function() {
	var reTag = /<(?:.|\s)*?>/g;
	return this.replace(reTag, "");
};

// 删除字符串两端的空格
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
// 删除字符串左端的空格
String.prototype.trimStart = function() {
	return this.replace(/(^\s*)/g, "");
}
// 删除字符串右端的空格
String.prototype.trimEnd = function() {
	return this.replace(/(\s*$)/g, "");
}
Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}
/**
 * 可变字符字符串
 */
this.StringBuilder = function() {
	this.__strings__ = new Array;
}
this.StringBuilder.prototype.append = function(str) {
	this.__strings__.push(str);
};
this.StringBuilder.prototype.toString = function() {
	return this.__strings__.join("");
};
/**
 * 格式化字符串
 */
String.format = function() {
	if (arguments.length == 0) {
		return null;
	}
	var str = arguments[0];
	for ( var i = 1; i < arguments.length; i++) {
		var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
		str = str.replace(re, arguments[i]);
	}
	return str;
}
function IsNull(value) {
	return (typeof (value) == "undefined" || value == null);
}
/* 父窗口打开网址 */
function openURL(url) {
	if (url && window.parent) {
		top.location.href = url;
	}
}
/* 判断浏览器版本 */
var isIE = navigator.userAgent.indexOf("MSIE") > 0;
var isFirefox = navigator.userAgent.indexOf("Firefox") > 0;
var isSafari = navigator.userAgent.indexOf("Safari") > 0;
var isCamino = navigator.userAgent.indexOf("Camino") > 0;
var isMozilla = navigator.userAgent.indexOf("Gecko") > 0;
var isIE6 = isIE7 = false;
if (isIE) {
	if (navigator.appVersion.match(/MSIE 7./i) == 'MSIE 7.') {
		isIE7 = true;
	}
	if (navigator.appVersion.match(/MSIE 6./i) == 'MSIE 6.') {
		isIE6 = true;
	}
}
/* 图片尺寸修改 */
function resizeImage(img, maxW, maxH) {
	var maxWidth = maxW; // 设置图片宽度界限
	var maxHeight = maxH; // 设置图片高度界限
	var heightWidth = img.height / img.width; // 设置高宽比
	var widthHeight = img.width / img.height; // 设置宽高比
	if (img.width > maxWidth) {
		img.width = maxWidth;
		img.height = maxWidth * heightWidth;
	}
	if (img.height > maxHeight) {
		img.height = maxHeight;
		img.width = maxHeight * widthHeight;
	}
}
/* 显示IFrame 遮罩窗口 */
function frameDialog(url, title, boxHeight, boxWidth) {
	var dialogBoxBg = document.createElement("div"); // 阴影层
	var dialogBox = document.createElement("div"); // 框层
	var dialogCtShadow = document.createElement("div")// 框阴影层
	var dialogTit = document.createElement("h2"); // 标题
	var dialogCt = document.createElement("div"); // 内容题
	dialogBoxBg.setAttribute("id", "dialogBoxBg");
	dialogCtShadow.setAttribute("id", "dialogCtShadow");
	dialogBox.setAttribute("id", "dialogBox");
	var width = document.documentElement.clientWidth
			+ document.documentElement.scrollLeft;
	var height = document.documentElement.clientHeight
			+ document.documentElement.scrollTop;
	document.body.appendChild(dialogBoxBg);
	document.body.appendChild(dialogBox);
	document.body.appendChild(dialogCtShadow);
	dialogBox.appendChild(dialogTit);
	dialogBox.appendChild(dialogCt);

	dialogBox.className = "dialogBox";
	dialogCt.className = "dialogCt";
	dialogCtShadow.className = "dialogCtShadow";
	dialogCt.style.height = boxHeight + "px";
	dialogBox.style.height = boxHeight + "px";
	dialogBox.style.width = boxWidth + "px";
	dialogBox.style.marginTop = -dialogBox.offsetHeight / 2
			+ document.documentElement.scrollTop + "px";
	dialogCtShadow.style.height = dialogBox.offsetHeight - 2 + "px";
	dialogCtShadow.style.marginTop = -dialogBox.offsetHeight / 2 + 5
			+ document.documentElement.scrollTop + "px";
	dialogCtShadow.style.width = dialogBox.offsetWidth - 2 + "px";
	dialogCtShadow.style.marginLeft = -(dialogBox.offsetWidth - 2) / 2 + 5
			+ "px"
	dialogTit.innerHTML = "<span onclick=\"closeEditor();\"></span>" + title;
	dialogCt.innerHTML = "<iframe  width=\"100%\" scrolling=\"no\" id=\"dialogConteiner\" style=\"overflow:hideen;height:88%;\" frameborder=\"0\"></iframe><div class=\"clear:both;\"></div>";
	document.getElementById("dialogConteiner").setAttribute("src", url);
	document.body.style.overflow = "hidden";
}
/* 关闭IFrame 遮罩窗口 */
function closeEditor() {
	document.body.removeChild(document.getElementById('dialogBoxBg'));
	document.body.removeChild(document.getElementById('dialogBox'));
	document.body.removeChild(document.getElementById('dialogCtShadow'));
	document.body.style.position = '';
	document.body.style.overflow = "";
}
jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
	return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};
onerror = function() {
	return;
}
function checkAll(field) {
	var checkflag = this.checked;
	alert(this.checked);
	field = document.getElementsByName(field)
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
	} else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
		}
		checkflag = "false";
	}
}
function jsSelectIsExitItem(objSelect, objItemValue) {        
    var isExit = false;        
    for (var i = 0; i < objSelect.options.length; i++) {        
        if (objSelect.options[i].value == objItemValue) {        
            isExit = true;        
            break;        
        }        
    }        
    return isExit;        
}
//1.判断select选项中 是否存在Value="paraValue"的Item        
function jsSelectIsExitItem(objSelect, objItemValue) {        
    var isExit = false;        
    for (var i = 0; i < objSelect.options.length; i++) {        
        if (objSelect.options[i].value == objItemValue) {        
            isExit = true;        
            break;        
        }        
    }        
    return isExit;        
} 
//2.向select选项中 加入一个Item        
function jsAddItemToSelect(objSelect, objItemText, objItemValue) {        
    //判断是否存在        
    if (!jsSelectIsExitItem(objSelect, objItemValue)){   
        var varItem = new Option(objItemText, objItemValue);      
        objSelect.options.add(varItem);     
    }        
}        
   
// 3.从select选项中 删除一个Item        
function jsRemoveItemFromSelect(objSelect, objItemValue) {        
    //判断是否存在        
    if (jsSelectIsExitItem(objSelect, objItemValue)) {        
        for (var i = 0; i < objSelect.options.length; i++) {        
            if (objSelect.options[i].value == objItemValue) {        
                objSelect.options.remove(i);        
                break;        
            }        
        }             
    }       
}
//4.删除select中选中的项    
function jsRemoveSelectedItemFromSelect(objSelect) {        
    var length = objSelect.options.length - 1;    
    for(var i = length; i >= 0; i--){    
        if(objSelect[i].selected == true){    
            objSelect.options[i] = null;    
        }    
    }    
}
//4.删除select中选中的项    
function jsGetItemValuesFromSelect(objSelect) {        
    var strValue = "";
    for (var i = 0; i < objSelect.options.length; i++) {        
    	strValue = strValue + "," + objSelect.options[i].value;  
    }
    return strValue;
} 
//5.修改select选项中 value="paraValue"的text为"paraText"        
function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) {        
    //判断是否存在        
    if (jsSelectIsExitItem(objSelect, objItemValue)) {        
        for (var i = 0; i < objSelect.options.length; i++) {        
            if (objSelect.options[i].value == objItemValue) {        
                objSelect.options[i].text = objItemText;        
                break;        
            }        
        }            
    }      
}
//6.设置select中text="paraText"的第一个Item为选中        
function jsSelectItemByValue(objSelect, objItemValue) {
    //判断是否存在        
    var isExit = false;        
    for (var i = 0; i < objSelect.options.length; i++) {        
        if (objSelect.options[i].value == objItemValue) {        
            objSelect.options[i].selected = true;
            isExit = true;        
            break;        
        }        
    }    
}
//7.设置select中value="paraValue"的Item为选中    
//document.all.objSelect.value = objItemValue;    
       
// 8.得到select的当前选中项的value    
//var currSelectValue = document.all.objSelect.value;    
       
// 9.得到select的当前选中项的text    
//var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;    
       
// 10.得到select的当前选中项的Index    
//var currSelectIndex = document.all.objSelect.selectedIndex;    
       
// 11.清空select的项    
//document.all.objSelect.options.length = 0
// ---------------------------------------------------
// 日期格式化
// 格式 YYYY/yyyy/YY/yy 表示年份
// MM/M 月份
// W/w 星期
// dd/DD/d/D 日期
// hh/HH/h/H 时间
// mm/m 分钟
// ss/SS/s/S 秒
// ---------------------------------------------------
Date.prototype.format = function(formatStr) {
	var str = formatStr;
	var Week = [ '日', '一', '二', '三', '四', '五', '六' ];
	str = str.replace(/yyyy|YYYY/, this.getFullYear());
	str = str.replace(/yy|YY/,
			(this.getYear() % 100) > 9 ? (this.getYear() % 100).toString()
					: '0' + (this.getYear() % 100));
	str = str.replace(/MM/, this.getMonth() > 9 ? this.getMonth().toString()
			: '0' + this.getMonth());
	str = str.replace(/M/g, this.getMonth());
	str = str.replace(/w|W/g, Week[this.getDay()]);
	str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString()
			: '0' + this.getDate());
	str = str.replace(/d|D/g, this.getDate());
	str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString()
			: '0' + this.getHours());
	str = str.replace(/h|H/g, this.getHours());
	str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes()
			.toString() : '0' + this.getMinutes());
	str = str.replace(/m/g, this.getMinutes());
	str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds()
			.toString() : '0' + this.getSeconds());
	str = str.replace(/s|S/g, this.getSeconds());
	return str;
}
function strToDate(str) {
	var arys = new Array();
	arys = str.split('-');
	if (arys.length <= 1) {
		arys = str.split('-');
	}
	var newDate = new Date(arys[0], arys[1], arys[2]);
	return newDate;
}
function getCookie(name) {
	var arr = document.cookie.match(new RegExp(name+"=([^&;]+)"));
	if(arr != null){return decodeURI(arr[1]);} 
	return "";
}
function writeUserName(){	
	var outurl=window.location.href;
	var str = ' <a href="http://my.58.com/login/?path='+outurl+'">登录</a>&nbsp;<a href="http://my.58.com/reg/">注册</a>';
	try
	{
		var msgcount = parseInt(getCookie("MsgUnReadTotal"))+parseInt(getCookie("SystemUnReadTotal"))+parseInt(getCookie("RequireFriendUnReadTotal"))+ parseInt(getCookie("CommentUnReadTotal"));
		if(getCookie("UserName") != ""){
			str='&nbsp;&nbsp;&nbsp;<a href="http://my.58.com/">'+getCookie("UserName")+'</a> <img alt="站内消息" hspace="4" src="http://pic.58.com/images/icoMail.gif" /><a  href="http://my.58.com/Liuyanjieshou/">('+msgcount+')</a> <a href="http://my.58.com/">用户中心</a> <a href="http://post.58.com/" class="link_red" style="text-decoration:none;">发布</a> <a href="http://my.58.com/ajax/loginout/?path='+outurl+'">退出</a>';}
		document.write(str);
		return true;
	}catch(e){
		document.write(str); return true;
	}
}
function SetHome(obj,vrl){
    try{
            obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
            if(window.netscape) {
                    try {
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                    }  
                    catch (e) { 
                            alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“加入收藏”后忽略安全提示，即可设置成功。");  
                    }
                    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                    prefs.setCharPref('browser.startup.homepage',vrl);
             }
    }
}
var changecity={
        mode:"iframe",
        url:"changecity.htm",
        ot:"",
        createFrame:function(){
           if(this.ot == ""){
              document.getElementById("all_city").innerHTML='<iframe id="chf" scrolling="no" width="400" height="210" src="'+this.url+'" frameborder="0"></iframe>';
           }else{
              document.getElementById("all_city").innerHTML='<iframe id="chf" scrolling="no" width="400" height="210" src="'+this.url+"?"+this.ot+'" frameborder="0"></iframe>';
           }
        },
        changeClass:function(className){
           if(className == "sc"){
	            if(!document.getElementById("chf")){
	              this.url="/changecity.htm";
	              this.createFrame();
	            }
           }
           document.getElementById('all_city').className = className;
        }
}

// 获取浏览器参数
function getUrlPara(paraName)
{var sUrl = location.href;
var sReg = "(?:\\?|&){1}"+paraName+"=([^&]*)";
var re=new RegExp(sReg,"gi");
re.exec(sUrl);
return RegExp.$1;
}

function del() {
	var msg = " 您真的确定要删除吗?";
	if (confirm(msg) == true) {
		return true;
	} else {
		return false;
	}
}

// 此处为独立函数
function LTrim(str) {
	var i;
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " " && str.charAt(i) != " ")
			break;
	}
	str = str.substring(i, str.length);
	return str;
}
function RTrim(str) {
	var i;
	for (i = str.length - 1; i >= 0; i--) {
		if (str.charAt(i) != " " && str.charAt(i) != " ")
			break;
	}
	str = str.substring(0, i + 1);
	return str;
}
function Trim(str) {
	return LTrim(RTrim(str));
} // JScript 文件


