window.onload = function()
{
	wm_init();

}

function wm_init()
{
	 show_fck();	
	 winput();
	 addHintInfo();
	 quick_menu();
	 do_lock();
	 //setInterval("do_lock()",2000);

}



function noscroll()
{
	if (document.body.clientHeight<document.body.scrollHeight )
	{
		//
	}
}

function show_pic_muti_preview( imgstr , pre )
{
	
	imgs = $(imgstr).value.split("\r\n");
	//alert( imgstr );
	//alert( imgs );
	//alert( imgs.length );
	if( imgs.length > 0 )
	{
		$(pre).innerHTML = '';
		for( i = 0 ; i < imgs.length ; i++ )
		{
			if( imgs[i].length > 10 )
				$(pre).innerHTML += '<img src="' + imgs[i] + '" lock="50" onload="do_lock()" onclick="window.open(this.src)" style="cursor:pointer"/>&nbsp;';
		}
		
	}

	do_lock();
	
}

function do_lock()
{
	imgs = document.getElementsByTagName( 'IMG' );
	for( i = 0 ; i < imgs.length ; i++ )
	{
		size = parseInt( imgs[i].getAttribute("lock") );
		if( size > 0  )
		{
			if( imgs[i].width > size )
				imgs[i].width = size;

			//alert( imgs[i].width );
		}
	}
}

function winput()
{
	var obj = document.getElementsByTagName('INPUT');
	try
	{
		if( obj.length < 1 )
		{
			return false;
		} 
		
		for( i=0 ;i < obj.length; i++)
		{
			if( obj[i].getAttribute("wclass") )
			{
				if( obj[i].value == '' )
					obj[i].className = "w" + obj[i].getAttribute("wclass") + " winput";
				else
					obj[i].className = "winput";
				obj[i].onfocus = function(){ this.className = "winput"; };
				obj[i].onblur = function(){ if(this.value == '') this.className = "w" + this.getAttribute("wclass") + " winput"; };
			}

		}	
	}
	catch (e)
	{
	
	  
	} 

}

function copyText(obj) 
{
	ie = (document.all)? true:false
	if (ie)
	{
		var rng = document.body.createTextRange();
		rng.moveToElementText($(obj));
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
		alert( '已经将内容复制到剪贴板，你可以使用Ctrl+v将内容转贴到其他的编辑器上' );
	}
}

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(Element.extend(element));
  }
  return results.length < 2 ? results[0] : results;
}

Object.extend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}

function quick_menu()
{
	if( !$('qmenu')) return false; 
	
	$('qmenu').onmouseover = function()
	{
		//xy = Position.page( $('qmenu') );
		//alert( xy[0] );
		/*
		$('qmenu_pop').setStyle({left:xy[0]});
		$('qmenu_pop').setStyle({top:xy[1]});
		*/
		$('qmenu_pop').style.left = 240; 
		$('qmenu_pop').style.top = 56;
		$('qmenu_pop').style.display = 'block';
	}

	$('qmenu').onmouseout = function()
	{
		$('qmenu_pop').style.display = 'none';
	}
}


