﻿function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "";
}

function showhide(obj) { var el = document.getElementById(obj); el.style.display = (el.style.display != 'none' ? 'none' : '' );}

function fsh(obj,img) { 
    var el = document.getElementById(obj); el.style.display = (el.style.display != 'none' ? 'none' : '' );
    var im = document.getElementById(img); im.className = (im.className != 'favshon' ? 'favshon' : 'favsh' );
}

function wincheck() {
    var divVal;
    divVal=document.getElementById('hdnComp');

    if (divVal.value=="1")
    {
    setTimeout('self.parent.myLytebox.end()', 3000);
    }
}

function wincheckajax() {
    setTimeout('self.parent.myLytebox.end()', 3000);
}

function chtab(d) { 
    	for(i=1;i<=3;i++){
		    aid = "aid"+i; pid = "pid"+i; lid = "list"+i;
		    divalla = document.getElementById(aid); divallp = document.getElementById(pid); divalll = document.getElementById(lid); 

		    if(i!=d) {
		        divalla.style.display = "none";
		        divallp.style.display = "";
		        divalll.style.display = "none";
    	    }

		    else {
		        divalla.style.display = "";
		        divallp.style.display = "none";
		        Effect.SlideDown(lid);
		        //divalll.style.display = "";
		    }
		}
}

function intab(d) { 

    	for(i=1;i<=2;i++){
		    aid = "aid"+i; pid = "pid"+i; lid = "list"+i;
		    divalla = document.getElementById(aid); divallp = document.getElementById(pid); divalll = document.getElementById(lid); 

		    if(i!=d) {
		        divalla.style.display = "none";
		        divallp.style.display = "";
		        divalll.style.display = "none";
    	    }

		    else {
		        divalla.style.display = "";
		        divallp.style.display = "none";
		        Effect.SlideDown(lid);
		        //divalll.style.display = "";
		    }
		}
}

function bustab(d,t,l) { 
    	for(i=1;i<=t;i++){
		    aid = l+"aid"+i; pid = l+"pid"+i; lid = l+"list"+i;
		    divalla = document.getElementById(aid); divallp = document.getElementById(pid); divalll = document.getElementById(lid); 

		    if(i!=d) {
		        divalla.style.display = "none";
		        divallp.style.display = "";
		        divalll.style.display = "none";
    	    }

		    else {
		        divalla.style.display = "";
		        divallp.style.display = "none";
		        Effect.SlideDown(lid);
		        //divalll.style.display = "";
		    }
		}
}



