/**
* @file common.js
* @copyright (c) 2005 - 2007 eifr.com
* @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
* eifr is free software
*/

function MM_jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openSelectWin(tourl)
{ 
  window.open(tourl,'select','status=no,scrollbars=yes,top=100,left=200,width=600,height=480');
}


function showHidden(strid)
{
	if(document.getElementById(strid))
		document.getElementById(strid).style.display="";
}

function showDisplayHidden(chk,area)
{
	var chkO = document.getElementById(chk);
	if(chkO.checked)
	{
		document.getElementById(area).style.display="";
		chkO.checked = true;
	}
	else
	{
		document.getElementById(area).style.display="none";
		chkO.checked = false;
	}
}

function showRemark_radio(prefix,suffix)
{
	var tagO = document.getElementsByTagName('div');
	if(suffix!='')
	{
		for (var ti=0;ti<tagO.length;ti++)
	  {    
	    if(tagO[ti].id.substr(0,prefix.length)==prefix)
	    {
		    if(tagO[ti].id==prefix+'_'+suffix)
		    {	
		    	tagO[ti].style.display="";
		    }
		    else
		    {
		    	tagO[ti].style.display="none";
		    } 
		  }
	  }
	}
	
}

function showSubClassTr(sid,img_path)
{
	var tagO = document.getElementsByTagName('tr');

	if (document.getElementById("img" + sid ).src.indexOf("arrow_display.gif")!=-1)
	{
		document.getElementById("img" + sid ).src = img_path+"arrow_hidden.gif";
		
		for (var ti=0;ti<tagO.length;ti++)
	  {    
	    if(tagO[ti].id)
	    {	
	    	if(tagO[ti].id.length>sid.length && tagO[ti].id.substr(0,sid.length)==sid)
		    {	
		    	tagO[ti].style.display="";
		    }
	    } 
	  }
	  
	}
	else
	{
		document.getElementById("img" + sid ).src = img_path+"arrow_display.gif";
		
		for (var ti=0;ti<tagO.length;ti++)
	  {
	    if(tagO[ti].id)
	    {
	    	if(tagO[ti].id.length>sid.length && tagO[ti].id.substr(0,sid.length)==sid)
		    {
		    	tagO[ti].style.display="none";
		    }
	    } 
	  }
	  
	}
}

function submitButton(tourl,strmsg,is_confirm)
{
	if(is_confirm)
	{		
		if(confirm("你确认要\""+strmsg+"\"吗？"))
		{    			
			location.href=tourl;
		}
	}
	else
	{
		location.href=tourl;
	}
}

function submitOpenerValue(form_input,tmpValue,tmpTxt)
{	
	if(confirm("你确认选择\""+tmpTxt+"\"吗？"))
	{    			
		if(window.opener.document.getElementById(form_input))
		{
			window.opener.document.getElementById(form_input).value=tmpValue;
			if(window.opener.document.getElementById(form_input+'_show')) 
			{
				window.opener.document.getElementById(form_input+'_show').value = tmpTxt;
			}
			window.close();
		}
	}	
}

function submitsSelect(actTyle,tourl)
{
	var strtemp = "";	
	var strmsg = "";
	var isconfirm = false;
	var inputO =  document.getElementsByTagName("input");
  if(inputO.length>0)
	{			
  	
  	for(i=0; i<inputO.length; i++)
  	{
  		if(inputO[i].name.toLowerCase()=="selectid")
  		{
	  		if(inputO[i].getAttribute("type") == "checkbox")
	  		{
		  		if(inputO[i].checked == true)
		  		{	    			
						strtemp += ","+inputO[i].value;															
		  		}
		  	}
		  	else if(inputO[i].getAttribute("type") == "radio")
		  	{
		  		if(inputO[i].checked == true)
		  		{	    			
						strtemp += ","+inputO[i].value;		
						break;													
		  		}
		  		
		  	}
		  	else if(inputO[i].getAttribute("type") == "hidden")
		  	{
		  		strtemp += ","+inputO[i].value;
		  		break;
		  	}
		  }
  	}
	  
  	if(strtemp!='')
	  {
	  	strtemp = strtemp.substr(1,strtemp.length); 	
	  }
  }

  if(actTyle=="add" )
  {
  	strtemp = ""; 	
  }
    
  switch(actTyle)
	{
		case "add":
			strmsg = "增加";
			break;
		case "copy":
			strmsg = "复制";
			isconfirm = true;
			break;
		case "edit":
			strmsg = "编辑";
			break;
		case "delete":
			strmsg = "删除";
			isconfirm = true;
			break;
		case "delete_forever":
			strmsg = "永久删除";
			isconfirm = true;
			break;
		case "save":
			strmsg = "保存";
			break;
			
	}

	if(actTyle=="edit" || actTyle=="copy" || actTyle=="preview")
	{
		var strtemp_arr = strtemp.split(",");
		
		if(strtemp=="" || strtemp_arr.length>1)
		{
			alert("只能操作一个");
  		return;
		}
	}
	
	if((actTyle=="delete" || actTyle=="delete_forever") && strtemp=="")
  {
  	alert("请选择");
  	return;
  }

	if(isconfirm)
	{		
		if(confirm("你确认要\""+strmsg+"\"吗？"))
		{    			
			document.getElementById("selectValue").value = strtemp;	    			    			    			
			document.editForm.action = tourl;
			document.editForm.submit();
		}
	}
	else
	{
		document.getElementById("selectValue").value = strtemp;	    			    			    			
		document.editForm.action = tourl;
		document.editForm.submit();
	}
	
}