function show_fck()
{
	var replaced = Array();
	var ii = 0;
	var in_it = 0;
	var obj = document.getElementsByTagName('textarea');
	try
	{
		if( obj.length < 1 )
		{
			return false;
		} 
		
		for( i=0 ;i < obj.length; i++)
		{
			if( obj[i].type == "textarea" && obj[i].getAttribute("rel") == "fck" )
			{
				in_it = 0;
				for( key in replaced )
				{
					if( replaced[key] == obj[i].id )
					{
						in_it = 1;
					} 
				}
				
				if( in_it == 0 )
				{
					//alert(obj[i].id);
			
					replaced[ii] = obj[i].id;
					ii++;

					
					
					var oFCKeditor = new FCKeditor( obj[i].id ) ;
					oFCKeditor.BasePath = "lib/" ;
					if( obj[i].getAttribute("toolbar")  )
					{
						oFCKeditor.ToolbarSet = obj[i].getAttribute("toolbar");
					}
					else
					{
						oFCKeditor.ToolbarSet = "Basic";
					}
					
					// get the width and height of textarea
					//alert( parseInt( obj[i].getAttribute("height") ) );
					if( parseInt( obj[i].getAttribute("height") ) > 0 )
					{
						oFCKeditor.Height = parseInt( obj[i].getAttribute("height") ) ;
						//alert( oFCKeditor.Height );
					}
					
					if( parseInt( obj[i].getAttribute("width") ) > 0 )
					{
						oFCKeditor.Width = parseInt( obj[i].getAttribute("width") ) ;
					}
					oFCKeditor.ReplaceTextarea() ;
				}

				
			}

		}	
	}
	catch (e)
	{
	
	  
	} 
	
	
}

var rate_array = Array();

function rate_set_value( mid , id , value , def )
{
	name = 'rate_' + mid + '_' + id;
	//alert( rate_array['name'] );
	if ( rate_array[name] == value )
	{
		return false;
	}
	else
	{	
		var url = '?a=ajax_show_star&v=' + value + '&mid=' + mid + '&id=' + id + '&d=' + def;
		var pars = '';
		var myAjax = new Ajax.Updater( name , url, {method: 'post', parameters: pars});
		rate_array[name] = value;
	}
}


function zoomin( name )
{
	
	//$(name).style.width = parseInt( $(name).style.width ) + 40 + 'px';
	$(name).style.height = parseInt( $(name).style.height ) + 40 + 'px';
}

function zoomout( name )
{
	
	if( parseInt( $(name).style.width ) > 80 &&  parseInt( $(name).style.height ) > 80  )
	{
		//$(name).style.width = parseInt( $(name).style.width ) - 40 + 'px';
		$(name).style.height = parseInt( $(name).style.height ) - 40 + 'px';
	} 	
}

function set( name , value )
{
	var objs = document.getElementsByName( name );
	if( objs[0] )
	{
		switch( objs[0].type )
		{
			case 'radio': 
				return set_radio( name , value  );
				break;
			case 'select-one': 
				return set_select( name , value  );
				break;
			case 'checkbox': 
				return set_checkbox( name , value  );
				break;
			case 'textarea':
				set_text( name , value );
				break;
			case 'text':
			default: return set_text( name , value );
		}
	}
	
}

function set_text( name , value )
{
	var el = getElement( name );
	el.value = value;
}

 function getElement( name )
 {
	var el = document.getElementsByName( name );
	if( el[0] == null )
	{
		alert( 'cannot find ' + name + ' ! ' );
	}
	else
	{
		return el[0];
	}
	
 }

function set_checkbox( name , value )
{
	var obj = document.getElementsByName( name );
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].type=="checkbox")
		{
			if( obj[i].value == value )
			{
				obj[i].checked = true;
			}
		}
	}
}

function checkbox_on( name )
{
	var obj = document.getElementsByName( name );
	for(var i=0;i<obj.length;i++)
	{
		obj[i].checked = true;
	}

}

function checkbox_off( name )
{
	var obj = document.getElementsByName( name );
	for(var i=0;i<obj.length;i++)
	{
		obj[i].checked = false;
	}

}

function set_select_text( name , value )
{
	var sel = getElement( name );
	var ops = sel.options;
	for( var i = 0 ; i < ops.length ; i++ )
	{
		if( ops[i].text == value  )
		{
			try
			{
				if( i != ops.selectedIndex )
				{
					ops.selectedIndex = i;
					ops[i].selected = true;
				}
				
			}
			catch( e ) 
			{
				// alert( e.description );
				// ie对于动态生成的下拉框会抛出一个“不能设置selected属性，未指明的错误”的异常
				// 原因不明，先不做处理
			}
			
			
		}
	}
}

