var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function changecolor1(param1,param2,param3,content){
	div1 = document.getElementById(param1);
	div2 = document.getElementById(param2);
	div3 = document.getElementById(param3);

	div1.className='span2';
	document.getElementById('content').innerHTML = document.getElementById(content).innerHTML;
	div2.className='span1';
	div3.className='span1';
}

function changecolor2(param1,param2,param3,param4){
	div1 = document.getElementById(param1);
	div2 = document.getElementById(param2);
	div3 = document.getElementById(param3);
	div4 = document.getElementById(param4);

	div1.className='span4';
	div2.className='span3';
	div3.className='div1';
	div4.className='div2';
}

function changecolor3(param1,param2,param3,param4,iframe,src){
	div1 = document.getElementById(param1);
	div2 = document.getElementById(param2);
	div3 = document.getElementById(param3);
	div4 = document.getElementById(param4);

	div1.className='span4';
	div2.className='span3';
	div3.className='div1';
	div4.className='div2';
	if(src){
		document.frames[iframe].location=src;
	}
}

function loadiframe1(iframename,src){
	var iframe1 = document.createElement("iframe");
	iframe1.width=0;
	iframe1.height=0;
	iframe1.frameBorder=0;
	iframe1.id=iframename;
	iframe1.name=iframename;
	iframe1.style.visibility="hidden";
	iframe1.style.display="none";
	document.body.appendChild(iframe1);
	iiframe1 = window.frames[iframename];
	iiframe1.location=src;
}

function checkgovadd(){
	if(document.forms[0].name.value==''){
		alert('请填写主题！');
		return false;
	}
	if(document.forms[0].active.value==''){
		alert('请填写活动内容！');
		return false;
	}
	if(document.getElementById('pic1').value==''){
		document.forms[0].nopic1.value='1';
	}
	if(document.getElementById('pic2').value==''){
		document.forms[0].nopic2.value='1';
	}
	if(document.forms[0].address1.value==''){
		alert('请填写活动地点！');
		return false;
	}
	if(document.forms[0].address2.value==''){
		alert('请填写详细地址！');
		return false;
	}
	if(document.forms[0].number.value!=''&&!(/^[0-9]*[1-9][0-9]*$/).test(document.forms[0].number.value)){
		alert('请正确填写人数！');
		return false;
	}
	if(document.forms[0].number_m.value!=''&&!(/^[0-9]*[1-9][0-9]*$/).test(document.forms[0].number_m.value)){
		alert('请正确填写人数！');
		return false;
	}
	if(document.forms[0].number_f.value!=''&&!(/^[0-9]*[1-9][0-9]*$/).test(document.forms[0].number_f.value)){
		alert('请正确填写人数！');
		return false;
	}
	if(document.forms[0].number.value==''&&document.forms[0].number_m.value==''&&document.forms[0].number_f.value==''&&(document.forms[0].year_end.value=='--'||document.forms[0].month_end.value=='--'||document.forms[0].day_end.value=='--')){
		alert('请选择截止日期或者填写人数！');
		return false;
	}
	if(document.forms[0].price.value==''){
		alert('请填写人均消费！');
		return false;
	}
	if(document.forms[0].captain.value==''){
		alert('请填写发起人！');
		return false;
	}
	return true;
}

function checkungovadd(){
	if(document.forms[0].name.value==''){
		alert('请填写主题！');
		return false;
	}
	if (document.forms[0].pic.value){
		filename = document.forms[0].pic.value;
	      extension = filename.substring(filename.length-3, filename.length);
	      if (extension.toUpperCase()!='JPG' && extension.toUpperCase()!='GIF')
	      {
	        alert("图片必须为JPG或者GIF格式，请确认图片的格式！");	        
	        return false;
	      }
      }
	if(this.document.forms[0].link.value==''){
		alert('请填写链接地址！');
		return false;
	}
	return true;
}

function checkpagecontent(){
	if(this.document.form1.name.value==''){
		alert('请填写标题！');
		return false;
	}
	if(this.document.form1.author.value==''){
		alert('请填写作者！');
		return false;
	}
	return true;
}

function checkall(){
		if(document.form2.btnSelect.value=="全选"){
			for(var i=0;i<document.form2.del_shop_id.length;i++)
				document.form2.del_shop_id[i].checked=true;
			
			document.form2.btnSelect.value="取消";
		}else{
			for(var i=0;i<document.form2.del_shop_id.length;i++)
				document.form2.del_shop_id[i].checked=false;
			document.form2.btnSelect.value="全选";
		}
}

function del_govall(govid){
	result = confirm('您是否真的要删除？');
	if(result){
	oldhref = escape(window.location.href);
	ref = '?type=gov&action=del&govid_all='+govid+'&oldhref='+oldhref;
	window.location=ref;
	}
}

function del_ungovall(ungovid){
	result = confirm('您是否真的要删除？');
	if(result){
	oldhref = escape(window.location.href);
	ref = '?type=ungov&action=del&ungovid_all='+ungovid+'&oldhref='+oldhref;
	window.location=ref;
	}
}

function del_pagecontent(pageid){
	result = confirm('您是否真的要删除？');
	if(result){
	oldhref = escape(window.location.href);
	ref = './alllist.php?action=removepagecontent&pageid_all='+pageid+'&oldhref='+oldhref;
	window.location=ref;
	}
}

function del_user(govuserid_all){
	result = confirm('您是否真的要删除？');
	if(result){
	oldhref = escape(window.location.href);
	ref = '?action=removeuser&userid_all='+govuserid_all+'&oldhref='+oldhref;
	window.location=ref;
	}
}