function checkSearch()
{
	if( document.getElementById("search_keyword").value.length<1)
	{
		alert("\请输入搜索关键字")
		return false;
	}
	return true;
	
}


function WinOpen(Url,Width,Height)
{
	window.open(Url,'_blank','width='+Width+',height='+Height+',scrollbars=yes');
}

var curFontSize = 12;
function doStrZoom(areaid,csize)
{
	if(csize==1) curFontSize = curFontSize+2;
	if(csize==-1) curFontSize = curFontSize-2;
	if(document.getElementById(areaid))
		document.getElementById(areaid).style.fontSize=curFontSize+"px";
}

/*
@param media_attributes(style=1:radio,2:video)
*/
function mediaPlay(file_url,media_attributes)
{
	if(file_url && media_attributes)
	{
		var tmpRealRegex = new RegExp( '.(RM|RA|RAM|RMVB|AVI)$', 'i' );
		var tmpMediaRegex = new RegExp( '.(ASF|WMV|WMA|MPG|ASX|MPEG)$', 'i' );
		var scontrols = '';
		var strAttributes = '';
		var strarr = media_attributes.split(',');
		var media_style = 2;
		var comwidth = 438;
		var comheigth = 360;
		var comautostart = 1;
		var comloop = 1;
		var commenu = 1;
		var aheigth = 68;
		var vheigth = 360;
		
		for(var i=0;i<strarr.length;i++)
		{
			var tmparr = strarr[i].split('=');
			if(tmparr[0]=='style')
			{
				media_style=tmparr[1];
				break; 
			}
		}
	
		if(media_style==1) comheigth = aheigth;
		
		for(var i=0;i<strarr.length;i++)
		{
			var tmparr = strarr[i].split('=');
			switch(tmparr[0])
			{
				case 'width':
					if(tmparr[1]>0) comwidth=tmparr[1]; 
					strAttributes += ' width='+comwidth;
					break;
				case 'height':
					if(tmparr[1]>0) comheigth=tmparr[1]; 
					strAttributes += ' height='+comheigth;
					break;
				case 'play':
					if(tmparr[1]!='') comautostart=tmparr[1];
					strAttributes += ' autostart='+comautostart;
					break;
				case 'loop':
					if(tmparr[1]!='') comloop=tmparr[1];
					strAttributes += ' loop='+comloop;
					break;
				case 'menu':
					break;
			}
			
		}
		
		if(tmpMediaRegex.test(file_url))
		{
			if(media_style==1) scontrols = ' showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" clicktoplay="0" defaultframe="datawindow" invokeurls="0"';
			else scontrols = ' showcontrols=1 showpositioncontrols=1 showstatusbar=0 autosize=0';
			scontrols+=strAttributes;
			document.write("<center><embed src='"+file_url+"' type='video/x-ms-asf-plugin' pluginspage='http://www.microsoft.com/netshow/download/player.htm' "+scontrols+"></embed></center>");
		}
		else if (tmpRealRegex.test(file_url))
		{
			if(media_style==1) scontrols = 'ControlPanel,StatusBar';
			else scontrols = 'ImageWindow,ControlPanel,StatusBar';
			document.write("<center><embed SRC='"+file_url+"' type='audio/x-pn-realaudio-plugin' CONSOLE='Clip1' CONTROLS='"+scontrols+"' "+strAttributes+"></center>");
		}
		file_url = null;
		media_attributes = null;
		tmpRealRegex = null;
		tmpMediaRegex = null;
	}
}

