function xoopsGetElementById(id){
	if (document.getElementById) {
		return (document.getElementById(id));
	} else if (document.all) {
		return (document.all[id]);
	} else {
		if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
			return (document.layers[id]);
		}
	}
}

function xoopsSetElementProp(name, prop, val) {
	var elt=xoopsGetElementById(name);
	if (elt) elt[prop]=val;
}

function xoopsSetElementStyle(name, prop, val) {
	var elt=xoopsGetElementById(name);
	if (elt && elt.style) elt.style[prop]=val;
}

function xoopsGetFormElement(fname, ctlname) {
	var frm=document.forms[fname];
	return frm?frm.elements[ctlname]:null;
}

function justReturn() {
	return;
}

function openWithSelfMain(url,name,width,height,returnwindow) {
	var options = "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";

	var new_window = window.open(url, name, options);
	window.self.name = "main";
	new_window.focus();
	if (returnwindow != null) {
	   return new_window;
	}
}

function setElementColor(id, color){
	xoopsGetElementById(id).style.color = "#" + color;
}

function setElementFont(id, font){
	xoopsGetElementById(id).style.fontFamily = font;
}

function setElementSize(id, size){
	xoopsGetElementById(id).style.fontSize = size;
}

function changeDisplay(id){
	var elestyle = xoopsGetElementById(id).style;
	if (elestyle.display == "") {
		elestyle.display = "none";
	} else {
		elestyle.display = "block";
	}
}

function setVisible(id){
	xoopsGetElementById(id).style.visibility = "visible";
}

function setHidden(id){
	xoopsGetElementById(id).style.visibility = "hidden";
}

function makeBold(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
		eleStyle.fontWeight = "bold";
	} else {
		eleStyle.fontWeight = "normal";
	}
}

function makeItalic(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.fontStyle != "italic") {
		eleStyle.fontStyle = "italic";
	} else {
		eleStyle.fontStyle = "normal";
	}
}

function makeUnderline(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.textDecoration != "underline") {
		eleStyle.textDecoration = "underline";
	} else {
		eleStyle.textDecoration = "none";
	}
}

function makeLineThrough(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.textDecoration != "line-through") {
		eleStyle.textDecoration = "line-through";
	} else {
		eleStyle.textDecoration = "none";
	}
}

function appendSelectOption(selectMenuId, optionName, optionValue){
	var selectMenu = xoopsGetElementById(selectMenuId);
	var newoption = new Option(optionName, optionValue);
	newoption.selected = true;
	selectMenu.options[selectMenu.options.length] = newoption;
}

function disableElement(target){
	var targetDom = xoopsGetElementById(target);
	if (targetDom.disabled != true) {
		targetDom.disabled = true;
	} else {
		targetDom.disabled = false;
	}
}
function xoopsCheckAll(formname, switchid) {
	var ele = document.forms[formname].elements;
	var switch_cbox = xoopsGetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if ( (e.name != switch_cbox.name) && (e.type == 'checkbox') ) {
			e.checked = switch_cbox.checked;
		}
	}
}

function xoopsCheckGroup(formname, switchid, groupid) {
	var ele = document.forms[formname].elements;
	var switch_cbox = xoopsGetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if ( (e.type == 'checkbox') && (e.id == groupid) ) {
			e.checked = switch_cbox.checked;
			e.click(); e.click();  // Click to activate subgroups
									// Twice so we don't reverse effect
		}
	}
}

function xoopsCheckAllElements(elementIds, switchId) {
	var switch_cbox = xoopsGetElementById(switchId);
	for (var i = 0; i < elementIds.length; i++) {
		var e = xoopsGetElementById(elementIds[i]);
		if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
			e.checked = switch_cbox.checked;
		}
	}
}

function xoopsSavePosition(id)
{
	var textareaDom = xoopsGetElementById(id);
	if (textareaDom.createTextRange) {
		textareaDom.caretPos = document.selection.createRange().duplicate();
	}
}