function edit_gov(govid,area){
	oldhref = escape(window.location.href);
	ref = '?type=gov&action=edit&govid='+govid+'&area='+area+'&oldhref='+oldhref;
	window.location='./edit.php'+ref;
}

function edit_ungov(ungovid,area){
	oldhref = escape(window.location.href);
	ref = '?type=ungov&action=edit&ungovid='+ungovid+'&area='+area+'&oldhref='+oldhref;
	window.location='./edit.php'+ref;
}

function edit_pagecontent(pageid,area){
	oldhref = escape(window.location.href);
	ref = '?action=edit&pageid='+pageid+'&area='+area+'&oldhref='+oldhref;
	window.location='./editor.php'+ref;
}

function showpic(picpath,x,y){
	window.open("./showpic.php?pic="+picpath,"newwindow","toolbar=no,width=150,height=120,menubar=no,location=no,status=no,top="+y+",left="+x);
}

function show(id,e) {
  if (window.DOMObjects) {
    DOMElementShow(DOMObjects[id]);

    var x = DOMEventGetOffsetX(e) + 50;
    var y = DOMEventGetOffsetY(e) + 50;

    var width = DOMElementGetWidth(DOMObjects[id]);
    var innerWidth = DOMWindowGetInnerWidth();
    var xOffset = DOMWindowGetXOffset();

    var height = DOMElementGetHeight(DOMObjects[id]);
    var innerHeight = DOMWindowGetInnerHeight();
    var yOffset = DOMWindowGetYOffset();

    if (x > innerWidth + xOffset - width)
      x = innerWidth + xOffset - width - 25;

    if (y > innerHeight + yOffset - height)
      y = y - height - 75;

    DOMElementSetLeft(DOMObjects[id], x);
    DOMElementSetTop(DOMObjects[id], y);
  }
}

function hide() {
  if (DOMObjects && DOMObjects.length>0)
    for (var i=0; i<DOMObjects.length; i++)
      DOMElementHide(DOMObjects[i]);
}

function start() {
  if (window.DOMObjects)
    DOMInitialize('div');
}

function changenum(tag){
	tagvalue=eval('document.forms[0].'+tag+'.value');
	if(tagvalue=='1'){
	document.getElementById('num1span').className='flagspan2';
	document.getElementById('num2span').className='flagspan1';
	document.forms[0].number_m.value='';
	document.forms[0].number_f.value='';
	}
	else{
	document.getElementById('num2span').className='flagspan2';
	document.getElementById('num1span').className='flagspan1';
	document.forms[0].number.value='';
	}
}

function checkregister(){
	if(document.forms[0].user_id.value==''){
		alert('请先登陆！');
		return false;
	}
	if(document.forms[0].phone.value==''&&document.forms[0].mobile.value==''&&document.forms[0].address.value==''&&document.forms[0].email.value==''&&document.forms[0].zipcode.value==''){
		alert('请至少填写一种联络方式！');
		return false;
	}
	if(document.forms[0].mobile.value!=''&&!(/^[0-9]{8,13}/).test(document.forms[0].mobile.value)){
		alert('请正确填写移动电话！');
		return false;
	}
	if(document.forms[0].zipcode.value!=''&&!(/^[0-9]{6}$/).test(document.forms[0].zipcode.value)){
		alert('请正确填写邮政编码！');
		return false;
	}
	if(document.forms[0].email.value!=''&&!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(document.forms[0].email.value)){
		alert('请正确填写邮箱！');
		return false;
	}

	
	document.forms[0].submit();
}

function checkmail1(){
	if(document.forms['postmail1'].username.value==''){
		alert('请填写MSN邮箱');
		return false;
	}
	if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(document.forms['postmail1'].username.value)){
			alert('请正确填写MSN邮箱');
			return false;
	}
	document.forms['postmail1'].submit();
}

function checkmail11(){
    var str='';
    var myform = window.frames['listmail'].document.postlist;
	for(var i=0; i<myform.elements.length; i++){
	if(myform.elements[i].checked)
	str +=myform.elements[i].value+',';
	}
	if(str==''){
		alert('请选择好友邮箱');
		return false;
	}
	else{
	str = str.substr(0,str.length-1);
	document.forms['postmail11'].tomail.value = str;
	}
	if(document.forms['postmail11'].title.value==''){
		alert('请填写邀请主题');
		return false;
	}
	if(document.forms['postmail11'].content.value==''){
		alert('请填写邀请信息');
		return false;
	}
	document.forms['postmail11'].submit();
}

function checkmail3(){
	if(document.forms['postmail3'].title.value==''){
		alert('请填写邀请主题');
		return false;
	}
	if(document.forms['postmail3'].frommail.value==''){
		alert('请填写寄信人邮箱');
		return false;
	}
	if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(document.forms['postmail3'].frommail.value)){
			alert('请正确填写寄信人邮箱');
			return false;
		}
	if(document.forms['postmail3'].tomail.value==''){
		alert('请填写邀请人邮箱');
		return false;
	}
	var tostring = document.forms['postmail3'].tomail.value;
	if(tostring.indexOf(',')>0){
		toarray = tostring.split(',');
		for(var i=0; i<toarray.length; i++){
		if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(toarray[i])){
			alert('请正确填写邀请人邮箱');
			return false;
		}
		}
	}
	else if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(document.forms['postmail3'].tomail.value)){
			alert('请正确填写邀请人邮箱');
			return false;
	}
	
	if(document.forms['postmail3'].content==''){
		alert('请填写邀请信息');
		return false;
	}
	document.forms['postmail3'].submit();
}

function delpic(pictype,id,pic){
	if(pic){
	if(confirm('您确认删除该图片？')){
		document.frames['send'].location='./alllist.php?action=delpic&pictype='+pictype+'&delid='+id+'&pic='+pic;
	}
	}
}
