
function selectAllCheckbox(obj) {
	var i = 0;
	if (obj[0] == null) {
		obj.checked = true;
	} else {
		for (i = 0; i < obj.length; i++) {
			obj[i].checked = true;
		}
	}
}
function setElementDisabled() {
	var i = 0;
	for (i = 0; i < document.all.length; i++) {
		document.all[i].disabled = true;
	}
}
function setDisabled(objs, flag) {
	var i = 0;
	if (objs[0] == null) {
		ojbs.disabled = flag;
	} else {
		for (i = 0; i < objs.length; i++) {
			objs[i].disabled = flag;
		}
	}
}
function Item(text, value) {
	this.text = text;
	this.value = value;
}
function AddToList(Dest, Item) {
	var hasOne = false;
	var i;
	for (i = 0; i < Dest.options.length; i++) {
		if (Dest.options[i].value == Item.value) {
			hasOne = true;
			break;
		}
	}
	if (!hasOne) {
		Dest.options.length = Dest.options.length + 1;
		i = Dest.options.length - 1;
		Dest.options[i].text = Item.text;
		Dest.options[i].value = Item.value;
	}
}
function opt(txt, val, sel) {
	this.txt = txt;
	this.val = val;
	this.sel = sel;
}
function RemoveFromList(TheList, index) {
	var i;
	var j;
	for (i = 0; i < TheList.options.length; i++) {
		if (i == index) {
			//remove from list
			for (j = index; j < TheList.options.length - 1; j++) {
				TheList.options[j].text = TheList.options[j + 1].text;
				TheList.options[j].value = TheList.options[j + 1].value;
			}
			TheList.options.length = TheList.options.length - 1;
		}
	}
}
function DoMoveBetweenLists(Source, Destination, Msg, Remove) {
	var SourceList = Source;
	var DestinationList = Destination;
	//var SelectedItem = new Array;
	if (Remove != true) {
		Remove = false;
	}
	var SourceOK = false;
	var i;
	for (i = 0; i < SourceList.options.length; i++) {
		if (SourceList.options[i].selected) {
			SelectedItem = new Item(SourceList.options[i].text, SourceList.options[i].value);
			if (Remove) {
				RemoveFromList(SourceList, i);
			}
			AddToList(DestinationList, SelectedItem);
			SourceOK = true;
		}
	}
	if (!SourceOK) {
		alert(Msg);
	}
}
function DoRemoveFromList(Source, Msg) {
	var SourceList = Source;
	var SelectedItem = new Array;
	var SourceOK = false;
	var i = 0, j = 0;
	for (i = 0; i < SourceList.options.length; i++) {
		if (SourceList.options[i].selected) {
			SourceList.options[i].value = "";
			j++;
			SourceOK = true;
		}
	}
	if (SourceOK) {
		if (SourceList.options.length > 30) {
			RemoveFromListQuick(SourceList);
		} else {
			RemoveFromListBlank(SourceList);
		}
	}
	if (!SourceOK) {
		alert(Msg);
	}
}
function RemoveFromListQuick(TheList) {
	var i = 0;
	k = 0;
	var j = TheList.options.length - 1;
	for (i = 0; i < TheList.options.length; i++) {
		if (TheList.options[i].value == "") {
			while (j > i) {
				if (TheList.options[j].value != "") {
					TheList.options[i].text = TheList.options[j].text;
					TheList.options[i].value = TheList.options[j].value;
					TheList.options[j].value = "";
					break;
				} else {
					j--;
				}
			}
			if (i > j) {
				break;
			}
		}
	}
	for (k = i - 1; k < TheList.options.length; k++) {
		if (TheList.options[k].value == "") {
			TheList.options.length = k;
			break;
		}
	}
}
function RemoveFromListBlank(TheList) {
	var i = 0;
	var j = 0;
	//remove blank from list
	while (j < TheList.options.length) {
		if (TheList.options[j].value == "") {
			i = j;
			while (i < TheList.options.length - 1) {
				TheList.options[i].text = TheList.options[i + 1].text;
				TheList.options[i].value = TheList.options[i + 1].value;
				i++;
			}
			TheList.options.length = TheList.options.length - 1;
		} else {
			j++;
		}
	}
}
function showWeek(month, Dest) {
	var i;
	var size = month % 3;
	if (size == 0) {
		size = 5;
	} else {
		size = 4;
	}
	if (Dest.options) {
		Dest.options.length = 0;
	}
	for (i = 0; i < size; i++) {
		Dest.options[i] = new Option(i + 1, i + 1);
	}
}
function fillIntoList(array, list) {
	if (!array) {
		return;
	}
	if (!list) {
		return;
	}
	for (var i = 0; i < array.length; i++) {
		list.options[i] = new Option(array[i], array[i]);
	}
}

