﻿var blnCaptchaError = false;
var ErrorMessage = "";
function reSizeFromFlash(){/*Players Call This ; should be removed from fla and players*/}
function WS_Comment(params)
{
	glbXmlRequest = new AkimanXmlHTTP(getID(strLoadingDiv),getID(strDebugDiv));
	var soapData = SoapDataBuilder("CommentService",params);	
	AjaxRequest("/Mod/Comment/WS_Comment.asmx",soapData,"",strLoadingDiv);	
}
function Flash(strIDPrefix,strFileName,strMovieUrl,strWidth,strHeight,lngCommentID)
{
    if (swfobject)
	{
	    var attributes = {
		id:strIDPrefix+strFileName,
		name: strIDPrefix+strFileName};
	    
	    var params = {quality:"high",
		align:"middle",
		play:"true",
		loop:"true",
		scale:"showall",
		wmode:"opaque",
		devicefont:"false",
		bgcolor:"#ffffff",
		menu:"true",
		allowScriptAccess:"sameDomain",
		salign:""};
		
	    var flashvars = { 
	    fileName:strFileName};
	    
	    swfobject.embedSWF(strMovieUrl, "CommentText"+lngCommentID, strWidth, strHeight, "7", false, flashvars, params, attributes);
    }
}
function RecordFlash(strID,strFileName,strMovieUrl,strWidth,strHeight,lngObjectID,lngObjectTypeID,strSitePrefix,blnIsLoggedIn)
{
    if (swfobject)
	{
	    var attributes = {
		id:strFileName,
		name: strFileName};
	    
	    var params = {
	    quality:"high",
		align:"middle",
		play:"true",
		loop:"true",
		scale:"noscale",
		wmode:"window",
		devicefont:"false",
		bgcolor:"#ffffff",
		menu:"true",
		allowScriptAccess:"sameDomain",
		salign:""};
		
	    var flashvars = { 
	    OID:lngObjectID,
	    OTID:lngObjectTypeID,
	    SP:strSitePrefix,
	    UNO:UniqueID(),
	    ILI:blnIsLoggedIn};
	    
	    swfobject.embedSWF(strMovieUrl, strID, strWidth, strHeight, "7", false, flashvars, params, attributes);
    }
}
function CloseAudioComment()
{
    CloseMediaComment('Audio');
}
function CloseVideoComment()
{
    CloseMediaComment('Video');
}
function CloseMediaComment(strType)
{
    NoDisplay("OverlayBack");NoDisplay(strType+"Comment");
}
function ApproveComment(lngCommentID)
{
    params = CustomParamBuilder("strOperation","ApproveComment");
    params += CustomParamBuilder("lngCommentID", lngCommentID);
	WS_Comment(params);    
}

