window.onload = function()
{
	 show_fck();					
}

function show_fck()
{
	var replaced = Array();
	var ii = 0;
	var in_it = 0;
	var obj = document.all;
	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/" ;
				oFCKeditor.ToolbarSet = "Basic";
				oFCKeditor.ReplaceTextarea() ;
			}

			
		}  
	} 
	
	
}

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 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粘贴到需要的地方' );
}