﻿//// SpamNotification- Author: Vakas
var choiceDialogRef;
var SpamNotification = Class.create({   initialize: 
    function() { 
        this.SpamNotificationExpertID = 'this//';
        this.SpamNotificationVisitorID = '';            
        this.SpamNotificationUserID = '';            
        this.SpamNotificationMessage = '';
        this.checkForSpamNotificationInterval = 30000;      
        
    } 
 }); 
 
 
// SpamNotification.addMethods({   setSpamNotificationMessage : function(notMsg) {
//    this.SpamNotificationMessage = notMsg;
//}
//});

//SpamNotification.addMethods({   getSpamNotification : function() {
//    alert(this.SpamNotificationMessage);
//}
//});

 SpamNotification.addMethods({ fetchSpamNotifications: function () {
     var height = 170;
     //var visitorID = this.SpamNotificationVisitorID;
     var url = baseURL + '/AjaxHandlers/SpamNotification.ashx';
     var params = 'action=cql';
     new Ajax.Request(url, {
         method: 'post', postBody: params, onSuccess: function (transport) {
             var p = transport.responseJSON;
             // document.getElementById("testresp").innerHTML += p.Html;
             var updatedIds = new Array();
             updatedIds = p.UpdatedIDs;
             if (p.Html != '' && p.Html != null) {
                 if (p.IsSubscribed == 'True') {
                     height = 380;
                 }
                 document.getElementById('HiddenFieldResponderContent').value = p.Html;
                 if (document.getElementById('HiddenFieldResponderContent').value != null && document.getElementById('HiddenFieldResponderContent').value != '') {
                     titlebarTextAlert();
                     tb_show('Message Received!', baseURL + '/responddialog.aspx?UpdatedIds=' + updatedIds + '&KeepThis=true&modal=true&height=' + height + '&width=835');
                 }
             }
             else {
                 // closeChoiceDialog();
             }

         }
     });
 }
 });

function openChoiceDialog(title, text, updatedIDs) {
    choiceDialogRef = new RespondDialog({
	handle:'#dialogChoice',
	title:title,
	//content: "<div class='block-brbg-orange' style='padding:10px'>" + text + "</div>",
	content:text, // "<div class='successbar' id='FormMessageBar'><div class='right'><span style=\'color:#000000;font-size:12px\'>" + text + "</span></div></div>",	
  updatedIDs:updatedIDs,
	width:980,
	height: 'auto',
	close:{
		link:true,
		overlay: true,
		updatedIDs: 20,
		esc:true
	},
	padding:0,
	margin:50
});

choiceDialogRef.open();
/* No sound still
//also play a sound alert
if(mySound)
    mySound.play();
    */

//also blink tab
    titlebarTextAlert();    
}


function closeChoiceDialog() {
    // alert(updatedIDs);
    choiceDialogRef = new RespondDialog({
        handle: '#dialogChoice',
       // title: title,
       // content: "<div class='block-brbg-orange' style='padding:10px'>" + text + "</div>",
        updatedIDs: 0,
        width: 980,
        height: 100,
        close: {
            link: true,
            overlay: true,
            updatedIDs: 20,
            esc: true
        },
        padding: 0,
        margin: 50
    });
    choiceDialogRef.close();
//    //also play a sound alert
//    if (mySound)
//        mySound.play();

//    //also blink tab
//    titlebarTextAlert();
}

