
function replaceImage(obj)
{
   var imgList=obj.getElementsByTagName("IMG");
   if(imgList)
   {
      
      for(var i=0;i<imgList.length;i++)
      {  
         
         if(imgList[i].parentNode.tagName=="A")
         {
            continue;//本身图片有连接了。就跳过
         }
         var src = imgList[i].src;
         //alert(src);
         var image=new Image(); 
         image.src=src;
         
         
       var xw=600; 
        var xl=600; 
        var width = image.width; 
        var height = image.height; 
        
        var bili = width/height;         
        if(width==0)
           return;     
        var A=xw/width; 
        var B=xl/height; 
             
        if(!(A>1&&B>1)) 
        { 
            if(A<B) 
            { 
                image.width=xw; 
                image.height=xw/bili; 
            } 
            if(A>B) 
            { 
                image.width=xl*bili; 
                image.height=xl; 
            } 
        } 

         var a = document.createElement("div");

         
         a.innerHTML ="<a href='"+src+"' target='_blank'><img border='0' src='"+src+"' width='"+image.width+"' height='"+image.height+"' alt='点击察看原图' />";
         imgList[i].parentNode.appendChild(a);
         imgList[i].parentNode.removeChild(imgList[i]);

      }
   }
}
function IsLoginAjax(rtnAction)
{ 
   var opt = {
              method: 'post',             
              onSuccess: function(t) {
                  if(t.responseText == 'true')
                  {                                        
                    if(rtnAction)
                    {
                        rtnAction(true);
                    }
                    else
                    {
                        rtnAction(false);
                    }
                  }                  
                  else
                  {
                    if(rtnAction)
                     {
                        rtnAction(false);
                    }
                    else
                    {
                        rtnAction(false);
                    }
                  }                                              
              },
              // Handle 404
              on404: function(t) {
                  alert('Error 404: location "' + t.statusText + '" was not found.');
                  return false;
              },
              // Handle other errors
              onFailure: function(t) {
                  alert('Error ' + t.status + ' -- ' + t.statusText);
                  return false;
              }
         }
         new Ajax.Request('/Common/CommonActionAjax.aspx?Action=islogin',opt);//
}
function MainNvaiClick(obj)
{
	document.getElementById(obj).parentElement.className ="current";
	//alert(obj.getAttribute("id"));
	//obj.parentElement.getAttribute("class")  = "current";
}

function ManagePassClick()
{
	return confirm("确定发布信息？");	
}
function ManageDelClick()
{
	return confirm('确定删除信息？');
}
function ManageClearClick()
{
	return confirm('此操作将不可恢复，确定删除信息？');
}

function bodyLoad()
{
	if(document.all.item('ctlContent'))
	{
		frames.message.document.body.innerHTML = document.all.item('ctlContent').value;
	}
	if(document.all.item('ctlArrange') && document.all.item('ctlItems'))
	{
		LoadItems();
	}
}