function set_select( name , value )
{
	var sel = getElement( name );
	var ops = sel.options;
	for( var i = 0 ; i < ops.length ; i++ )
	{
		if( ops[i].value == value  )
		{
			try
			{
				if( i != ops.selectedIndex )
				{
					ops.selectedIndex = i;
					ops[i].selected = true;
				}
				
			}
			catch( e ) 
			{
				// alert( e.description );
				// ie对于动态生成的下拉框会抛出一个“不能设置selected属性，未指明的错误”的异常
				// 原因不明，先不做处理
			}
			
			
		}
	}
}


function set_radio( name , value )
{
	var objRadio = document.getElementsByName( name );
	for(var i=0;i<objRadio.length;i++)
	{
		if(objRadio[i].type=="radio")
		{
			if( objRadio[i].value == value )
			{
				objRadio[i].checked = true;
			}
		}
	}
}

function parentTag( obj , tag )
{
	var o = obj; 
	if( o.parentNode.nodeName != tag && isNaN( o.parentNode.nodeName) )
	{
		//alert( o.parentNode.nodeName );
		return parentTag( obj.parentNode , tag );
	}
	else
	{
		//alert( obj.parentNode.innerHTML );
		return obj.parentNode;
	}
}

function removeThisRow( obj )
{
	if( confirm( 'delete this row?' ) )
	{
		var i = parentTag( obj , 'TR' );
		//alert( i.parentNode.rows.length );
		if( i.parentNode.rows.length > 2 )
		i.parentNode.deleteRow( i.rowIndex );
	}
	
}

function insertUnderThisRow( obj )
{
	var i = parentTag( obj , 'TR' );
	var n = i.parentNode.appendChild( i.cloneNode( true ) );
	setSameValue( i , n );
}

function moveThisRowUp( obj )
{
	var i = parentTag( obj , 'TR' );
	if( i.rowIndex <= 1 ) return false;
	i.parentNode.rows[i.rowIndex-1].swapNode( i );
}

function moveThisRowDown( obj )
{
	var i = parentTag( obj , 'TR' );
	if( i.rowIndex+1 >= i.parentNode.rows.length ) return false;
	i.parentNode.rows[i.rowIndex+1].swapNode( i );
}

function setSameValue( from , to )
{
	var i = 0; // do not delete this!
	
	if( from.nodeType == 3 ) return false;
	if( from.nodeName == 'A' ) return false;
	if( from.nodeName == 'SPAN' ) return false;
	if( from.nodeName == '#text' ) return false;
	if( from.nodeName == 'SELECT' )
	{
		setSelectSameValue( from , to );
		return false;
	}
	if( from.nodeName == 'INPUT' )
	{
		if( from.getAttribute('type') == 'checkbox' )
			setCheckBoxSameValue( from , to );

		if( from.getAttribute('type') == 'radio' )
			setRadioSameValue( from , to );

		if( from.getAttribute('type') == 'text' )
			to.value = from.value;

		return false;
	}
	

	if( from.hasChildNodes() )
	{
		var names = navigator.appName;
	
		for( i = 0 ; i < from.childNodes.length ; i++ )
		{
			setSameValue( from.childNodes[i] , to.childNodes[i] );
		}
	}
}

function setSelectSameValue( from , to )
{
	to.options[from.selectedIndex].selected = true;
}

function setCheckBoxSameValue( from , to )
{
	if( from.checked ) to.checked = true;
}

function setRadioSameValue( from , to )
{
	if( from.checked ) to.checked = true;
}

function copyText(obj) 
{
	ie = (document.all)? true:false
	if (ie)
	{
		var rng = document.body.createTextRange();
		rng.moveToElementText($(obj));
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
		alert( '已经将内容复制到剪贴板，你可以使用Ctrl+v将内容转贴' );
	}
}

function setC( txt )
{
	clipboardData.setData( 'Text' , txt );
	alert( '已经将页面地址 ' + txt + ' 复制到剪贴板，你可以使用Ctrl+v粘贴到需要的地方' );
}