function xoopsInsertText(domobj, text)
{
	if(domobj.selectionEnd){
		var str1=domobj.value.substring(0, domobj.selectionStart);
		var str2=domobj.value.substring(domobj.selectionEnd, domobj.value.length);
		domobj.value = str1 + text + str2;
		domobj.selectionEnd = domobj.selectionStart;
		domobj.blur();	
	}else
	if (domobj.createTextRange && domobj.caretPos){
  		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;  
	} else if (domobj.getSelection && domobj.caretPos){
		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charat(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	} else {
		domobj.value = domobj.value + text;
  	}
}

function xoopsCodeSmilie(id, smilieCode) {
	var revisedMessage;
	var textareaDom = xoopsGetElementById(id);
	xoopsInsertText(textareaDom, smilieCode);
	textareaDom.focus();
	return;
}

function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl) {
	if (xoopsUrl == null) {
		xoopsUrl = "./";
	}
	imgDom = xoopsGetElementById(imgId);
	selectDom = xoopsGetElementById(selectId);
	if (selectDom.options[selectDom.selectedIndex].value != "") {
		imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
	} else {
        imgDom.src = xoopsUrl + "/images/blank.gif";
	}
}

function xoopsCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
	if (enterUrlPhrase == null) {
		enterUrlPhrase = "输入链接地址:";
	}
	if (enterWebsitePhrase == null) {
		enterWebsitePhrase = "输入网址标题:";
	}
	var text = prompt(enterUrlPhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var selection = getSelect(id);
		if (selection.length>0){
			var text2 = prompt(enterWebsitePhrase, selection);
		}else {
			var text2 = prompt(enterWebsitePhrase, "");
		}
		if ( text2 != null ) {
			if ( text2 == "" ) {
				var result = "[url=" + text + "]" + text + "[/url]";
			} else {
				var pos = text2.indexOf(unescape('%00'));
				if(0 < pos){
					text2 = text2.substr(0,pos);
				}
				var result = "[url=" + text + "]" + text2 + "[/url]";
			}
			xoopsInsertText(domobj, result);
		}
	}
	domobj.focus();
}

