﻿// JScript 文件

function DrawMsgDIV(senderPos,offsetLeft,offsetTop)
{
    if(document.getElementById("loadingdiv")!=null)
    {
        document.getElementById("loadingdiv").style.display='block';
    }
    else
    {
       
       load = document.createElement("DIV");    
        load.id="loadingdiv";    
        load.style.position="absolute";   
        load.style.backgroundColor = "#ffffff";
        load.style.width = "auto";
        load.style.height = "auto";
        load.style.overflow = "auto";
        load.style.paddingLeft = "5px";
        load.style.paddingRight = "5px";
        load.style.borderColor = "#FA6606"; 
        load.style.borderWidth = "1px";
        load.style.borderStyle = "solid";
        
        load.style.display = "block";
        load.style.fontSize = "13px";
        load.style.lineHeight = "40px";
        load.style.zIndex = "1";            
        document.body.appendChild(load);
    }
    load.style.left = senderPos.tagLeft+offsetLeft+"px";
    load.style.top = senderPos.tagTop+offsetTop+"px";
    //load.onclick = "this.style.display='none'";
    load.innerHTML = "<img src=\"/Controls/ctrlImg/waitting.gif\" />";
}


function valid_join_group(groupid)
{  
    gpid = groupid;
    xmlHttpGroup = createXMLHttpRequest();
    if(xmlHttpGroup)
    {
       var url = "/group/ajax/valid_join_group.aspx?groupid="+groupid
                 +"&ts="+new Date().getTime(); 
       xmlHttpGroup.open("Get",url);
       xmlHttpGroup.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpGroup.onreadystatechange=valid;
       xmlHttpGroup.send(null); 
                                        
       var senderPos = getPos(document.getElementById('imgsay'));
       DrawMsgDIV(senderPos,0,25);
       
    }    
}