function lock_pic_size()
{
	
	obj = document.getElementsByTagName( 'IMG' );
	if( obj.length < 1 )
	{
		return false;
	} 
	
	for( i=0 ;i < obj.length; i++)
	{
      
		if( obj[i].width > 400 )
		{
			
			obj[i].height = (400 * obj[i].height)/ obj[i].width;
			obj[i].width = 400;
		}
	   	
	 } 
}

function removeThisLi( obj )
{
	if( confirm( '真的要删除这行？' ) )
	{
		var i = parentTag( obj , 'LI' );
		if( i.parentNode.childNodes.length > 1 )
			i.parentNode.removeChild(i);
		else
			alert( '最后一行不能被删除' );
	}

}

function addLine( mylist )
{
	var d = document.createElement("LI");
	d.innerHTML = $( mylist ).childNodes[$( mylist ).childNodes.length-1].innerHTML;
	$( mylist ).appendChild(d , null);

	Sortable.create(mylist,{dropOnEmpty:false,containment:[mylist]});
	wm_init();
}

function fixcheck(obj , name , ontext , offtext )
{
	sCheckedT	= '<input name="' + name + '" type="checkbox" checked value="1">' + ontext ;
	sCheckedF	= '<input type="checkbox" value="0"><input type="hidden" value="0" name="' + name + '">' + offtext;

	if(obj.alt)
	{
		obj.innerHTML = sCheckedF;
		obj.alt	= false;
	}else{
		obj.innerHTML = sCheckedT;
		obj.alt	= true;
	}

}

function addHintInfo()
{
	var infos = document.getElementsByTagName( '*' );
	for( var i=0 ; i < infos.length ; i++ )
	{
		if( infos[i].getAttribute('wm_hint') != null)
		{
			
			if( infos[i].nodeType == 3 )
			{
				// text node
				infos[i].onmouseover = function(){ showHintDiv( this );	}
				infos[i].onmouseout = function() { hideHintDiv( this ); }
				infos[i].autocomplete="off";
			}
			else
			{
				infos[i].onfocus = function(){ showHintDiv( this ); }
				infos[i].onblur = function(){ hideHintDiv( this ); 	}
				infos[i].autocomplete="off";
			}
			

		}
	}
}



function hideDiv( obj , names )
{
	if( obj.className == 'input' )
	{
		obj.style.height = 20;			
	}
	$( names ).style.display = 'none';
}

function showDiv( obj , names , notice )
{
	if( obj.className == 'input' )
	{
		if( obj.scrollHeight < 80 )
		{
			obj.style.height = 80;
		}
		else
		{
			obj.style.height = obj.scrollHeight+10;			
		}
	}
	
	var xy = getXY( obj );
	$( names ).style.display = 'block'; 
	$( names ).style.left = xy.l; 
	$( names ).style.top = (xy.t+xy.h)+3;
	if( xy.w < 30 )
		$( names ).style.width = 80;
	else 
		$( names ).style.width = xy.w;
	if( isNull(notice) )
		$( names ).innerHTML = ' ↑ ' + obj.getAttribute( 'wm_hint' );
	else
		$( names ).innerHTML = ' ↑ ' + notice;
}

function showHintDiv( obj , notice )
{
	showDiv( obj , 'div_hint' , notice );

}

function hideHintDiv(obj)
{
	hideDiv( obj , 'div_hint' );
}


function showNavDiv( obj , notice )
{
	showDiv( obj , 'div_navbox' , notice );

}

function hideNavDiv(obj)
{
	hideDiv( obj , 'div_navbox' );
}


function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
function getXY(s)
{
	var oObj = typeof(s) == 'object' ? s : $(s);
	var iTop = 0;
	var iLeft = 0;
	var iWidth = oObj.offsetWidth;
	var iHeight = oObj.offsetHeight;
	while(oObj != document.body){
		iLeft += oObj.offsetLeft;
		iTop += oObj.offsetTop;
		oObj = oObj.offsetParent;
	}
	return {l:iLeft, t:iTop, w:iWidth, h:iHeight};
}