function xoopsCodeImg(id, enterImgUrlPhrase, enterImgPosPhrase, imgPosRorLPhrase, errorImgPosPhrase){
	if (enterImgUrlPhrase == null) {
		enterImgUrlPhrase = "输入图片地址:";
	}
	var selection = getSelect(id);
	if (selection.length>0){
		var text = prompt(enterImgUrlPhrase, selection);
	}else {
		var text = prompt(enterImgUrlPhrase, "");
	}
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		if (enterImgPosPhrase == null) {
			enterImgPosPhrase = "图片位置.";
		}
		if (imgPosRorLPhrase == null) {
			imgPosRorLPhrase = "'R' 或 'r' -- 右, 'L' 或 'l' -- 左, 或不填.";
		}
		if (errorImgPosPhrase == null) {
			errorImgPosPhrase = "ERROR! Enter the position of the image:";
		}
		var text2 = prompt(enterImgPosPhrase + "\n" + imgPosRorLPhrase, "");
		while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
			text2 = prompt(errorImgPosPhrase + "\n" + imgPosRorLPhrase,"");
		}
		if ( text2 == "l" || text2 == "L" ) {
			text2 = " align=left";
		} else if ( text2 == "r" || text2 == "R" ) {
			text2 = " align=right";
		} else {
			text2 = "";
		}
		var result = "[img" + text2 + "]" + text + "[/img]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeEmail(id, enterEmailPhrase){
	if (enterEmailPhrase == null) {
		enterEmailPhrase = "输入email地址:";
	}
	var selection = getSelect(id);
	if (selection.length>0){
		var text = prompt(enterEmailPhrase, selection);
	}else {
		var text = prompt(enterEmailPhrase, "");
	}
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[email]" + text + "[/email]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeQuote(id, enterQuotePhrase){
	if (enterQuotePhrase == null) {
		enterQuotePhrase = "输入要引用的文字:";
	}
	var selection = getSelect(id);
	if (selection.length>0){
		var text = prompt(enterQuotePhrase, selection);
	}else {
		var text = prompt(enterQuotePhrase, "");
	}
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var pos = text.indexOf(unescape('%00'));
		if(0 < pos){
			text = text.substr(0,pos);
		}
		var result = "[quote]" + text + "[/quote]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeCode(id, enterCodePhrase){
	if (enterCodePhrase == null) {
		enterCodePhrase = "输入要添加的代码.";
	}
	var selection = getSelect(id);
	if (selection.length>0){
		var text = prompt(enterCodePhrase, selection);
	}else {
		var text = prompt(enterCodePhrase, "");
	}
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[code]" + text + "[/code]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeText(id, hiddentext, enterTextboxPhrase){
	var textareaDom = xoopsGetElementById(id);
	var textDom = xoopsGetElementById(id + "Addtext");
	var fontDom = xoopsGetElementById(id + "Font");
	var colorDom = xoopsGetElementById(id + "Color");
	var sizeDom = xoopsGetElementById(id + "Size");
	var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
	var selection = getSelect(id);
	if (selection.length>0){
		var textDomValue = selection;
	}else {
		var textDomValue = textDom.value;
	}	
	var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
	var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
	var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
	if ( textDomValue == "" ) {
		if (enterTextboxPhrase == null) {
			enterTextboxPhrase = "Please input text into the textbox.";
		}
		alert(enterTextboxPhrase);
		textDom.focus();
	} else {
		if ( fontDomValue != "FONT") {
			textDomValue = "[font=" + fontDomValue + "]" + textDomValue + "[/font]";
			fontDom.options[0].selected = true;
		}
		if ( colorDomValue != "COLOR") {
			textDomValue = "[color=" + colorDomValue + "]" + textDomValue + "[/color]";
			colorDom.options[0].selected = true;
		}
		if ( sizeDomValue != "SIZE") {
			textDomValue = "[size=" + sizeDomValue + "]" + textDomValue + "[/size]";
			sizeDom.options[0].selected = true;
		}
		if (xoopsHiddenTextDomStyle.fontWeight == "bold" || xoopsHiddenTextDomStyle.fontWeight == "700") {
			textDomValue = "[b]" + textDomValue + "[/b]";
			xoopsHiddenTextDomStyle.fontWeight = "normal";
		}
		if (xoopsHiddenTextDomStyle.fontStyle == "italic") {
			textDomValue = "[i]" + textDomValue + "[/i]";
			xoopsHiddenTextDomStyle.fontStyle = "normal";
		}
		if (xoopsHiddenTextDomStyle.textDecoration == "underline") {
			textDomValue = "[u]" + textDomValue + "[/u]";
			xoopsHiddenTextDomStyle.textDecoration = "none";
		}
		if (xoopsHiddenTextDomStyle.textDecoration == "line-through") {
			textDomValue = "[d]" + textDomValue + "[/d]";
			xoopsHiddenTextDomStyle.textDecoration = "none";
		}
		xoopsInsertText(textareaDom, textDomValue);
		textDom.value = "";
		xoopsHiddenTextDomStyle.color = "#000000";
		xoopsHiddenTextDomStyle.fontFamily = "";
		xoopsHiddenTextDomStyle.fontSize = "12px";
		xoopsHiddenTextDomStyle.visibility = "hidden";
		textareaDom.focus();
	}
}

function xoopsValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
	var maxchars = 65535;
	var subjectDom = xoopsGetElementById(subjectId);
	var textareaDom = xoopsGetElementById(textareaId);
	var submitDom = xoopsGetElementById(submitId);
	if (textareaDom.value == "" || subjectDom.value == "") {
		if (plzCompletePhrase == null) {
			plzCompletePhrase = "请填写标题和内容.";
		}
		alert(plzCompletePhrase);
		return false;
	}
	if (maxchars != 0) {
		if (textareaDom.value.length > maxchars) {
			if (msgTooLongPhrase == null) {
				msgTooLongPhrase = "内容太长.";
			}
			if (allowedCharPhrase == null) {
				allowedCharPhrase = "允许的最大字符数: ";
			}
			if (currCharPhrase == null) {
				currCharPhrase = "现有字符长度: ";
			}
			alert(msgTooLongPhrase + "\n\n" + allowedCharPhrase + maxchars + "\n" + currCharPhrase + textareaDom.value.length + "");
			textareaDom.focus();
			return false;
		} else {
			submitDom.disabled = true;
			return true;
		}
	} else {
		submitDom.disabled = true;
		return true;
	}
}