function valid()
{
    if(xmlHttpGroup.readyState==4)
    {
       if(xmlHttpGroup.status==200)
       {//alert(xmlHttpGroup.responseText);
          if(xmlHttpGroup.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再发言'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpGroup.responseText=="-1")
          {
             load.innerHTML = "<font color='#ff0000'>先加入此公社，再发言...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpGroup.responseText=="1")
          {                                      
             load.style.display='none';
             location.href = "/profile/newarticle_"+gpid+".html"; 
          }
             
       }
    }
}


function join_group(groupid)
{  
    
    xmlHttpJoinGroup = createXMLHttpRequest();
    if(xmlHttpJoinGroup)
    {
       var url = "/group/ajax/join_group.aspx?groupid="+groupid
                 +"&ts="+new Date().getTime(); 
       xmlHttpJoinGroup.open("Get",url);
       xmlHttpJoinGroup.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpJoinGroup.onreadystatechange=joingroup;
       xmlHttpJoinGroup.send(null); 
                                        
       var senderPos = getPos(document.getElementById('imgjoingroup'));
       DrawMsgDIV(senderPos,0,-40);
       
    }    
}


function joingroup()
{
    if(xmlHttpJoinGroup.readyState==4)
    {
       if(xmlHttpJoinGroup.status==200)
       {
          if(xmlHttpJoinGroup.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再加入公社'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpJoinGroup.responseText=="-1")
          {
             load.innerHTML = "<font color='#0F5230'>已经加入了这个公社...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
             document.getElementById('imgjoingroup').style.display='none';
          }
          else if(xmlHttpJoinGroup.responseText.indexOf("##")!=-1)
          {        
             var joiner = xmlHttpJoinGroup.responseText.split("##");
             //if(document.getElementById("divjoiner").innerHTML.split("<div class=\"cell\">").length-1<6)
                document.getElementById("divjoiner").innerHTML = "<div class=\"cell\"><a href=\"\/group\/people\/"+joiner[0]+".html\"><img src=\"\/img\/user\/"+joiner[0]+".gif\" onerror=\"this.src='\/img\/user\/none.gif'\" /></a><div class=\"username\"><a href=\"\/group\/people\/"+joiner[0]+".html\">"+joiner[1]+"</a></div></div>"+document.getElementById("divjoiner").innerHTML; 
                 //alert(document.getElementById("divjoiner").innerHTML);                
             load.style.display='none';
             document.getElementById('imgjoingroup').style.display='none'; 
             
          }
             
       }
    }
}


function valid_reply()
{  
    copyIframeReply();
    var replydetail = document.getElementById('txtReply').value.replace(/<[^>]+>|<\/[^>]+>/g,"").replace(/\s+/g,'').replace("&nbsp;","");
    //alert(replydetail.length);
    if(replydetail.length==0)
    {
        var alert = $('Article1_alarm')||$('alarm');
        alert.innerHTML = "回应要写点东西";
        return false;
    }
    else
        return true;
}

function copyIframeReply()
{
    document.getElementById('txtReply').value = frameobj.document.body.innerHTML;

}
/*
function validreply()
{
    if(xmlHttpGroup.readyState==4)
    {
       if(xmlHttpGroup.status==200)
       {//alert(xmlHttpGroup.responseText);
          if(xmlHttpGroup.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再回应'>还没有登录...</a>";
             allowReply = false;
          }
          else if(xmlHttpGroup.responseText=="-1")
          {
             load.innerHTML = "<a href='javascript:join_group_reply("+gpid+")'>先加入此公社</a>，再回应";
             allowReply = false;
          }
          else if(xmlHttpGroup.responseText=="1")
          {                                      
             load.style.display='none';
             allowReply = true;
             //location.href = "/profile/newarticle_"+gpid+".html"; 
          }            
       }
    }
}*/

function join_group_reply(groupid)
{  
    //alert('');
    xmlHttpJoinGroup = createXMLHttpRequest();
    if(xmlHttpJoinGroup)
    {
       var url = "/group/ajax/join_group.aspx?groupid="+groupid
                 +"&ts="+new Date().getTime(); 
       xmlHttpJoinGroup.open("Get",url);
       xmlHttpJoinGroup.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpJoinGroup.onreadystatechange=joingroupreply;
       xmlHttpJoinGroup.send(null); 
                                        
       var senderPos = getPos(document.getElementById('Article1_btnReply'));
       DrawMsgDIV(senderPos,45,0);
       
    }    
}


function joingroupreply()
{
    if(xmlHttpJoinGroup.readyState==4)
    {
       if(xmlHttpJoinGroup.status==200)
       {
          if(xmlHttpJoinGroup.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再加入公社'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpJoinGroup.responseText=="-1")
          {
             load.innerHTML = "<font color='#0F5230'>已经加入了这个公社...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpJoinGroup.responseText.indexOf("##")!=-1)
          {                                         
             load.innerHTML = "<font color='#0F5230'>成功加入公社，现在可以回应...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";              
          }
             
       }
    }
}


function add_friend(scoreid)
{  
    xmlHttpAddFriend = createXMLHttpRequest();
    if(xmlHttpAddFriend)
    {
       var url = "/group/ajax/addfriend.aspx?scoreid="+scoreid
                 +"&ts="+new Date().getTime(); 
       xmlHttpAddFriend.open("Get",url);
       xmlHttpAddFriend.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpAddFriend.onreadystatechange=readyfriend;
       xmlHttpAddFriend.send(null); 
                                        
       var senderPos = getPos(document.getElementById('addfriend'));
       DrawMsgDIV(senderPos,0,20);
       
    }  
}

function readyfriend()
{
    if(xmlHttpAddFriend.readyState==4)
    {
       if(xmlHttpAddFriend.status==200)
       {
          if(xmlHttpAddFriend.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再加购友'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpAddFriend.responseText=="0")
          {
             load.innerHTML = "<font color='#0F5230'>已添加为购友并等待对方确认...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpAddFriend.responseText=="-1")
          {
             load.innerHTML = "<font color='#ff0000'>不能添加自己为好友...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpAddFriend.responseText=="1")
          {
             load.innerHTML = "<font color='#0F5230'>您以前已经添加为购友，并等待对方确认...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpAddFriend.responseText=="2")
          {
             load.innerHTML = "<font color='#0F5230'>对方已经是您的购友...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
             
       }
    }
}


function add_shop(shopid)
{  
    xmlHttpAddShop = createXMLHttpRequest();
    if(xmlHttpAddShop)
    {
       var url = "/group/ajax/addshop.aspx?shopid="+shopid
                 +"&ts="+new Date().getTime(); 
       xmlHttpAddShop.open("Get",url);
       xmlHttpAddShop.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpAddShop.onreadystatechange=readyshop;
       xmlHttpAddShop.send(null); 
                                        
       var senderPos = getPos(document.getElementById('shopid'));
       DrawMsgDIV(senderPos,0,20);      
    }  
}


function readyshop()
{
    if(xmlHttpAddShop.readyState==4)
    {
       if(xmlHttpAddShop.status==200)
       {
          if(xmlHttpAddShop.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再加购友'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpAddShop.responseText=="-90")
          {
             load.innerHTML = "<font color='#ff0000'>这个商店已经是您喜欢的...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpAddShop.responseText=="1")
          {
             document.getElementById('shopscore').innerHTML = parseInt(document.getElementById('shopscore').innerHTML,10) + 1;
             load.innerHTML = "<font color='#0F5230'>您已成功添加了喜欢的商店...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
             
       }
    }
}


function add_shop_product(shopid)
{  
    xmlHttpShopProduct = createXMLHttpRequest();
    if(xmlHttpShopProduct)
    {
       var url = "/group/ajax/addshop.aspx?shopid="+shopid
                 +"&ts="+new Date().getTime(); 
       xmlHttpShopProduct.open("Get",url);
       xmlHttpShopProduct.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpShopProduct.onreadystatechange=readyshopproduct;
       xmlHttpShopProduct.send(null); 
                                        
       var senderPos = getPos(document.getElementById('likeshop'));
       DrawMsgDIV(senderPos,0,20);      
    }  
}

function readyshopproduct()
{
    if(xmlHttpShopProduct.readyState==4)
    {
       if(xmlHttpShopProduct.status==200)
       {
          if(xmlHttpShopProduct.responseText=="-2")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再加购友'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpShopProduct.responseText=="-90")
          {
             load.innerHTML = "<font color='#ff0000'>这个商店已经是您喜欢的...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font>";
          }
          else if(xmlHttpShopProduct.responseText=="1")
          {
             load.innerHTML = "<font color='#0F5230'>您已成功添加了喜欢的商店...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
             
       }
    }
}

function showimgpannel()
{
    var senderPos = getPos(document.getElementById('btnImgPannel'));
    DrawImgPannel(senderPos,30,0);      
}

function DrawImgPannel(senderPos,offsetLeft,offsetTop)
{
    if(document.getElementById("imgpannel")!=null)
    {
        document.getElementById("imgpannel").style.display='block';
    }
    else
    {
       
       load = document.createElement("DIV");    
        load.id="imgpannel";    
        load.style.position="absolute";   
        load.style.backgroundColor = "#ffffff";
        load.style.width = "auto";
        load.style.height = "auto";
        load.style.overflow = "auto";
        load.style.paddingTop = "10px";
        load.style.paddingBottom = "10px";
        load.style.paddingLeft = "10px";
        load.style.paddingRight = "10px";
        load.style.borderColor = "#606060"; 
        load.style.borderWidth = "2px";
        load.style.borderStyle = "solid";
        
        load.style.display = "block";
        load.style.fontSize = "13px";
        load.style.lineHeight = "40px";
        load.style.zIndex = "1";            
        document.body.appendChild(load);
    }
    load.style.left = senderPos.tagLeft+offsetLeft+"px";
    load.style.top = senderPos.tagTop+offsetTop+"px";
    //load.onclick = "this.style.display='none'";
    load.innerHTML = "图片URL：<input id=\"txtimgurl\" type=\"text\" /><br/><input type=\"button\" value=\"确定\" onclick=\"imgpannel.style.display='none';copyImg();  \"/><input type=\"button\" value=\"取消\" onclick=\"load.style.display='none'\"/>";
    
    //alert(load.innerHTML);
}

function copyImg()
{
    var imgtag = "<div class=\"pPic\"><img src='"+txtimgurl.value+"' /></div>";
    //frameobj.document.body.innerHTML+=imgtag;
    frameobj.focus();
 //获得选取的焦点
 var sel = frameobj.document.selection.createRange();
 insertHTML(imgtag);
}


function sendComment(productid,comment)
{ 
    var strcomment = comment.replace(/\s+/g,"");
    if(strcomment.length==0)
    {
       alert("内容不能为空！");
       return;
    }
        
    xmlHttpComment = createXMLHttpRequest();
    if(xmlHttpComment)
    {
       var url = "/ajax/sendcomment.aspx?ts="+new Date().getTime(); 
       xmlHttpComment.open("POST",url,true);
       xmlHttpComment.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpComment.onreadystatechange=commentReply;
       xmlHttpComment.send("productid="+productid+"&comment="+escape(strcomment)); 
       //alert("productid="+productid+"&comment="+comment);                                 
       var senderPos = getPos(document.getElementById('btnComment'));
       DrawMsgDIV(senderPos,0,25);
       
    }    
}

function commentReply()
{
    if(xmlHttpComment.readyState==4)
    {
       if(xmlHttpComment.status==200)
       {
          if(xmlHttpComment.responseText=="0")
          {
             load.innerHTML = "<a href='/login.html' onclick='document.getElementById(\"loadingdiv\").style.display=\"none\"' target='_blank' title='先登录，再发言'>还没有登录...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></a>";
          }
          else if(xmlHttpComment.responseText=="-1")
          {
             load.innerHTML = "<font color='#ff0000'>通讯出现问题，重新试一下...<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
          }
          else if(xmlHttpComment.responseText.indexOf("##")!=-1) 
          {  
             var txtcomment = document.getElementById('SendComment1_txtComment');            
             load.innerHTML = "<font color='#0F5230'>发表成功！<a href='javascript:void(0);' onclick='load.style.display=\"none\"'>[关闭]</a></font></font>";
             userinfo = xmlHttpComment.responseText.split('##');
             document.getElementById('cmdPannel').innerHTML = "<div class=\"cmd_floor\">" +
                                                                  "<div class=\"face\"><img class=\"imgface\" src='/img/user/"+userinfo[0]+".gif' onerror=\"this.src='/img/user/none.gif'\" /></div>"+
                                                                  "<div class=\"detail\">"+
                                                                      "<div class=\"title\"><a href='/group/people/"+userinfo[0]+".html' target=\"_blank\">"+userinfo[1]+"</a>系统记录时间</div>"+
                                                                      "<div class=\"msg\">"+txtcomment.value+"</div>"+
                                                                   "</div>"+
                                                               "</div>" + document.getElementById('cmdPannel').innerHTML; 
             document.getElementById('commentAmount').innerHTML = parseInt(document.getElementById('commentAmount').innerHTML,10) + 1;                                                  
             txtcomment.value = "";   
          }
             
       }
    }
}