// some codes from lightbox 
//	by Lokesh Dhakar - http://www.huddletogether.com
// ------------------------------------------------------
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

if (!window.Element)
  var Element = new Object();
//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setLeft: function(element,t) {
	   	element = $(element);
    	element.style.left = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function closeDivWindow()
{
	$( 'wm_div_widow' ).style.display = 'none';
	$( 'wm_div_msg_box' ).style.display = 'none';
	showSelectBoxes();
	void(0);
}

function closeDivInfoBox()
{
	$( 'wm_div_msg_box' ).style.display = 'none';
	showSelectBoxes();
	void(0);
}

function showDivInfoBox( info )
{
	hideSelectBoxes();
	
	if( isNull($( 'wm_div_msg_box' ))  )
	{
		var objBox = document.createElement("div");
		//objBox.setAttribute('id','wm_div_msg_box');
		//objBox.style.display = 'none';
		//objBox.onclick = function() { objOverlay.style.display = 'none';objBox.style.display = 'none'; showSelectBoxes();return false; }
		//objBox.onclick = function() { objOverlay.style.display = 'none'; return false; }
		document.getElementsByTagName("body").item(0).appendChild(objBox);
		
	
	}

	table_html = '<div id="wm_div_msg_box"  style="position: absolute;padding:5px;top:80;left:200;width:400;border:1px solid #e8e8e8;background:#FFF;z-index:100;"><table width="100%"><tr><td width="165px"><img src="res/img/admin/alert.gif"></td><td align="left"><h3>系统提示2</h3>'
	+ info +  '</td></tr><tr><td colspan=2><p align="right" ><a href="javascript:closeDivInfoBox()">close</a> &raquo; &nbsp;&nbsp;</p></td></table></div>';
	objBox.innerHTML = table_html;
	//Element.setInnerHTML( 'wm_div_msg_box' , table_html );
	//Element.setTop('wm_div_msg_box', 80);
	//alert( $('wm_div_msg_box').style. );
	//Element.setLeft('wm_div_msg_box', 200  );
	Element.show('wm_div_msg_box');
}

function showDivWindow( info )
{
	// 创建对象
	if( isNull($( 'wm_div_widow' ))  )
	{
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','wm_div_widow');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { objOverlay.style.display = 'none';objBox.style.display = 'none'; showSelectBoxes();return false; }
		document.getElementsByTagName("body").item(0).appendChild(objOverlay);

		var objBox = document.createElement("div");
		objBox.setAttribute('id','wm_div_msg_box');
		objBox.style.display = 'none';
		//objBox.onclick = function() { objOverlay.style.display = 'none';objBox.style.display = 'none'; showSelectBoxes();return false; }
		//objBox.onclick = function() { objOverlay.style.display = 'none'; return false; }
		document.getElementsByTagName("body").item(0).appendChild(objBox);


	}

	// 显示对象
	hideSelectBoxes();
	var arrayPageSize = getPageSize();
	Element.setHeight('wm_div_widow', arrayPageSize[1]);
	new Effect.Appear('wm_div_widow', { duration: 0.2, from: 0.0, to: 0.8 });

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15) + 40 ;

	table_html = '<table width="100%"><tr><td width="165px"><img src="res/img/admin/alert.gif"></td><td align="left"><h3>系统提示</h3>'
	+ info +  '</td></tr><tr><td colspan=2><p align="right" ><a href="javascript:closeDivWindow()">close</a> &raquo; &nbsp;&nbsp;</p></td></table>';
	Element.setInnerHTML( 'wm_div_msg_box' , table_html );
	Element.setTop('wm_div_msg_box', lightboxTop);
	//alert( $('wm_div_msg_box').style. );
	Element.setLeft('wm_div_msg_box', arrayPageSize[0]/2 - 200  );
	Element.show('wm_div_msg_box');



}

