/*
	**********************************************
		Common functions for global system.
	**********************************************
*/

/*
	This function is used in:
	1.com/amjn/web/util/taglib/GoogleStylePageTag.java.
*/
function goPage(page){
    for(var i=0;i<document.forms.length;i++){
        var f=document.forms[i];
        if(f.name=="pageForm"){
            f.cpage.value=page;
            f.submit();
            break;
        }
    }
}

/*
	This function is used in:
	1./open/life/party/party/list.jsp.
	2./open/life/party/party/view.jsp.
	3./open/life/bbs/bbspub/list.jsp
	4./open/life/bbs/bbspub/listWonderful.jsp
	5./open/life/bbs/bbspub/view.jsp
	6./open/news/news/newsimg/list.jsp
	7./open/life/album/photo/list.jsp
	8./open/life/literature/chapter/list.jsp
	9./open/life/literature/article/view.jsp
*/
function submitFormByName(formName){
    for(var i=0;i<document.forms.length;i++){
        var f=document.forms[i];
        if(f.name==formName){
            f.submit();
            break;
        }
    }
}

/*
	This function is used in:
	1./open/eshop/webshop/common/prompt.jsp;
	2./open/life/virtual/common/prompt.jsp;
	3./open/eshop/company/common/prompt.jsp;
*/
function submitForm(formIndex){
	document.forms[formIndex].submit();
}

/*
	This function is used in:
	1./open/common/promptAutoForward.jsp;
	2./open/eshop/webshop/common/prompt.jsp;
	3./open/life/virtual/common/prompt.jsp;
	4./open/eshop/company/common/prompt.jsp;
*/
function delayAction(action,ms){
	setTimeout(action,ms);
}

function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

function isNumber(val){
	if(/[^\d]/.test(val)){
		return false;
	}
	return true;
}

/*
	This function is used in:
	1./open/eshop/trade/order/createForm.jsp;
*/
function selectDate(obj){
    temp = obj.size - 8
    if(temp<=0){
       	temp = 64 - -temp*6
    }else{
      	temp = 64 + temp*6
    }
    showx = event.screenX - event.offsetX - temp ;
    showy = event.screenY - event.offsetY + 18;
    newWINwidth = 210 + 4 + 18;
    retval = window.showModalDialog("/js/open/calendar.htm","", "dialogWidth:292px; dialogHeight:187px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;resizable:no;help:no");
    if( retval != null ){
      	obj .value = retval;
    }
}

/*
	This function is used in:
	1./open/eshop/webshop/shopdelivery/list.jsp;
	2./open/eshop/webshop/shopnews/list.jsp;
	3./open/eshop/webshop/shoppayment/list.jsp;
	4./open/life/virtual/virtualdiary/myDiaries.jsp;
	5./open/eshop/company/companyad/myAds.jsp;
	6./open/user/webuser/message/list.jsp
*/
function checkIfSelectedItem(item){
    if(item==null){
    	return;
    }
	if(item.type!='checkbox'){ // item is a array.
		for(var i=0;i<item.length;i++){
	        if(item[i].checked){
	          	return true;
	        }
	    }
	}
	else{ // item is only a object.
		if(item.checked){
            return true;
        }
	}
    alert('请选择条目.');
    return false;
}

var isRepeat=false;
function checkRepeatDo(){
	if(isRepeat){
		alert('系统正在提交，请稍候...');
		return false;
	}
	isRepeat=true;
	return true;
}

function getXMLHttpRequest(){
	var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	if(!xmlHttp){
		xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");
	}
	return xmlHttp;
}

/*
	************************************************
		Special functions for special purpose.
	************************************************
*/

/*
	This function is used in:
	1./open/eshop/webshop/shop/shopHome.jsp;
	2./open/life/virtual/virtualproposal/view.jsp
	3./open/life/virtual/virtualproposal/createForm.jsp
	3./open/user/webuser/communicate/list.jsp
*/
function checkIfInputedProposal(f){
	var proposal=trim(f.content.value);
	if(proposal.length==0){
		alert('请录入您的留言。');
		return false;
	}
	return true;
}

/*
	This function is used in:
	1./open/life/party/party/view.jsp
	2./open/eshop/post/postpub/view.jsp
	3./open/life/virtual/virtualdiary/view.jsp
	4./open/life/virtual/virtualmusic/view.jsp
	5./open/eshop/company/companycomment/list.jsp
	6./open/eshop/company/company/view.jsp
	7./open/life/album/photo/view.jsp
	8./open/life/literature/corpus/view.jsp
	9./open/life/literature/corpuscomment/list.jsp
	10./open/life/literature/article/view.jsp
	11./open/life/literature/articlecomment/list.jsp
*/
function checkIfInputedComment(f){
	var comment=trim(f.content.value);
	if(comment.length==0){
		alert('请录入您的评论。');
		return false;
	}
	return true;
}

