
//Ajax判断用户是否登陆

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 TradeLink(ctlId,val)
{
     var opt = {
              method: 'post',             
              onSuccess: function(t) {
               if(document.getElementById(ctlId)) 
                  {
                  document.getElementById(ctlId).innerHTML=t.responseText;   
                  }                                              
              },
              // 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=tradelink&tradeid='+val,opt);//
}

function LoadHits(spanid,type,id)
{
  if($(spanid)!=null)
  {
        var myAjax=new Ajax.Request(
        '/ashx/stat.ashx',
       {
         method:'get',
         parameters: 'type='+type+'&id='+id,
         onComplete: function setBrandJson(data)
          {
             $(spanid).innerHTML=data.responseText;
          }
       }); 
  }
}

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('此操作将不可恢复。\n确定彻底删除此信息？');
}

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 showSelectExpo()
{	
	window.open("/Exposition/ExpositionView.aspx","Select","height=400,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
function showAppraise(id)
{
   	window.open("/common/appraise.aspx?id="+id,"Select","height=400,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");

}
function showSelectExpoAdmin()
{	
	window.open("/Management/ExpositionView.aspx","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('ctlToolTip') )
	{
		window.opener.document.all.item('ctlToolTip').value = text;
	}	
	
	if(window.opener.document.all.item('ctlCompanyId') )
	{
		window.opener.document.all.item('ctlCompanyId').value = id;
	}		
	if(window.opener.document.all.item('ctlUrl') )
	{
		window.opener.document.all.item('ctlUrl').value = '/Common/CompanyPage.aspx?Type=index&CompanyID='+id+'&Id='+id;
	}
	if(window.opener.document.all.item('ctlCompanyName') )
	{
		window.opener.document.all.item('ctlCompanyName').value = text;
	}		
	window.close();
}

function selectExpo(id,text)
{
	if(window.opener.document.all.item('ctlExpoId') )
	{
		window.opener.document.all.item('ctlExpoId').value = id;
	}		
	if(window.opener.document.all.item('ctlExpoName') )
	{
		window.opener.document.all.item('ctlExpoName').value = text;
	}		
	window.close();
}

function setPanelStatus(panelId,obj)
{
    panelId=document.getElementById(panelId);
	if(panelId.style.display == 'none')
	{
		panelId.style.display = 'block';
	
	    var parentTar=panelId.parentNode;
	    if(parentTar)
	    {
	        parentTar.style.width="600px";
	    }
		obj.src="/Images/menu_title_up.gif";
		
	}
	else 
	{
		panelId.style.display = 'none';
		obj.src="/Images/menu_title_down.gif";
		var parentTar=panelId.parentNode;
	    if(parentTar)
	    {
	        parentTar.style.width="140px";
	    }
	}
}

function getBrandJson(companyid,drpid,btn)
{
if(btn.value=='所有品牌')
 companyid='';
var url = '/ashx/BrandIt.ashx';
var pars = 'companyid=' + companyid;
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: function setBrandJson(data)
{
 var oop=$(drpid).options;
 oop.length=0;
 if(btn.value=='所有品牌')
 {
    btn.value='相关品牌';
    oop.add(new Option('所有品牌列表','0'));
 }
 else
 {
    btn.value='所有品牌';
    oop.add(new Option('相关品牌列表','0'));
 }
 var returnobj = eval('(' + data.responseText + ')').BrandList;
  for (i = 0; i <returnobj.length; i++) {
     oop.add(new Option(returnobj[i].name,returnobj[i].id));
     } 
}
});
}


function changePanelStatus(chk,panelId,imgid)
{
   if(!document.getElementById(panelId) || !document.getElementById(imgid) || !chk)
      return;
    panelId=document.getElementById(panelId);
	if(chk.checked)
	{
		panelId.style.display = 'block';
	
	    var parentTar=panelId.parentNode;
	    if(parentTar)
	    {
	        parentTar.style.width="600px";
	    }
		document.getElementById(imgid).src="/Images/menu_title_up.gif";
		
	}
	else 
	{
		panelId.style.display = 'none';
		document.getElementById(imgid).src="/Images/menu_title_down.gif";
		var parentTar=panelId.parentNode;
	    if(parentTar)
	    {
	        parentTar.style.width="140px";
	    }
	}
}

function setPItem(spanid)
{
 var items=document.getElementById(spanid).childNodes
 for(var i=0;i<items.length-1;i++)
 {
    if(items[i].type=="checkbox")
       items[i].checked=true;
 }
}

function setPanelStatusByKey(panelId)
{
	if(document.getElementById(panelId).style.display == 'none')
	{
		document.getElementById(panelId).style.display = 'block';
	}
	else 
	{
		document.getElementById(panelId).style.display = 'none'; 
		var parentTar=panelId.parentNode;
	  
	    if(parentTar)
	    {
	       
	        parentTar.style.width="140px";
	        
	    }
	}
}
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 showUploadWindow2(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 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");
}

// 用正则表达式将前后空格 add by zth
String.prototype.trim = function()
{       
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 添加场次安排 mod by zth
function AddItem(content,optionPanel)
{			
	var text = content.value;
	if(text.trim()=="")
	{
	   alert('请填写 场次安排');
	   return false;
	}
	else	
	{
		var item = document.createElement("OPTION");
		item.text = text;
		item.value = text;
		optionPanel.add(item);
		item.selected=true;
		//document.Form1.ctlItems.add(item);
	}
}
//mod by zth 
function ClearItem(optionPanel)		
{		
	var slc = "";
	slc = optionPanel.selectedIndex;
	if(slc>=0)
	{				
		optionPanel.options.remove(slc);
		if(slc>=1)
		{
		optionPanel.options[slc-1].selected=true; //定位上一个option
		}
	}
	else
	{
	   alert('操作失败: 未选定场次');
	   return false;
	}	
}
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.trim();//.replace(/(^\s*)|(\s*$)/g,"");
		var val = txtVal.split('|');
		for(i=0;i<val.length;i++)
		{			
			var item = document.createElement("OPTION");
			if(val[i].trim() != "")
			{
			item.text = val[i];
			item.value = val[i];
			document.all.item('ctlItems').add(item);
			}
		}
	}
}




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=700;       
       var width = image.width; 
       
       if(width==0)
           return;     
           
        var A=xw/width;      
             
        if(!(A>1)) 
        { 
          image.width=xw;          
        } 
        var a = document.createElement("div");         
         a.innerHTML ="<a href='"+src+"' target='_blank'><img border='0' src='"+src+"' width='"+image.width+"' alt='点击察看原图' />";
         imgList[i].parentNode.appendChild(a);
         imgList[i].parentNode.removeChild(imgList[i]);

      }
   }
}