function is_all_fill( name )
{
	inputs = document.getElementsByName( name );
	if( !isNull( inputs ) )
	{
		for( var i = 0; i < inputs.length ; i++ )
		{
			if( isNull( inputs[i].value ) )
			{
				return false;
			}
		}

	}

	return true;
	
}

function data_field_submit_check()
{
	if( !is_all_fill( 'fields[dy_en_name][]' ) )
	{
		showDivWindow( '字段英文名不能为空!' );
		return false;
	}

	if( !is_all_fill( 'fields[dy_cn_name][]' ) )
	{
		showDivWindow( '字段中文名不能为空!' );
		return false;
	}
	
	if(check_data_field_exists('fields[dy_en_name][]','字段英文名')
		&&check_data_field_exists('fields[dy_cn_name][]','字段中文名'))
	{
		return true;
	}

	return false;
}

function check_data_field_exists( name , text )
{
	if( isNull( text ) ){ text = name; }
	var earr = Array();
	var myii = 0;
	inputs = document.getElementsByName( name );
	if( !isNull( inputs ) )
	{
		for( var i = 0; i < inputs.length ; i++ )
		{
			// 形成列表
			earr[myii] = inputs[i].value;
			myii++;
		}

		for( var i = 0; i < inputs.length ; i++ )
		{
			if( in_arrays( inputs[i].value , earr ) > 1  )
			{
				showDivWindow( '<font color=red>' + text + '在本页面上有重复，值为' + inputs[i].value + '</font>'  );
				$(name).value = '';
				return false;
			}
		}

		return true;
	}
	else
	{
		return false;
	}

}

function in_arrays( value , arr )
{
	var mycount = 0;
	for( var ii = 0 ; ii < arr.length ; ii++ )
	{
		//alert( 'fff' );
		if( arr[ii] == value )
		{
			mycount++;
		}
	}
	return mycount;

}

function handleIEhasLayout(){
	//trigger re-rendering
	document.body.style.zoom = 1.1;
	//restore it
	document.body.style.zoom = '';
}

function xmagik_digg( xid , mods , type , page , limit ,cache )
{
	var url = '?a=modajax';
	var pars = 'x=' + encodeURIComponent(xid) + '&m=' + encodeURIComponent( mods ) + '&t=' + encodeURIComponent( type ) + '&page=' + encodeURIComponent( page ) + '&l=' + limit +'&c=' + cache;
	var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: function(res){ xmagik_digg_back( res , xid ) }}  );
	
	$(xid).innerHTML = '<div style="position:absolute;padding-left:300px;padding-top:20px;"><center><img src="res/img/loading2.gif"><br/><font color=#d8d8d8>Loading...</font></center></div>' + $(xid).innerHTML;
}

function xmagik_digg_back( res , xid )
{
	$(xid).innerHTML = res.responseText;
}

function diggajax( strs )
{
	// ?a=modajax&page=2&m=1-2&t=new&l=2&x=xdigg9682720071013161121'
	strs = strs.replace('?' , '');
	strs.split('&').each(function(item)
	{
		var ii = item.split('=');
		eval( ii[0] + '="' + ii[1] + '";' );
	})
	xmagik_digg( x , m , t ,page , l , c );
}

function xdiggup( xid , mid , cid )
{
	var url = '?a=diggajax';
	var pars = 'x=' + encodeURIComponent(xid) + '&m=' + encodeURIComponent( mid ) + '&c=' + encodeURIComponent( cid ) ;
	var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: function(res){ xdiggdone( res , xid ) }}  );
	

}

function xdiggdone( res , xid )
{
	alert(res.responseText);
	if( res.responseText != '' )
		eval( res.responseText );
	else
	{
		xint = parseInt($(xid).innerHTML);
		$(xid).innerHTML = xint+1;
	}
}