/*
	This function is used in:
	1.checkChangedNum(var);
*/
function checkBuyNumRule(num){
	var numPattern=/^\d*$/;
	if(!numPattern.test(num)){
		alert('购买数量必须是数字。');
		return false;
	}
	if(num<1){
		alert('购买数量必须大于1个。');
		return false;
	}
	if(num>20){
		alert('尊敬的顾客，您一次性购买单种商品的最大数量不能超过20个,请重新填写。');
		return false;
	}
	return true;
}

/*
	This function is used in:
	1./open/eshop/webshop/shopcart/myCart.jsp;
*/
function checkChangedNum(f){
	var changedNum=f.changedNum;
	if(changedNum.type=='text'){
		return checkBuyNumRule(changedNum.value);
	}
	else{
		for(var i=0;i<changedNum.length;i++){
			if(!checkBuyNumRule(changedNum[i].value)){
				return false;
			}
		}
		return true;
	}
}

/*
	This function is used in:
	1./open/life/virtual/virtualperson/index.jsp;
	2./open/life/virtual/virtualperson/search.jsp;
*/
function checkMinAgeAndMaxAge(f){
	var minAge=f.minAge.value;
	var maxAge=f.maxAge.value;
	if(trim(minAge)==''||trim(maxAge)==''){
		alert('年龄没有填写。');
		return false;
	}
	var numPattern=/^\d*$/;
	if(!numPattern.test(minAge)||!numPattern.test(maxAge)){
		alert('填写的年龄非法。');
		return false;
	}
	return true;
}

/*
	This function is used in:
	1./open/life/virtual/virtualdiary/myDiaries.jsp
	2./open/eshop/company/companyad/myAds.jsp
	3./open/user/webuser/message/list.jsp
*/
function selectAll(obj,item){
    if(item==null){
    	return;
    }
	if(item.type!='checkbox'){ // item is a array.
		for(var i=0;i<item.length;i++){
	        item[i].checked=obj.checked;
	    }
	}
	else{ // item is only a object.
		item.checked=obj.checked;
	}
}

/*
	This function is used in:
	1./open/life/virtual/virtualperson/index.jsp
	2./open/life/virtual/virtualdiary/listDay.jsp
*/
function findAllDiariesByDate(selectedDay){
	var f=document.all("searchByDateForm");
	f.day.value=selectedDay;
	f.submit();
}

/*
	This function is used in:
	1.index.html
*/
function selectNews(divId){
	if(divId=='miyunNewsList'){
		document.all('miyunNewsListTd').background='/images/open/bg01_r.gif';
		document.all('miyunImgNewsTd').background='/images/open/bg01.gif';
		document.all('miyunLifeNewsTd').background='/images/open/bg01.gif';
		document.all('miyunAdvertNewsTd').background='/images/open/bg01.gif';
		document.all('miyunNewsList').style.display="";
		document.all('miyunImgNews').style.display="none";
		document.all('miyunLifeNews').style.display="none";
		document.all('miyunAdvertNews').style.display="none";
	}
	else if(divId=='miyunImgNews'){
		document.all('miyunNewsListTd').background='/images/open/bg01.gif';
		document.all('miyunImgNewsTd').background='/images/open/bg01_r.gif';
		document.all('miyunLifeNewsTd').background='/images/open/bg01.gif';
		document.all('miyunAdvertNewsTd').background='/images/open/bg01.gif';
		document.all('miyunNewsList').style.display="none";
		document.all('miyunImgNews').style.display="";
		document.all('miyunLifeNews').style.display="none";
		document.all('miyunAdvertNews').style.display="none";
	}
	else if(divId=='miyunLifeNews'){
		document.all('miyunNewsListTd').background='/images/open/bg01.gif';
		document.all('miyunImgNewsTd').background='/images/open/bg01.gif';
		document.all('miyunLifeNewsTd').background='/images/open/bg01_r.gif';
		document.all('miyunAdvertNewsTd').background='/images/open/bg01.gif';
		document.all('miyunNewsList').style.display="none";
		document.all('miyunImgNews').style.display="none";
		document.all('miyunLifeNews').style.display="";
		document.all('miyunAdvertNews').style.display="none";
	}
	else if(divId=='miyunAdvertNews'){
		document.all('miyunNewsListTd').background='/images/open/bg01.gif';
		document.all('miyunImgNewsTd').background='/images/open/bg01.gif';
		document.all('miyunLifeNewsTd').background='/images/open/bg01.gif';
		document.all('miyunAdvertNewsTd').background='/images/open/bg01_r.gif';
		document.all('miyunNewsList').style.display="none";
		document.all('miyunImgNews').style.display="none";
		document.all('miyunLifeNews').style.display="none";
		document.all('miyunAdvertNews').style.display="";
	}
}

function entranceChatRoom(chatRoomId){
    window.open("ChatRoomOpen.do?m=entrance&chatRoomId="+chatRoomId,"","scrollbars=yes,resizable=yes,width=800,height=600,toolbar=no,menubar=no,status=no,location=no");
}