function outPutPictrue(picurl,width,height)
{
   var image = new Image();
   var url = picurl;
   image.src=picurl; 
    if(image.width=='0')
    {
        url="默认图片";
    }
    document.write("<img src='"+url+"' width='"+width+"' height='"+width+"'>");
}

function getCookie(cookieName)
 { 
      var cookieString = document.cookie; 
      var start = cookieString.indexOf(cookieName + '=');
      if (start == -1)
          return null;  
      start += cookieName.length + 1;
      var end = cookieString.indexOf(';', start);
      if (end == -1) 
         return unescape(cookieString.substring(start));
      return unescape(cookieString.substring(start, end));
 }
function setCookie (name, value)
{   
    var expires = new Date();
    expires.setTime(expires.getTime() + 12 * 30 * 24 * 60 * 60 * 1000);
    document.cookie =name+'='+value+';path=/;expires=' + expires.toGMTString();
}

function GetArgsFromHref(sArgName) {var sHref=document.location.href;var args = sHref.split("?"); var retval = ""; if(args[0] == sHref) { return retval; } var str = args[1]; args = str.split("&"); for(var i = 0; i < args.length; i ++) { str = args[i]; var arg = str.split("="); if(arg.length <= 1) continue; if(arg[0] == sArgName) retval = arg[1]; } return retval; }



function commendChannel(id,type)
    {       
       
       var opt = {              
          method: 'post',  
          parameters:'' ,
          onSuccess: function(t) {              
          result=t.responseText;  
         if(result == 'ok')
        {
            alert('操作成功。');           
        }
        else
        {
            alert('操作失败。');
        }                
          },         
          on404: function(t) {
              alert('Error 404: location "' + t.statusText + '" was not found.');
          },        
          onFailure: function(t) {
              alert('Error ' + t.status + ' -- ' + t.statusText);
          }
         }       
      new Ajax.Request('/Common/CommonActionAjax.aspx?Action=channelcommend&id='+id+'&type='+type,opt);              
   } 
      