/*
function populateNotDisturbHoursAndMinutes(){    
    var objSpanHr = document.getElementById("spanHr");    
    if(objSpanHr == null){        
        setTimeout("populateNotDisturbHoursAndMinutes();",1000);
        return;
    }    
    var objSpanMin = document.getElementById("spanMin");
    var selectHrStr = "<select id=\"NDHr\" name=\"NDHr\">";
    for(var i=0;i<24;i++){
        selectHrStr += "<option value=\""+i+"\">"+i+" hour</option>";
    }
    selectHrStr+="</select>";
    objSpanHr.innerHTML = selectHrStr;
    
    var selectMinStr = "<select id=\"NDMin\" name=\"NDMin\">";
    for(var i=0;i<59;i++){
        selectMinStr += "<option value=\""+i+"\">"+i+" minute</option>";
    }
    selectMinStr+="</select>";
    objSpanMin.innerHTML = selectMinStr;
    
 }
 */
 /*
 function postUserDisturbSettings(){
    var objHour = document.getElementById("NDHr");
    var objMin = document.getElementById("NDMin");
    if(objHour.value == 0 && objMin.value == 0){
        alert("Both hours and minutes do not have the 0 value.");
        return false;
    }
    
    var url = baseURL + '/ajaxHandler.ashx'; 
    var date = new Date();
    var timeStamp = date.getYear() + '' + date.getMonth() + '' + date.getDay() + '' + date.getHours() + '' + date.getMinutes() + '' + date.getSeconds() + date.getMilliseconds();
    var params = 'action=dndsetting&ts='+timeStamp+'&hr='+objHour.value+"&min="+objMin.value;
    new Ajax.Request(url, {  
         method: 'post', postBody: params,   onSuccess: function(transport) {     
            alert("Your setting "+objHour.value+" hour and "+objMin.value+" minute has been saved.");
            } });
           
    
    
    if(choiceDialogRef != null)
        choiceDialogRef.close();
 }
  */ 
/*

function ignoreQuestion(parentDiv,questionId,questionLink, userType, userOrVisitorID){
    var url = baseURL + '/ajaxHandler.ashx'; 
    var params = 'qid='+questionId+'&uorvid='+userOrVisitorID+'&utype='+userType+'&action=addSpamNotification&response=ignore';
    new Ajax.Request(url, {  
         method: 'post', postBody: params,   onSuccess: function(transport) { 
            
            } });
            
            //End    

    var parDiv = document.getElementById(parentDiv);
    parDiv.innerHTML="";//Remove
    var span = document.createElement("span");
    span.id="rejChat"+questionId+userOrVisitorID+userType;
    span.innerHTML = "User is notified that you are unavailable for chat.";
    span.style.display="block";
    span.style.float="none";
    parDiv.appendChild(span);
    
    var divClear= document.createElement("div");
    divClear.style.clear= "both";
    parDiv.appendChild(divClear);
}
*/
/*
function joinChat(parentDiv,questionId,questionLink, userType, userOrVisitorID){    
    var url = baseURL + '/ajaxHandler.ashx'; 
    var params = 'qid='+questionId+'&uorvid='+userOrVisitorID+'&utype='+userType+'&action=addSpamNotification&response=join';
    
    new Ajax.Request(url, {  
         method: 'post', postBody: params,   onSuccess: function(transport) { 
            //alert(transport.responseText);
            var parDiv = document.getElementById(parentDiv);
            parDiv.innerHTML="";
            
            var span = document.createElement("span");
            span.id="accChat"+questionId+userOrVisitorID+userType;
            span.innerHTML = "User has been notified. You can now chat on a newly opened window.";
            span.style.display="block";
            span.style.float="none";
            parDiv.appendChild(span);
            
            var divClear= document.createElement("div");
            divClear.style.clear= "both";
            parDiv.appendChild(divClear);
      } });
            
            //End    

    
    
    
    window.open(questionLink+"-livechat#StartChat");

    
}
*/

//Title alerter
var titleSwitchCount = 0;
var titleSwitchLimit = 5;
var titleOriginalText = document.title;
var titleText = "You have a new alert!";
var titleDelay = 800;

function titlebarTextAlert() {
// Failsafe
if( titleSwitchCount) return;

titlebarSwitch();
}

function titlebarSwitch() {

if( document.title == titleOriginalText) {
// New message text
document.title = titleText;
titleSwitchCount++;

} else {
// Original text
document.title = titleOriginalText;
if( titleSwitchCount == titleSwitchLimit) titleSwitchCount = 0;
}

// If count is 0 then we must have just reset it
if( titleSwitchCount) setTimeout( "titlebarSwitch();", titleDelay);
}