function run_script( str )
{
	scripts = [];
	var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
	while ((script = regexp.exec(str))) scripts.push(script[1]);
	scripts = scripts.join('\n');
	if (scripts) (window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);

}

function magik_admin_send( fid )
{
	var url = $(fid).action;
	//alert( $(fid).action );
	var ff = $(fid);
	
	var pars = Form.serialize( $(fid) ) ;
	var myAjax = new Ajax.Request( url, {method: $(fid).method, parameters: pars, onComplete: function(res){ magik_admin_finish( res , fid ) }}  );

}

function magik_admin_finish( res , fid )
{
	if( $('admin_notice') )
	{
		$('admin_notice').innerHTML = '<img src="/magik/img/comment.gif">&nbsp;' + res.responseText + '</center>';
		run_script( res.responseText  );
	}
	else
	{
		new Insertion.Before( fid , '<div id="admin_notice"><img src="/magik/img/comment.gif">&nbsp;' + res.responseText + '</div>' );
	}

	$('admin_notice').scrollTo();
	
	
}

function magik_admin_send2( fid , toid )
{
	var url = $(fid).action;
	//alert( $(fid).action );
	var ff = $(fid);
	
	var pars = Form.serialize( $(fid) ) ;
	var myAjax = new Ajax.Request( url, {method: $(fid).method, parameters: pars, onComplete: function(res){ magik_admin_finish2( res , toid ) }}  );

}

function magik_admin_finish2( res , toid )
{
	$(toid).innerHTML = res.responseText;
	run_script( res.responseText  );

}


function ajax_set_contents( url , mid )
{
	var myAjax = new Ajax.Updater( mid, url, {method: 'post'});
}

function switchdiv( id ,read )
{
	if( $(id).style.display != 'none' )
	{
		$(id).style.display = 'none';
	}
	else
	{
		$(id).style.display = 'block';
	}
	if(read == '1')
	{
		ajax_send_url(id);
	}
}


function ajax_send_url(id)
{

	var url = '';
	
	var pars = 'a=pm_make_read&id=' + id.split("-")[0];
       
	var myAjax = new Ajax.Request(
                    url,
                    {method: 'get', parameters: pars, onComplete:function(){showReaded(id)}}
                    );

}

function showReaded(id)
    {
        //put returned XML in the textarea
        $(id.split("-")[0]+'-readed').innerText = "已读";
    }

function ajax_del_pm( id , box )
	{
		var url='/';

		var pars='a=pm_del&id=' + id.split("-")[0] + '&box=' + box;

		var myAjax = new Ajax.Request(
                    url,
                    {method: 'post', parameters: pars, onComplete:function(){del_pm_list(id)}}
                    );
	}

function del_pm_list(id)
{
	$(id).outerHTML="<font   color=#FF0000>已删除</font>";

}



function tab_selected( ul , li )
{
	var p = $(ul);
	var lis = p.getElementsByTagName('li');
	for( var i=0 ; i < lis.length ; i++ )
	{
		alert( li + ' ~ ' + lis[i].id );
		if( lis[i].id == li )
		{
			lis[i].className="current";
		}
		else
		{
			lis[i].className="nt";
		}
	}
		
}

