// JScript File
// JScript File
if (typeof SULEKHA == "undefined") {
    var SULEKHA = {};
}

SULEKHA.namespace = function() {
    //alert("namespace");
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=SULEKHA;

        for (j=(d[0] == "SULEKHA") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    //alert(o);
    return o;
};
YAHOO.namespace("sulekha.container");
// Destination comments starts
function fnWait(sWait,headtext)
{
  
  if (sWait) 
   {
    YAHOO.sulekha.container.wait = new YAHOO.widget.Panel("wait",{x:10, width: "240px", fixedcenter: true, close: false, draggable: false, modal: true,visible: false } );
    YAHOO.sulekha.container.wait.setHeader(headtext);
    YAHOO.sulekha.container.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
    YAHOO.sulekha.container.wait.render(document.body);
    YAHOO.sulekha.container.wait.show();
    }
  else
    YAHOO.sulekha.container.wait.hide();
 } 
function close()
 {

  fnWait(false,''); 
  window.location.href=window.location.href;
}

 function fnChkLogincomments()
    {   
        document.getElementById('commentbox').style.display='none';
        sName = getCookie('sulekha_screenname');
        sBaseaddress = getCookie('sulekha_baseaddress');
        if (sBaseaddress == null || sBaseaddress == '' || sBaseaddress.indexOf('.sulekha.com') <= 0 || sName == null || sName == '')
            window.location.href ='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
        else
            return 1;    
     }   
function fnrendercomments()
{
var islogincomments=fnChkLogincomments();
if (islogincomments =1)
{
  document.getElementById('commentbox').style.display='block';
}
}

function fnClosecomments()
{
  document.getElementById('commentbox').style.display='none';
  document.getElementById('resultstarcommentdiv').innerHTML = '';
  document.getElementById('submitstarcommentdiv').style.display='block';
}

function fnInsertFeedbackDetail()
{
var objstarcomment = document.getElementById('Messagetopic').value;
 var sErrorMovies='';
    if (( document.getElementById('Messagetopic').value ) == '' || ( document.getElementById('Messagetopic').value ) == null ) 
     {
       sErrorMovies = 'Please enter the Comment';
     }
     if (sErrorMovies.length > 0)
     {
       alert(sErrorMovies);
    }
 else
 {
    YAHOO.util.Connect.setForm( document.getElementById('frmstarcomments'));
    YAHOO.util.Connect.asyncRequest("POST","/startaforum.aspx",callbackmoviescomments_Feedback);
    document.getElementById('submitstarcommentdiv').style.display='none';
    document.getElementById('resultstarcommentdiv').innerHTML = "<div class='info'> <img src='http://www.sulekha.com/img07/greyloading.gif' border='0'/>Posting a Comment,please wait...</div>" ;
}
}

var handleSuccessmoviescomments_Feedback = function(o)
{
// document.getElementById('commentbox').style.display='none';
//YAHOO.sulekha.container.wait.hide();
if(o.responseText !== undefined)
{
var sResult = o.responseText;
sResult=sResult.replace(/(&gt;)/g,'>');
sResult=sResult.replace(/(&lt;)/g,'<');
document.getElementById('resultstarcommentdiv').innerHTML = sResult;
//YAHOO.sulekha.container.wait.setBody(sResult);
}
}
var handleFailuremoviescomments_Feedback = function(o)
{
 if(o.responseText !== undefined)
  {
    document.getElementById('submitstarcommentdiv').style.display='';
    document.getElementById('resultstarcommentdiv').innerHTML = o.statusText ;
   // alert("Transaction failed.Pls try again. The error is: " + o.statusText);
  }
}
var callbackmoviescomments_Feedback =
{
  success:handleSuccessmoviescomments_Feedback,
  failure: handleFailuremoviescomments_Feedback
};

function setdisplayorder()
{
 var Dispopt = document.getElementsByName('dispoption'); 
  var sDisUrl = window.location.href;
 if (Dispopt != null || Dispopt != '')
  {
   sDisUrl= sDisUrl.substring(sDisUrl.indexOf('=')+1);
   sDisUrl=sDisUrl.substring(0,1);
   if (sDisUrl == "1") Dispopt[1].checked = true;
   else  if (sDisUrl == "0") Dispopt[0].checked = true;
   else checked = true;
   }
 
}

function ChangeDisplayOrder()
{

   var objDisp = document.getElementsByName('dispoption'); 

var sUrl = window.location.href;

sUrl = sUrl.substring(0,sUrl.indexOf('#'));


if (sUrl.indexOf('?&dispoption=') >= 0)
    sUrl= sUrl.substring(0,sUrl.indexOf('?&dispoption='));

var sel = 0;
if (objDisp[0].checked == 1)
    sel = 0;
else if (objDisp[1].checked == 1)
    sel = 1;
sUrl = sUrl + '?&dispoption=' + sel;

var tUrl = window.location.href;
var tPos = tUrl.indexOf('#');
var tHash = '';
if (tPos >= 0)
	tHash = tUrl.substring(tPos, tUrl.length)

sUrl = sUrl + tHash;
window.location.href = sUrl;
};
function PostaReply()
{
fnGetEditorData();
SULEKHA.Forums.PostaReply('forumpost');
};
function fnChkLogin()
{   
    sName = getCookie('sulekha_screenname');
    sBaseaddress = getCookie('sulekha_baseaddress');
    if (sBaseaddress == null || sBaseaddress == '' || sBaseaddress.indexOf('.sulekha.com') <= 0 || sName == null || sName == '')
        window.location.href ='http://www.sulekha.com/network/signin.aspx';
    else
        return 1;    
}      
function SetupReplyForm(forumid,contentid)
{
 fnChkLogin();

var FormObj = document.getElementById ('forumposttemplate');
var ShowForumInDiv = document.getElementById('input'+contentid);


var subject = document.getElementById ('sub-' + contentid).innerHTML;
var forumnam = document.getElementById ('hforum' + contentid).value;
var titleurl = document.getElementById ('htitleurl' + contentid).value;
var threadtitleurl = document.getElementById ('hthreadurl' + contentid).value;
var thread = document.getElementById ('hthread' + contentid).value;
var threadowner = document.getElementById ('hthreadowner' + contentid).value;
var threadreplyowner = document.getElementById ('hthreadreplyowner' + contentid).value;
var moviescategory = document.getElementById ('moviescategory' + contentid).value;
var moviestitleurl = document.getElementById ('moviestitleurl' + contentid).value;
//    var moviestarstilllink = document.getElementById ('moviestarstilllink').value;
//    var moviestarwalllink = document.getElementById ('moviestarwalllink').value;
//    var moviestartrailink = document.getElementById ('moviestartrailink').value;
//    var moviestarrevlink = document.getElementById ('moviestarrevlink').value;
//    var moviestareventlink = document.getElementById ('moviestareventlink').value;
//var moviestarstill = document.getElementById ('moviestarstill').value;
//var starid = document.getElementById ('starid').value;
var moviestarstilllink = '';
var moviestarwalllink = '';
var moviestartrailink = '';
var moviestarrevlink = '';
var moviestareventlink = '';
var moviestarstill = '';
var starid = '';
if (SULEKHA.Forums.CurrentForm == "undefined"  || SULEKHA.Forums.CurrentForm == '')
{
}
else
{
    var PrevForm = document.getElementById (SULEKHA.Forums.CurrentForm);
    PrevForm.innerHTML='';
}

ShowForumInDiv.innerHTML = "";

var FormHTML = "<form id='forumpost' class='forumpostform'>" +FormObj.innerHTML + "</form>";
var sTitle = '\'' + 'Re:' + subject.replace('Re:','') + '\'';
if (navigator.appName.indexOf("Netscape") != -1)
  sTitle = sTitle.substring(1,sTitle.length - 1);
FormHTML = FormHTML.replace('title', 'title');
FormHTML = FormHTML.replace('titlevalue', sTitle);
FormHTML = FormHTML.replace('contentidvalue', contentid);
FormHTML = FormHTML.replace('forumidvalue', forumid);
FormHTML = FormHTML.replace('message', 'message');
FormHTML = FormHTML.replace('forumnamvalue', forumnam);
FormHTML = FormHTML.replace('threadtitleurlvalue', threadtitleurl);
FormHTML = FormHTML.replace('titleurlvalue', titleurl);
FormHTML = FormHTML.replace('theardidvalue', thread);
FormHTML = FormHTML.replace('theardownervalue', threadowner);
FormHTML = FormHTML.replace('theardreplyownervalue', threadreplyowner);
FormHTML = FormHTML.replace('moviestitleurlvalue', moviestitleurl);
FormHTML = FormHTML.replace('moviescategoryvalue', moviescategory);
FormHTML = FormHTML.replace('moviestarstilllinkvalue', moviestarstilllink);
FormHTML = FormHTML.replace('moviestarwalllinkvalue', moviestarwalllink);
FormHTML = FormHTML.replace('moviestartrailinkvalue', moviestartrailink);
FormHTML = FormHTML.replace('moviestarrevlinkvalue', moviestarrevlink);
FormHTML = FormHTML.replace('moviestareventlinkvalue', moviestareventlink);
FormHTML = FormHTML.replace('moviestarstillvalue', moviestarstill);
FormHTML = FormHTML.replace('staridvalue', starid);
FormHTML = FormHTML.replace('bSavePosttemplate', 'bSavePost');
ShowForumInDiv.innerHTML = FormHTML ;
SULEKHA.Forums.CurrentForm = 'input'+contentid ;
YAHOO.util.Event.addListener("bSavePost", "click", PostaReply);
ShowForumInDiv.style.display = "block";   
};


function fnEditorLoad()
{
    var sBasePath =  '/FCKeditor_2.4.3/fckeditor/'; 
    var oFCKeditor = new FCKeditor('message');
    oFCKeditor.ToolbarSet = 'Comments';
    oFCKeditor.BasePath	= sBasePath;
    oFCKeditor.Height = '250px';
    oFCKeditor.ReplaceTextarea(); 
} 
function fnFckInsertVideo()
{
    var strToInsert = "<div class='videoobject' align='center'>"+document.getElementById('iVideoTitle').value +"<br/>"+ document.getElementById('iImgUrl').value+"</div>";
    oEditorInstance = FCKeditorAPI.GetInstance('message');        
    oImageDiv.innerHTML =  strToInsert;

    YAHOO.sulekha.container.dialog2.hide();
}
function fnShowVideoDialog()
{
    var oEditorInstance = FCKeditorAPI.GetInstance('message');
    oImageDiv = oEditorInstance.CreateElement( 'SPAN' ) ;
    YAHOO.sulekha.container.dialog2.show();
}

// Function for supporting posting of forums
var handleForumPostSuccess =  function (o)
{   
YAHOO.sulekha.container.wait.hide();
if(o.responseText !== undefined)
{
var sResult= o.responseText;
document.getElementById('title').value="";
document.getElementById('message').value="";
var nameforum=document.getElementById('formtype').value;
//window.location.href=sResult;
if(nameforum=="newtopic")
{
//window.location.href=sResult;
document.getElementById('dialog1').innerHTML = sResult;
YAHOO.sulekha.container.dialog1.show();

}
if(nameforum=="reply")
{
//window.location.href=sResult;
document.getElementById('dialog1').innerHTML = sResult;
YAHOO.sulekha.container.dialog1.show();
}
}
};

var handleForumPostFailure = function (o)
{
var Result = o.status + " " + o.statusText;
alert("Transaction failed.  The error is: " + Result);
};

SULEKHA.Forums = {
CurrentForm:'',
StartaTopic:function(FormId)
{
var sError='';
if (( document.getElementById('title').value ) == '' || ( document.getElementById('title').value ) == null ) 
{
sError = 'Please enter the subject';
}
if (( document.getElementById('message').value ) == '' || ( document.getElementById('message').value ) == null ) 
{
sError = 'Please enter the message';
}
if (sError.length > 0)
{
alert(sError);
}
else
{
var   fValidateResult = this.ValidateFormFields('newtopic', FormId);

if ( fValidateResult == false )
return ;


fnWait(true,"Starting a Topic, please wait...");

this.PostToServer(FormId);
}

},

PostaReply:function(FormId)
{

var sError='';
if (( document.getElementById('title').value ) == '' || ( document.getElementById('title').value ) == null ) 
{
sError = 'Please enter the subject';
}
if (( document.getElementById('message').value ) == '' || ( document.getElementById('message').value ) == null ) 
{
sError = 'Please enter the message';
}
if (sError.length > 0)
{
alert(sError);
}
else
{
var   fValidateResult = this.ValidateFormFields('reply', FormId);

if ( fValidateResult == false )
return ;


fnWait(true,"Posting Reply, please wait...");

this.PostToServer(FormId);
}
},
ValidateFormFields:function(formType, formId)
{

return true;
},

PostToServer:function(FormId)
{

try
{

var callback =
{
    success: handleForumPostSuccess,
    failure: handleForumPostFailure,
    argument: [FormId]
};

YAHOO.util.Connect.setForm(FormId);
YAHOO.util.Connect.asyncRequest('POST', '/startaforum.aspx', callback);
}
catch(e)
{
alert(e);
}
}
} ;

function fnGetEditorData()
{
var stripHTML = /<\S[^><]*>/g;
var sEditorData = GetContents('message'); 
 sEditorData = sEditorData.replace('<span name="sVideoInsert" style="color: rgb(204, 204, 204);">&lt; Video &gt;</span>','');
// cleanup all word related codes
 var oCheckbox = document.getElementsByName('forumid');
 
//sEditorData = CleanWord(sEditorData, true, true);

document.getElementById('message').value = sEditorData ;


}
function GetContents(objTxtArea)
{   
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance(objTxtArea) ;
    // Get the editor contents in XHTML.
    return( oEditor.GetXHTML( true ) ) ;		// "true" means you want it formatted.
}

function hidereplies(parentcommentid, lnk )
   {
     var objShowReply = document.getElementById('showreply'+parentcommentid);
     var ObjHideReply = document.getElementById('hidereply'+parentcommentid);
//     alert(objShowReply.style.display + ObjHideReply.style.display);
//     alert(objShowReply.id + ObjHideReply.id);
     if(objShowReply.style.display =="block")
        objShowReply.style.display="none";
     else
        objShowReply.style.display="block";
     
     if(ObjHideReply.style.display =="none")
        ObjHideReply.style.display="block";
     else
        ObjHideReply.style.display="none";
        
        if(ObjHideReply.style.display == 'none')
  lnk.innerHTML=lnk.innerHTML.replace('View','Hide');
 
 if(ObjHideReply.style.display == 'block')
  lnk.innerHTML=lnk.innerHTML.replace('Hide','View');
  
}  


function setuopdialog()
{

YAHOO.sulekha.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
												            { width : "515px",
												              fixedcenter : true,
												              visible : false, 
												              constraintoviewport : true,
												              modal:true
												             } );	
YAHOO.sulekha.container.dialog1.render();
YAHOO.sulekha.container.dialog2 = new YAHOO.widget.Dialog("yui-editor-panel-dialog", 
									                { width : "515px",
									                  fixedcenter : true,
									                  visible : false, 
									                  constraintoviewport : true,
									                  modal:true
									                 } );	
YAHOO.sulekha.container.dialog2.render();   
        
       
}