function getSelect(id){
	if (window.getSelection){
		ele = document.getElementById(id);
		var selection = ele.value.substring(
			ele.selectionStart, ele.selectionEnd
		);
	}
	else if (document.getSelection){
		var selection = document.getSelection();
	}
	else if (document.selection){
		var selection = document.selection.createRange().text;
	}
	else{
		var selection = null;
	}
	return selection;
}
/*
function xoopsMulText(id, enterTextboxPhrase){
	
	var textDom = xoopsGetElementById(id + "Addtext");
	
	var sizeDom = xoopsGetElementById(id + "zhuangbei");
	var sizeDom1 = xoopsGetElementById(id);
	
	var selection = getSelect(id);
	if (selection.length>0){
		var textDomValue = selection;
	}else {
		var textDomValue = textDom.value;
	}	

	var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
	if ( textDomValue == "" ) {
		if (enterTextboxPhrase == null) {
			enterTextboxPhrase = "Please input text into the textbox.";
		}
		alert(enterTextboxPhrase);
		textDom.focus();
	} else {
		
		if ( sizeDomValue != "zhuangbei") {
			textDomValue =  sizeDomValue  + textDomValue;
			var option = new Option(textDomValue,textDomValue);
			var item = sizeDom1.options.length;
			sizeDom1.options[item] = option;
		
			sizeDom.options[0].selected = true;
		}
		
		//xoopsInsertText(textareaDom, textDomValue);
		textDom.value = "";
	
		//xoopsHiddenTextDomStyle.visibility = "hidden";
		//textareaDom.focus();
	}
}
function xoopsMulDelText(id){
	var zhuangbei = xoopsGetElementById(id);
	zhuangbei.options[zhuangbei.selectedIndex]=null;
	
}*/
function xoopsMulText(id, hiddentext, enterTextboxPhrase){
	var textareaDom = xoopsGetElementById(id);
	var textDom = xoopsGetElementById(id + "Addtext");
	
	var sizeDom = xoopsGetElementById(id + "zhuangbei");
	var sizeDom1 = xoopsGetElementById(id + "juyouzhuangbei");
	var zhuangbeiqita = xoopsGetElementById(id + "zhuangbeiqita");
	var pinpaiqita = xoopsGetElementById(id + "pinpaiqita");
	var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
	var selection = getSelect(id);
	if (selection.length>0){
		var textDomValue = selection;
	}else {
		var textDomValue = textDom.value;
	}	

	var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
	/*if ( textDomValue == "" ) {
	if (enterTextboxPhrase == null) {
			enterTextboxPhrase = "Please input text into the textbox.";
		}
		alert(enterTextboxPhrase);
		textDom.focus();
	} else {
		*/
       	if( zhuangbeiqita.value!="请选择装备品牌" &&  pinpaiqita.value !="请选择装备品牌")
		{
		//if ( sizeDomValue != "zhuangbei") {
			if (textDomValue!="")
			{
			textDomValue =  zhuangbeiqita.value+ " - " +pinpaiqita.value  + " - "+textDomValue;
			}
			else
			{
				textDomValue =  zhuangbeiqita.value +" - " + pinpaiqita.value ;
			}
			
			
			var option = new Option(textDomValue,textDomValue);
			var item = sizeDom1.options.length;
			sizeDom1.options[item] = option;
		
			sizeDom.options[0].selected = true;
		//}
		//textareaDom="";
		textareaDom.value="";
			for (var i = 0; i < item+1; i++) 
			{
		textDomValue=sizeDom1.options[i].value;
		xoopsInsertText(textareaDom, textDomValue +"\n" );
	         }
		
		}
		textDom.value = "";
	
		xoopsHiddenTextDomStyle.visibility = "hidden";
		textareaDom.focus();
	//}
}
function xoopsMulDelText(id){
	var zhuangbei = xoopsGetElementById(id + "juyouzhuangbei");
	var textareaDom = xoopsGetElementById(id);
	zhuangbei.options[zhuangbei.selectedIndex]=null;
	var textDomValue="";
	textareaDom.value="";
			for (var i = 0; i < zhuangbei.length; i++) 
			{
		textDomValue=zhuangbei.options[i].value;
		xoopsInsertText(textareaDom, textDomValue);
	         }
	
}
function zhuangbeiCL(id){
	var zhuangbei = xoopsGetElementById(id + "zhuangbei");
    var zhuangbeiqita = xoopsGetElementById(id + "zhuangbeiqita");
	var pinpai = xoopsGetElementById(id + "pinpai");
    zhuangbeiqita.value="";
    var zhuangbeitxt=zhuangbei.options[zhuangbei.options.selectedIndex].value;
for (m = pinpai.options.length-1; m > 0; m--)
 pinpai.options[m] = null
var group= new Array(zhuangbei.options.length)
     group[1]=new Array("请选择装备品牌","Granite Gear 花岗岩","ARC'TERYX 始祖鸟","Gregory 格里高里","SALEWA 沙乐华","Ozark 奥索卡","Aigle","Black Yak","Columbia 哥伦比亚","Osprey Packs","Outbound","Jack wolfskin 狼爪","The North Face 乐斯飞斯","Acme 阿珂姆","LAFUMA 乐飞叶","Vaude 沃德","Bigpack 派格","kolumb 哥伦布","One polar 极地","Mangrove 曼哥夫","pureland 普尔兰德","Scaler 思凯乐","K2 summit 凯图颠峰","Montfly 飞欧德","Nikko 日高","Toread 探路者","Vaude 沃德","其他")
    group[2]=new Array("请选择装备品牌","ARC'TERYX 始祖鸟","The North Face 乐斯飞斯","Ozark 奥索卡","SALEWA 沙乐华","Columbia 哥伦比亚","LAFUMA 乐飞叶","Life Unlimited 生活无限","snowwolf 雪狼","K2 summit 凯图颠峰","KAILAS CHINA","Montfly 飞欧德","Anemaqen 阿尼玛卿","AmazTEK 阿码斯","Atunas 欧都纳","pureland 普尔兰德","Nikko 日高","Toread 探路者","TrekSta","Black Yak","Vaude 沃德","其他")
	group[3]=new Array("请选择装备品牌","Garmont","Montail","Asolo","HBN","Salomon","Columbia","Lafum","Timberland","Nordica","TrekSta","MILLET","kolumb 哥伦布","Black yak","LAFUMA 乐飞叶","Columbia 哥伦比亚","Toread 探路者","Nikko 日高","PITORPAN潘比得","Ozark 奥索卡","The North Face 乐斯飞斯","其他")
   group[4]=new Array("请选择装备品牌","Black yak","Arid Out Door","Mountain Hardwear","Marmot","Coleman","Asage","The North Face 乐斯飞斯","Acme 阿珂姆","Monutain Hard Ware","K2 summit 凯图颠峰","pureland 普尔兰德","Toread 探路者","Ozark 奥索卡","其他")
    group[5]=new Array("请选择装备品牌","Black yak","Lafuma","Coleman","Marmot","ALPS Mountaineering","The North Face 乐斯飞斯","K2 summit 凯图颠峰","pureland 普尔兰德","Montfly 飞欧德","sanfo三夫","SheHe 极星户外","Toread 探路者","Ozark 奥索卡","Monutain Hard Ware","其他")
	group[6]=new Array("请选择装备品牌","Leki","Emson Line","Rei","Scarpa/Black Diamond","Alpina","Climb High","Black yak","Life-Link","Garmont","其他")
	group[7]=new Array("请选择装备品牌","Botaofoulder","Coleman","Wpcbrands","Exstreamwater","Mcnett","Optimususa","SunnyRec","Pyromid","Snowpeak","Gorp","Vaude","其他")
	group[8]=new Array("请选择装备品牌","Botaofoulder","Coleman","Wpcbrands","Exstreamwater","Coleman","Generalecology","Mcnett","Cfornc","Starnsinc","Purwater","Century camping","Sweetwaterfilters","Safewater any uhcre","Msrcorp","Lightisright","SunnyRec","Msrcorp","其他")
	group[9]=new Array("请选择装备品牌","Beal","Black Diamond","Bufo","petzl","其他")
 for (i = 0; i < group[zhuangbei.options.selectedIndex].length; i ++){
 pinpai.options[i] = new Option(group[zhuangbei.options.selectedIndex][i],group[zhuangbei.options.selectedIndex][i]);
 }
 pinpai.options[0].selected = true
	//var s=["zhuangbei","zhuangbeiqita"];
	//var opt0 = ["请选择装备类型","请选择装备品牌"];
    if (zhuangbeitxt=="其他")
    {
    zhuangbeiqita.value=zhuangbeitxt;
   // zhuangbeiqita.style="visibility:visible"
   //zhuangbeiqita.style.display="";
    zhuangbeiqita.disabled="";
    }
    else
    {
    	zhuangbeiqita.value=zhuangbeitxt;
    	//zhuangbeiqita.style.display="none";
    	 zhuangbeiqita.disabled="disabled";
    	 

    }
}
function pinpaiCL(id){
	var pinpai = xoopsGetElementById(id + "pinpai");
	var pinpaioqita = xoopsGetElementById(id + "pinpaiqita");
    pinpaioqita.value="";
    var pinpaitxt=pinpai.options[pinpai.options.selectedIndex].value;
    if (pinpaitxt=="其他")
    {
    pinpaioqita.value=pinpaitxt;
   // zhuangbeiqita.style="visibility:visible"
   pinpaioqita.disabled="";
    
    }
    else
    {    	pinpaioqita.value=pinpaitxt;
    	pinpaioqita.disabled="disabled";
     }

	
}