function format_images()
{
	var size = 400;
	var imgs = document.getElementsByTagName('img');
	if( imgs )
	{
		for( var i=0 ; i < imgs.length ; i++ )
		{
				if( imgs[i].width > size )
				{
					imgs[i].height = ( (size-20) * imgs[i].height )/ imgs[i].width;
					imgs[i].width = size-20;
					imgs[i].style.cursor = 'pointer';
					imgs[i].style.border = '1px solid #d8d8d8';
					imgs[i].style.margin = '2px';
					imgs[i].style.padding = '2px';
					imgs[i].title = "图片已经被缩小，点击在新窗口打开原图";
					imgs[i].onclick=function(){ window.open(this.src) };
				}
					
		}
	}
}
function get_modules_seo()
{
	var m_ename = $('modules').value;

	var url = '';
	
	var pars = 'a=get_modules_seo&m_ename=' + m_ename;
       
	var myAjax = new Ajax.Request(
                    url,
                    {method: 'get', parameters: pars, onComplete:function(res)
					{
						show_seo(res);
					}
						});

}
function show_seo (res)
{
	var seos = res.responseText.split('|-|-|');
	set('WEB_SITE_SEO_TOP_WORD',seos[0]);
	set('WEB_SITE_SEO_META_KEYWORD',seos[1]);
	set('WEB_SITE_SEO_META_DESCRIP',seos[2]);
	set('WEB_SITE_SEO_HEADER_CODE',seos[3]);
}
function selectIt(action)
{
	var e=document.getElementsByTagName("input");

	for(var i=0 ;i<e.length;i++)
	{
	
		e[i].checked=(action=="selectAll")?1:(!e[i].checked);
		if (e[i].type.toLowerCase() == "checkbox")
		{
			mail_check_ids(e[i].value);
		}
	}

}
function ajax_email_list(link)
{
	var url='/';
	var pars=link;

	var myAjax = new Ajax.Request(
                    url,
                    {method: 'post', parameters: pars, onComplete:function(res){

					$('mail_list').innerHTML = res.responseText;
					 mails_check_selected()
						}}
                    );
		
}

function mails_send()
{
	$('mail_all').style.display = "none";
	$('send_info').innerHTML = "发送中......";
	$('mail_send').submit();
}
function search_emails()
{
	var link = 'a=people_email_search&page=1&search_text=' + $('search_text').value;
	ajax_email_list(link);
}
function mail_check_ids(id)
{

	var all_ids = $('all_ids').value.split('-');
	
	if ($('uid-'+id).checked)
	{
		all_ids=all_ids.without(id);
		all_ids.push(id);
	}
	else
	{
		all_ids=all_ids.without(id);
	}
		all_ids=all_ids.compact();
		var ids = all_ids.join('-');
		$('all_ids').value = ids;
}
function mails_check_selected()
{
	var e=document.getElementsByTagName("input");

	for(var i=0 ;i<e.length;i++)
	{
		if (e[i].type.toLowerCase() == "checkbox")
		{			
			e[i].checked = check_mail_checked(e[i].value);		
		}
		
	}
	
}
function check_mail_checked(id)
{
	var all_ids = $('all_ids').value.split('-');

	var check;
	all_ids.each(function(c){
		
		if (c == id)
		{
			check = true;
		}
	})
	check=(check==true)?true:false;

	return check;
}
function check_poll_radio(fname,all)
{
	var num = 0;
	var e=document.getElementsByTagName("input");

	for(var i=0 ;i<e.length;i++)
	{
		if (e[i].type.toLowerCase() == "radio")
		{			

			if(e[i].checked == true)
			{
				num++;
			}
		}
		
	}
	if(num == all )
	{
		$(fname).submit();
		return;
	}
	alert('请选择必要的选项');
}
function quick_menu()
{
	if( !$('qmenu')) return false; 
	
	$('qmenu').onmouseover = function()
	{
		//Position.absolutize($('qmenu'));
		xy = Position.page( $('qmenu') );
		//alert( xy[0] );
		
		$('qmenu_pop').setStyle({left:xy[0]});
		$('qmenu_pop').setStyle({top:xy[1]+15});
		//$('qmenu_pop').style.left = 0; 
		//$('qmenu_pop').style.top = 0;
		$('qmenu_pop').style.display = 'block';
	}

	$('qmenu').onmouseout = function()
	{
		$('qmenu_pop').style.display = 'none';
	}
}

function reload_miniblog()
{
	var url = '/?a=minifeeds';
	if($('friend_only_check_box').checked == true )
	{
		url = url + '&friendonly=1'; 
	}
	location = url;
}