function insertComment(userid) {

var contentText=document.getElementById('ctl00_postBody_txtComment').value;
var postid=document.getElementById('ctl00_postBody_hdnPostid').value;
var divCommentResult=document.getElementById('divCommentResult');
if (userid>0 && contentText!='' && postid>0)
{

  new Ajax.Request('http://www.ideshot.com/Ajax/CommentInsert.aspx', {
  method: 'get',
  onSuccess: function(transport){
     
      var response = transport.responseText;
          
      if(response==1) {
         divCommentResult.innerHTML="<div class='okmsg'>Yorumunuz gönderilmiştir, teşekkürler.</div>";
         document.getElementById('ctl00_postBody_txtComment').value = "";
      }
      else
         divCommentResult.innerHTML="<div class='ermsg'>Gönderilemedi, lütfen tekrar deneyin!</div>";
  },
  onFailure: function(){ alert('Yorumunuz gönderilemedi, lütfen tekrar deneyin!') },
  parameters: {userid: userid, postid: postid, contentText:contentText}
  });
 }
 else
  divCommentResult.innerHTML="<div class='ermsg'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}

function modifyComment(userid,commentid) {

var contentText=document.getElementById('txtComment').value;
var commentid=document.getElementById('hdnCommentid').value;
var divCommentResult=document.getElementById('divCommentResult');
if (userid>0 && contentText!='' && commentid>0)
{

  new Ajax.Request('http://www.ideshot.com/Ajax/CommentInsert.aspx', {
  method: 'get',
  onSuccess: function(transport){
     
      var response = transport.responseText;
          
      if(response==1) {
         self.parent.location = commentid=document.getElementById('hdnUrlReferrer').value;
      }
      else
         divCommentResult.innerHTML="<div class='ermsg'>Gönderilemedi, lütfen tekrar deneyin!</div>";
  },
  onFailure: function(){ alert('Yorumunuz gönderilemedi, lütfen tekrar deneyin!') },
  parameters: {userid: userid, commentid: commentid, contentText:contentText}
  });
 }
 else
  divCommentResult.innerHTML="<div class='ermsg'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}

function insertPost(userid) {
//debugger;

	var postTitle=document.getElementById('txtPostTitle').value;
	var postContent=document.getElementById('txtPostContent').value;
	var postTag=document.getElementById('txtTag').value;
	var brandid=document.getElementById('hdnBrandid').value;
	var postid=document.getElementById('hdnPostid').value;
	var subCategoryid=document.getElementById('ddSubCategory').value;
	var categoryid=document.getElementById('ddCategory').value;
	var postType=document.getElementById('hdnPostType').value;
	
	var divC=document.getElementById('divResult');
		
	if (userid>0 && postTitle!='' && postContent!='')
	{
	
	  new Ajax.Request('http://www.ideshot.com/Ajax/PostInsert.aspx', {
	  method: 'get',
	  onSuccess: function(transport){
		
		  var response = transport.responseText;
		  
			  
		  if(response=="")
		    divC.innerHTML="<div class='ermsg'>Gönderilemedi, lütfen tekrar deneyin!</div>";
		  else if (response=="mod")
		  {
		    divC.innerHTML="<div class='addpostokmsg'>Öneriniz gönderilmiştir. Onaylandıktan sonra yayınlanacaktır.</div>";
		    document.getElementById('btn').disabled='disabled';
		    document.getElementById('divAddPost').style.display='none';
		    wincheckajax();
		  }
		  else
		     self.parent.location = response;
			 
	  },
	  onFailure: function(){ alert('Yorumunuz gönderilemedi, lütfen tekrar deneyin!') },
	  parameters: {userid: userid, postTitle: postTitle,postTag: postTag, postContent:postContent,brandid: brandid,postid: postid,subCategoryid:subCategoryid,categoryid:categoryid,postType:postType}
	  });
	 }
	 else
	  divC.innerHTML="<div class='er'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}



function refreshSubCategory(categoryid) {

     
      var subCategoryList=document.getElementById("hdnSubCategory").value;
      var childDropDown=document.getElementById("ddSubCategory");

      if (!childDropDown){
         return;
      }

      childDropDown.length = 0;

      if (!subCategoryList){
          return;
      }
      
       var option = document.createElement("OPTION");
       option.value = "0";
       option.innerHTML = "Seçiniz";     
       childDropDown.appendChild(option);
      
      var rows = subCategoryList.split('~'); 
      for (var i = 0; i < rows.length; ++i){
      
         var cols = rows[i].split('|'); 
         if (categoryid==cols[0])
         {     
             option = document.createElement("OPTION");
             option.value = cols[1];
             option.innerHTML = cols[2];     
             childDropDown.appendChild(option);
         }
      
      }     
}

function insertPostRate(postid,userid,rate) {
//debugger;

if (userid>0 &&  postid>0 && rate>0)
{

  new Ajax.Request('http://www.ideshot.com/Ajax/RateInsert.aspx', {
  method: 'get',
  onSuccess: function(transport){
     //debugger;
      var response = transport.responseText;
          
      if(response==1) {
         //alert("ok");
		 LyteStart("http://www.ideshot.com/RateResponse.aspx?response=" + response,'320','60','no');
         aElem = document.getElementById("rate_" + postid);
         aElem.className = "likeon";
         
      } else if(response==2) {
         //alert("exist");
		 LyteStart("http://www.ideshot.com/RateResponse.aspx?response=" + response,'320','60','no');
         aElem = document.getElementById("rate_" + postid);
         aElem.className = "likeon";
      } else {
         //alert("err");
		 LyteStart("http://www.ideshot.com/RateResponse.aspx?response=" + response,'320','60','no');
      }
      
         
  },
  onFailure: function(){ alert('Yorumunuz gönderilemedi, lütfen tekrar deneyin!') },
  parameters: { postid: postid,userid: userid, rate:rate}
  });
 }
 else
  divC.innerHTML="<div class='er'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}

function LyteStart(url,width,height,scrolling) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   objLink.setAttribute('rel','lyteframe');
   objLink.setAttribute('rev','width:'+width+';height:'+height+';scrolling: '+scrolling+';')
   myLytebox.start(objLink, false, true);
  
}

function moderateItem(process, status, itemid) {

debugger;
    answer = confirm("Emin misiniz?");
    if (!answer) return;

debugger;

var divCommentResult=document.getElementById('modify_' + process + '_' + status + '_' + itemid);


if (process > 0 && status >= 0 && itemid>0)
{

  new Ajax.Request('http://www.ideshot.com/Ajax/AdminProcess.aspx', {
  method: 'get',
  onSuccess: function(transport){
     
      var response = transport.responseText;
          
      if (response == '0') {
        divCommentResult.innerHTML="<div class='ermsg'>Gönderilemedi, lütfen tekrar deneyin!</div>";
      }
      else
        divCommentResult.innerHTML = response;
         
  },
  onFailure: function(){ alert('Gönderilemedi, lütfen tekrar deneyin!') },
  parameters: {process: process, status: status, itemid:itemid}
  });
 }
 else
  divCommentResult.innerHTML="<div class='ermsg'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}

function userFollowAction(followid,status) {
  
  var divA=document.getElementById("ctl00_ContentPlaceHolder1_divFollowAction");
  divA.innerHTML="<img src=\"http://www.ideshot.com/images/loading.gif\" />";

  new Ajax.Request('http://www.ideshot.com/Ajax/UserFollowProcess.aspx', {
  method: 'get',
  onSuccess: function(transport){

      var response = transport.responseText;
          
      if(response!="err")
         divA.innerHTML=response;
  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {followid: followid, status:status}
  });
 }
 
 function userFollowActionFromFriend(followid,status,followType) {
  
  var divName='divFollowAction_';
    if (followType==1)
      divName +='Following_' + followid;
    else if (followType==2)
      divName +='Follower_' + followid;
  
  var divA=document.getElementById(divName);
  divA.innerHTML="<img src=\"http://www.ideshot.com/images/loading.gif\" />";

  new Ajax.Request('http://www.ideshot.com/Ajax/UserFollowProcessFromFriend.aspx', {
  method: 'get',
  onSuccess: function(transport){

      var response = transport.responseText;
          
      if(response!="err")
         divA.innerHTML=response;
  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {followid: followid, status:status, followType:followType}
  });
 }
 
 function brandFavorite(brandid,status) {

  var divA=document.getElementById("divBrandFavorite");

  new Ajax.Request('http://www.ideshot.com/Ajax/UserBrandProcess.aspx', {
  method: 'get',
  onSuccess: function(transport){

      var response = transport.responseText;
          
      if(response!="err")
         divA.innerHTML=response;
  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {brandid: brandid, status:status}
  });
 }
 
   function allBrandFavorite(brandid,status) {

  var divA=document.getElementById(brandid);

  new Ajax.Request('http://www.ideshot.com/Ajax/UserAllBrandProcess.aspx', {
  method: 'get',
  onSuccess: function(transport){

      var response = transport.responseText;
      debugger;
        
      if(response!="err")
         {
                if(status==1)
	 {
    		divA.className="remfav";
                            divA.onclick=function() {allBrandFavorite(brandid,2)};

               }
               else
	{
    		divA.className="addfav";
                            divA.onclick=function() {allBrandFavorite(brandid,1)};

              }

         }
  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {brandid: brandid, status:status}
  });
 }
 
 function getCampaign(brandid) {
debugger;
if (brandid>0 )
{

  new Ajax.Request('http://www.ideshot.com/Ajax/GetCampaign.aspx', {
  method: 'get',
  onSuccess: function(transport){
     debugger;

      var response =  eval(transport.responseText);
       
      var imgSmall=document.getElementById('ctl00_ContentPlaceHolder1_imgSmall');
      var imgBrandSmall=document.getElementById('ctl00_ContentPlaceHolder1_imgBrandSmall');
      var aUrl1=document.getElementById('ctl00_ContentPlaceHolder1_aUrl1');
      var aUrl2=document.getElementById('ctl00_ContentPlaceHolder1_aUrl2');
      var spnTitle=document.getElementById('ctl00_ContentPlaceHolder1_spnTitle');
      var spnSummary=document.getElementById('ctl00_ContentPlaceHolder1_spnSummary');
      var aBrand=document.getElementById('ctl00_ContentPlaceHolder1_aBrand');
      var spnBrandDescription=document.getElementById('ctl00_ContentPlaceHolder1_spnBrandDescription');
      var aUrl3=document.getElementById('ctl00_ContentPlaceHolder1_aUrl3');
      var aShare=document.getElementById('ctl00_ContentPlaceHolder1_aShare');
            
              
        imgSmall.src =response[0].smallImage;
        aUrl1.href = response[0].pageName;
        aUrl2.href = response[0].pageName;
        spnTitle.innerHTML = response[0].title;
        spnSummary.innerHTML = response[0].summary;
        imgBrandSmall.src = response[0].brandSmallImage;      
        aBrand.href=response[0].brandUrl;
        aBrand.title = response[0].brandDescription;
        spnBrandDescription.innerHTML = response[0].brandDescription;
        aUrl3.href = response[0].brandUrl;
        aShare.href = response[0].shareUrl;

  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {brandid: brandid}
  });
 }
 else
  divCommentResult.innerHTML="<div class='ermsg'>Lütfen formdaki tüm alanları doldurunuz.</div>";
}

function checkAvailabilityUsername(d) {
    
   var username=document.getElementById("ctl00_ContentPlaceHolder1_" + d).value;
   var divCtrl=document.getElementById(d + "Ctrl");
   var btn=document.getElementById("ctl00_ContentPlaceHolder1_btnSetUsername" );
   
   if (username.length>=3)
   {

   
   divCtrl.innerHTML="<img src=\"http://www.ideshot.com/images/loading.gif\" />";

   new Ajax.Request('http://www.ideshot.com/Ajax/CheckAvailabilityUsername.aspx', {
   method: 'get',
   onSuccess: function(transport){

      var response = transport.responseText;
          
      if(response!="err")
      {
          if (response=="true")
          { 
             divCtrl.innerHTML="<span class='chkokmsg'>Kullanılabilir</span>";
             btn.disabled=false;
          }
          else if (response=="false")
          {
             divCtrl.innerHTML="<span class='chkermsg'>Kullanılamaz</span>";
             btn.disabled=true;
          }  
          else if (response=="invalid")
          {
             divCtrl.innerHTML="<span class='chkermsg'>Geçersiz</span>";
             btn.disabled=true;
          } 
      }
  },
  onFailure: function(){ alert('Hata oluştu!') },
  parameters: {username:username}
  });
  }
  else
  {
    divCtrl.innerHTML="<span class='chkermsg'>En az 3 karakter</span>";
    btn.disabled=true;
    
  }
    
}