// This function is for stripping leading and trailing spaces
function trim(str) {
	if (str != null) {
		var i;
		for (i = 0; i < str.length; i++) {
			if (str.charAt(i) != " ") {
				str = str.substring(i, str.length);
				break;
			}
		}
		for (i = str.length - 1; i >= 0; i--) {
			if (str.charAt(i) != " ") {
				str = str.substring(0, i + 1);
				break;
			}
		}
		if (str.charAt(0) == " ") {
			return "";
		} else {
			return str;
		}
	}
}
function moveOption(obj, to) {
	if (!obj) {
		return false;
	}
	list = obj;
	var total = list.options.length;
	index = list.selectedIndex;
	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total - 1) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}
	to = index + to;
	var opts = new Array();
	for (i = 0; i < total; i++) {
		opts[i] = new opt(list.options[i].text, list.options[i].value, list.options[i].selected);
	}
	tempOpt = opts[to];
	opts[to] = opts[index];
	opts[index] = tempOpt;
	list.options.length = 0; // clear    
	for (i = 0; i < opts.length; i++) {
		list.options[i] = new Option(opts[i].txt, opts[i].val);
		list.options[i].selected = opts[i].sel;
	}
	list.focus();
}
function IIF(exp, val1, val2) {
	if (exp) {
		return val1;
	} else {
		return val2;
	}
}
function isSeqString(str) {
	if (str.length > 1) {
		result = true;
		tmp = str.charAt(0).charCodeAt();
		for (i = 1; i < str.length; i++) {
			if (tmp != str.charAt(i).charCodeAt() - 1) {
				result = false;
				break;
			}
			tmp = str.charAt(i).charCodeAt();
		}
		return result;
	} else {
		return false;
	}
}
function getPageNum(str) {
	if (str.length > 1) {
		num = parseInt(str);
		if (isNaN(num)) {
			return 1;
		} else {
			if (num > 0) {
				return num;
			} else {
				return 1;
			}
		}
	} else {
		return 1;
	}
}
function GetUp(obj) {
	var i, j;
	i = obj.selectedIndex;
	j = i - 1;
	if (i > 0) {
		Temp_Text = obj.options(j).text;
		Temp_ID = obj.options(j).value;
		obj.options(j).text = obj.options(i).text;
		obj.options(j).value = obj.options(i).value;
		obj.options(i).text = Temp_Text;
		obj.options(i).value = Temp_ID;
		obj.selectedIndex = j;
	}
}
function GetDown(obj) {
	var i, j;
	i = obj.selectedIndex;
	if (i != obj.length - 1) {
		j = i + 1;
		if (i < obj.length) {
			Temp_Text = obj.options(j).text;
			Temp_ID = obj.options(j).value;
			obj.options(j).text = obj.options(i).text;
			obj.options(j).value = obj.options(i).value;
			obj.options(i).text = Temp_Text;
			obj.options(i).value = Temp_ID;
			obj.selectedIndex = j;
		}
	}
}

// =========================================================================
//                          Cookie functions
// =========================================================================
/* This function is used to set cookies */
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" : "");
}
/* This function is used to get cookies */
function getCookie(name) {
	var prefix = name + "=";
	var start = document.cookie.indexOf(prefix);
	if (start == -1) {
		return null;
	}
	var end = document.cookie.indexOf(";", start + prefix.length);
	if (end == -1) {
		end = document.cookie.length;
	}
	var value = document.cookie.substring(start + prefix.length, end);
	return unescape(value);
}
/* This function is used to delete cookies */
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";
	}
}
var handleError = function (errorString, exception) {
	window.status = "\u4fe1\u606f\uff1a" + errorString + " " + dwr.util.toDescriptiveString(exception, 2);
};
var handleWarnning = function (errorString, exception) {
	window.status = "\u8b66\u544a\uff1a" + errorString + " " + dwr.util.toDescriptiveString(exception, 2);
};
function open5107ChatWin(id, opid) {
	var url = "http://shangji.5107.cn/v4/chat/chat.php?msgType=sec&vcwStyle=0&vcwColor=0&vcwLang=gb2312&smwStyle=0&smwColor=0&company=" + id;
	if (opid != "" && opid != 0) {
		url += "&opid=" + opid + "&srcType=1";
	}
	try {
		var f = window.open(url, "_blank", "toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,width=690,height=543,resizable=no,left=0,top=0, status=no");
		f.focus();
	}
	catch (e) {
	}
}
function openShiXunChatWin(code, name, rs) {
	var url = "http://www.tv2tel.com/eyetel.asp?enumber=" + code + "&username=" + name + "&rs=" + rs;
	try {
		var f = window.open(url, "_blank", "toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,width=690,height=543,resizable=no,left=0,top=0, status=no");
		f.focus();
	}
	catch (e) {
	}
}