function AddAudioComment(lngObjectID,lngObjectTypeID,strSitePrefix,blnIsLoggedIn)
{
    RecordFlash('AudioRecordFlash','AudioRecorder','/Mod/Comment/AudioRecorder.swf',487,145,lngObjectID,lngObjectTypeID ,strSitePrefix,blnIsLoggedIn);
    Display("OverlayBack");Display("AudioComment");
}
function AddPublicAudioComment(lngObjectID,lngObjectTypeID,strSitePrefix)
{
    NoDisplay("Error");ErrorMessage = "";
    if (ControlPublicUser()) AddAudioComment(lngObjectID,lngObjectTypeID,strSitePrefix,false);
}
function AddVideoComment(lngObjectID,lngObjectTypeID,strSitePrefix,blnIsLoggedIn)
{
    RecordFlash('VideoRecordFlash','VideoRecorder','/Mod/Comment/VideoRecorder.swf',487,329,lngObjectID,lngObjectTypeID ,strSitePrefix,blnIsLoggedIn);
    Display("OverlayBack");Display("VideoComment");
}
function AddPublicVideoComment(lngObjectID,lngObjectTypeID,strSitePrefix)
{
    NoDisplay("Error");ErrorMessage = "";
    if (ControlPublicUser()) AddVideoComment(lngObjectID,lngObjectTypeID,strSitePrefix,false);
}
function ShowMediaTab(strTab,blnVideo)
{
    var strPrefix = blnVideo ? "Video" : "Audio";
    NoDisplay(strPrefix+"RecordingTips");NoDisplay(strPrefix+"MicSetup");
    ChangeClass(strPrefix+"RecordingTipsTab","Tab");ChangeClass(strPrefix+"MicSetupTab","Tab");    
    if (blnVideo)
    {
        NoDisplay(strPrefix+"VideoSetup");ChangeClass(strPrefix+"VideoSetupTab","Tab");
    }    
    Display(strPrefix+strTab);
    ChangeClass(strPrefix+strTab+"Tab","TabSelected");
}
function SendMediaComment(strFileName,blnIsLoggedIn,strType)
{
    params = CustomParamBuilder("strOperation", blnIsLoggedIn ? "Send"+strType+"Comment" : "SendPublic"+strType+"Comment");
    params +=CustomParamBuilder("strFileName", strFileName);
	params += parseAspForm();
	WS_Comment(params);
	NoDisplay("OverlayBack");NoDisplay(strType+"Comment");
}
function SendVideoComment(strFileName,blnIsLoggedIn)
{
    SendMediaComment(strFileName,blnIsLoggedIn,"Video")
}
function SendAudioComment(strFileName,blnIsLoggedIn)
{
    SendMediaComment(strFileName,blnIsLoggedIn,"Audio")
}
function ControlCommentTxt()
{
    var objComment = GetAspFormField("txtComment");
    if (objComment.value.length < 2)
    {
        ErrorMessage += "<p>"+Error_NoComment+"</p>";
    }  
}
function ControlPublicUser()
{
    var objPublicName = GetAspFormField("strPublicName");
    var objPublicEmail = GetAspFormField("strPublicEmail");
    var objCaptcha = GetAspFormField("strCaptcha");    
   
    if (objPublicName.value.length < 2)
    {
       ErrorMessage += "<p>"+Error_PublicName+"</p>";
    }         
    if (!isEmail(objPublicEmail.value))
    {
	    ErrorMessage += "<p>"+Error_PublicEmail+"</p>";
	}      
	if (objCaptcha.value.length != 5)	
	{
		ErrorMessage += "<p>"+Error_Captcha+"</p>";
	}	
	if (!(ErrorMessage.length > 0))
	{	    
	    var	params ;
	    params = CustomParamBuilder("strOperation", "ControlCaptcha");
	    params += parseAspForm();
	    WS_Comment(params);
	    if (blnCaptchaError)
	    {
	        ErrorMessage += "<p>"+Error_Captcha+"</p>";
	    }
	}	
	if (ErrorMessage.length > 0)
	{
	    SetInnerHtml("Error",ErrorMessage);
	    Display("Error");
	    return false;
	}
	else
	{
	    return true;
	}
}
function SendPublicComment()
{
    NoDisplay("Error");    
    ErrorMessage = "";
    ControlCommentTxt();    
    if (ControlPublicUser())
    {
        var	params ;
        params = CustomParamBuilder("strOperation", "SendPublicComment");
	    params += parseAspForm();
	    WS_Comment(params);
    }
}
function SendComment()
{
    NoDisplay("Error");    
    ErrorMessage = "";
    ControlCommentTxt();
	if (ErrorMessage.length > 0)
	{
	    SetInnerHtml("Error",ErrorMessage);
	    Display("Error");
	}
	else
	{
        var params = CustomParamBuilder("strOperation", "SendComment");
	    params += parseAspForm();
	    WS_Comment(params);
	}
}
function EditComment(lngCommentID)
{
    var	params = CustomParamBuilder("strOperation", "EditComment");
    params += CustomParamBuilder("lngCommentID", lngCommentID);
    WS_Comment(params);
    SetAspFormField("lngCommentID",lngCommentID);
    Display("CancelButton");Display("SaveButton");NoDisplay("SendButton");
    NoDisplay("AddAudio");NoDisplay("AddVideo");
    SetInnerHtml("ReplyBody","");NoDisplay("Reply");   
    TimedScrollTo("CommentBox","CommentContainer"+lngCommentID,500);
    FlashCommentTextBox();
}
function DeleteComment(lngCommentID)
{
    if (confirm(Error_ConfirmDelete))
    {
	    var	params = CustomParamBuilder("strOperation", "DeleteComment");	
	    params += CustomParamBuilder("lngCommentID", lngCommentID);
	    params += CustomParamBuilder("lngObjectID", GetAspFormField("lngObjectID").value);
	    params += CustomParamBuilder("lngObjectTypeID", GetAspFormField("lngObjectTypeID").value);
	    WS_Comment(params);        
    }
}
function ReplyComment(lngCommentID,intLevel)
{
    var objCommentText = getID("CommentContainer"+lngCommentID);
    if (objCommentText)
    {
        SetInnerHtml("ReplyBody",objCommentText.innerHTML);
        Display("Reply");Display("CancelButton");
        SetAspFormField("lngParentCommentID",lngCommentID);SetAspFormField("intLevel",intLevel);
        SetAspFormField("txtComment","");
        TimedScrollTo("CommentBox","CommentContainer"+lngCommentID,1000);
        FlashCommentTextBox();
    }
}
function CancelComment()
{
    SetAspFormField("txtComment","");SetAspFormField("lngParentCommentID",0);SetAspFormField("lngCommentID",0);SetAspFormField("intLevel",0);
    NoDisplay("Reply");NoDisplay("CancelButton");NoDisplay("SaveButton");
    Display("SendButton");Display("AddAudio");Display("AddVideo");
    SetInnerHtml("ReplyBody","");  
}
function SaveComment()
{
    var	params = CustomParamBuilder("strOperation", "SaveComment");
    params += parseAspForm();
    WS_Comment(params);
}
function ShowThanks(blnPublic)
{
    Display("SendButton");Display("AddAudio");Display("AddVideo");
    NoDisplay("CancelButton");NoDisplay("SaveButton");NoDisplay("Reply");
    SetAspFormField("txtComment","");SetAspFormField("lngParentCommentID",0);SetAspFormField("lngCommentID",0);SetAspFormField("intLevel",0);
    SetInnerHtml("ReplyBody","");    
    if (blnPublic)
    {
        Display("Thanks");
        SetAspFormField("strPublicName","");SetAspFormField("strPublicEmail","");SetAspFormField("strCaptcha","");SetAspFormField("strPublicOrganisation","");
        var objCaptcha = getID("ImgCaptcha");
        if (objCaptcha) objCaptcha.src="/Mod/Comment/Captcha.aspx?SID="+UniqueID();
    }
    else
    {   
        //Display("ThanksUser");
        RefreshList();
        //setTimeout("NoDisplay('ThanksUser')",3000);
    }
}
function CloseThanks()
{
    NoDisplay("Thanks");
}
function RefreshList()
{
    NoDisplay("UserCommentList");
    Display("RefreshList");
    setTimeout("Display('UserCommentList')",1000);
    setTimeout("NoDisplay('RefreshList')",1000);    
}
function ShowPublicComments()
{
    NoDisplay("List");NoDisplay("LoginToView");
    Display("PublicList");
    ChangeClass("PublicTab","TabSelected");ChangeClass("UserTab","TabNotSelected");
}
function ShowUserComments(blnLoggedIn)
{
    if (blnLoggedIn){Display("List");}else{Display("LoginToView")};
    ChangeClass("PublicTab","TabNotSelected");ChangeClass("UserTab","TabSelected");NoDisplay("PublicList");
}
function RefreshCount(intPublicCount,intUserCount)
{
   SetInnerHtml("PublicCommentCount",intPublicCount);
   SetInnerHtml("UserCommentCount",intUserCount);
   if (intPublicCount == 0) {Display("PublicListNoComment")} else {NoDisplay("PublicListNoComment")}
   if (intUserCount == 0) {Display("ListNoComment")} else {NoDisplay("ListNoComment")}
}
var blnFlash = true;
var intFlashCount = 0;
var tmFlashCommentBox = null;
function FlashCommentTextBox()
{
    intFlashCount = 0;
    tmFlashCommentBox = setInterval("FlashBox()",500);
}
function FlashBox()
{
     var objTextBox = GetAspFormField("txtComment");
     if (objTextBox)
     {
        if(intFlashCount < 6)
        {
            blnFlash = !blnFlash        
            objTextBox.style.border="1px solid "+(blnFlash?"red":"#ccc");
            intFlashCount++;
        }     
        else
        {
            objTextBox.style.border="1px solid #ccc";
            clearInterval(tmFlashCommentBox);
        }
     }
     else
     {
        clearInterval(tmFlashCommentBox);
     }     
}
function HighLightAndJump(lngCommentID)
{
    //TimedScrollTo("CommentItem"+lngCommentID,"CommentBox",1000);
    new Effect.Highlight($('CommentItem'+lngCommentID),{speed:0.1, duration:10.0  });
}