function saveClick1()
{				
	if(document.all.item('ctlContent') && frames.message){document.all.item('ctlContent').value = frames.message.document.body.innerHTML;}			
	if(document.all.item('ctlDetails')&& frames.message){document.all.item('ctlDetails').value = frames.message.document.body.innerHTML;}
	if(document.all.item('ctlComment')&& frames.message){document.all.item('ctlComment').value = frames.message.document.body.innerHTML;}	
	if(document.all.item('ctlDescription')&& frames.message){document.all.item('ctlDescription').value = frames.message.document.body.innerHTML;}	
	if(document.all.item('ctlSummary')&& frames.message){document.all.item('ctlSummary').value = frames.message.document.body.innerHTML;}	
}
function showSelectProduct()
{
	//var val = window.open("/Common/ProductSelectMain.aspx", "", "dialogWidth:40em; dialogHeight:20em; status:0;help:0");	
	window.open("/Common/ProductSelectMain.aspx","Select","height=400,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
	//if(val != null && document.all.item('ctlProductId') ){document.all.item('ctlProductId').value = val;}			
}
function cancelProduct()
{
	if(document.all.item('ctlProductId') )
	{
		document.all.item('ctlProductId').value = "";
	}		
	if(document.all.item('ctlProductName') )
	{
		document.all.item('ctlProductName').value = "";
	}
	if(document.all.item('ctlFactory') )
	{
		document.all.item('ctlFactory').value = "";
	}
}
function selectProduct(id,text,company)
{
	if(id != null && window.opener.document.all.item('ctlProductId') )
	{
		window.opener.document.all.item('ctlProductId').value = id;
	}		
	if(text != null && window.opener.document.all.item('ctlProductName') )
	{
		window.opener.document.all.item('ctlProductName').value = text;
	}
	if(company != null && window.opener.document.all.item('ctlFactory') )
	{
		window.opener.document.all.item('ctlFactory').value = company;
	}
	window.close();
}
function showSelectCompany(companyType)
{	
	window.open("/Management/CompanyView.aspx?Type="+companyType,"Select","height=400,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}

function DefShowSelectCompany()
{
	window.open("/Management/CompanyView.aspx","Select","height=400,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
function cancelCompanyId(ctl1,ctl2)
{
	if(document.all.item(ctl1))
	{
		document.all.item(ctl1).value = "";
	}
	if(document.all.item(ctl2))
	{
		document.all.item(ctl2).value = "";
	}
}
function selectCompany(id,text)
{
	if(window.opener.document.all.item('ctlCompanyId') )
	{
		window.opener.document.all.item('ctlCompanyId').value = id;
	}		
	if(window.opener.document.all.item('ctlCompanyName') )
	{
		window.opener.document.all.item('ctlCompanyName').value = text;
	}		
	window.close();
}

function setPanelStatus(panelId)
{
	if(panelId.style.display == 'none')
	{
		panelId.style.display = 'block';
	}
	else 
	{
		panelId.style.display = 'none'; 
	}
}

function showUploadWindow(folder)
{
	window.open("/Common/UploadFile.aspx?Folder=" + folder ,"Select","height=140,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}

function ShowUploadPicWindow(folder,ctl)
{
	window.open("/Common/UploadFile.aspx?Folder=" + folder +"&ReturnCtl="+ctl,"Select","height=140,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
		
function AddItem(content,optionPanel)
{			
	var text = content.value;
	if(text)
	{
		var item = document.createElement("OPTION");
		item.text = text;
		item.value = text;
		optionPanel.add(item);
		//document.Form1.ctlItems.add(item);
	}
}
function ClearItem(optionPanel)		
{		
	var slc = "";
	slc = optionPanel.selectedIndex;
	if(optionPanel.value != "")
	{				
		optionPanel.options.remove(slc);
	}
}
function SaveItems(textCtl,optionPanel)
{		
	if(optionPanel.length > 0)
	{
		var val = "";	
		var length = optionPanel.length;
		for(i=0;i<length;i++)
		{
			val = val + optionPanel.options[i].text + "|";
		}
		textCtl.value = val;
	}
}

function LoadItems()
{
	var txtVal = document.all.item('ctlArrange').value;
	if(txtVal != null)
	{			
		txtVal = txtVal.replace(/(^\s*)|(\s*$)/g,"");
		var val = txtVal.split('|');
		for(i=0;i<val.length;i++)
		{			
			var item = document.createElement("OPTION");
			item.text = val[i];
			item.value = val[i];
			document.all.item('ctlItems').add(item);
		}
	}
}

function SelectElement(url,title,id,type)
{
	window.opener.document.getElementById('ctlUrl').value = url;
	window.opener.document.getElementById('ctlElementId').value = id;
	window.opener.document.getElementById('ctlElementType').value = type;
	window.opener.document.getElementById('ctlTitle').value = title;
	window.close();
}