﻿// JScript File
var DELETECONFIRM = "Are you sure you want to delete the selected friends";
var DELETECONFIRMMEMBER = "Are you sure you want to delete the selected members from your network";
var DELETECONFIRMNETWORK = "Are you sure you want to delete membership from selected networks";
var ERR_DELETE_SELECT = 'No friend selected for deletion';
var ERR_DELETE_SELECT_MYNETWORK = 'No Network members selected for deletion';
var ERR_DELETE_SELECT_OTHERNETWORK = 'No network selected for deletion';


function ShowHideConfirmDeleteMessage() {
    el = document.getElementById("divDeleteConfirmMessage");
    el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
    return false;
}
function ShowHideNotSelectedMemberMessage() {
    el = document.getElementById("divNotSelectedMemberMessage");
    el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
    return false;
}
        //function to convert dd/Mon/yyyy string to mm/dd/yyyy date    added on 28 Mar 2011 by shoab
        function ConvertDateFormat(DateToConvert)
        {
            var months = { 'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12' };
            split = DateToConvert.split('/');            
            var dt = [months[split[1]], split[0], split[2]].join('/');            
            var ConvertedDate = new Date(dt);
            return ConvertedDate;
        }


function checkAll()
{
    for(i=0;i<document.getElementsByTagName("input").length;i++)
    {
        if(document.getElementsByTagName("input")[i].type == "checkbox") {
            if (!document.getElementsByTagName("input")[i].disabled)
            document.getElementsByTagName("input")[i].checked = true;                
        }
    }
}

function uncheckAll()
{
    for(i=0;i<document.getElementsByTagName("input").length;i++)
    {
        if(document.getElementsByTagName("input")[i].type == "checkbox")
        {
            document.getElementsByTagName("input")[i].checked = false;                
        }
    }
}

function confirmDelete()
{    
    var count= 0;
    for(i=0;i<document.getElementsByTagName("input").length;i++)
    {
        if(document.getElementsByTagName("input")[i].type == "checkbox")
        {
            if(document.getElementsByTagName("input")[i].checked == true)
            {
                count++;
            }
        }
    }

    if(count == 0)
    {
        alert(ERR_DELETE_SELECT);
        return false;
    }
    else
    {
        var answer = confirm(DELETECONFIRM);
        if (answer)
            return true;
        else
            return false;
    }

}

function confirmDeleteNew() {
    var count = 0;
    for (i = 0; i < document.getElementsByTagName("input").length; i++) {
        if (document.getElementsByTagName("input")[i].type == "checkbox") {
            if (document.getElementsByTagName("input")[i].checked == true) {
                count++;
            }
        }
    }

    if (count == 0) {
        ShowHideNotSelectedMemberMessage();
        return false;
    }
    else {
        ShowHideConfirmDeleteMessage();
            return false;
    }

}
function confirmDeleteNW(type) {
    var count = 0;
    for (i = 0; i < document.getElementsByTagName("input").length; i++) {
        if (document.getElementsByTagName("input")[i].type == "checkbox") {
            if (document.getElementsByTagName("input")[i].checked == true) {
                count++;
            }
        }
    }
    var ERR_DELETE;
    var CONFIRMDELETENW;
    if (type == "MYNETWORK") {
        CONFIRMDELETENW = DELETECONFIRMMEMBER;
        ERR_DELETE = ERR_DELETE_SELECT_MYNETWORK;
    }
    if (type == "OTHERNETWORK") {
        CONFIRMDELETENW = DELETECONFIRMNETWORK;
        ERR_DELETE = ERR_DELETE_SELECT_OTHERNETWORK;
    }
    else {
    }
    if (count == 0) {
        alert(ERR_DELETE);
        return false;
    }
    else {
        var answer = confirm(CONFIRMDELETENW);
        if (answer)
            return true;
        else
            return false;
    }

}

var bName = navigator.appName;
        
function taCount(taObj,maxL, Cnt) 
{ 
    objCnt=createObject(Cnt);
    objVal=taObj.value;
    if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
    if (objCnt) {
        if(bName == "Netscape"){	
	        objCnt.textContent=maxL-objVal.length;}
        else{objCnt.innerText=maxL-objVal.length;}
    }
    return true;
}
function createObject(objId) 
{
    if (document.getElementById) return document.getElementById(objId);
    else if (document.layers) return eval("document." + objId);
    else if (document.all) return eval("document.all." + objId);
    else return eval("document." + objId);
}  
function textboxMultilineMaxNumber(obj, maxLength, evt)
{
    var charCode=(evt.which) ? evt.which : event.keyCode;
  
    var max = maxLength - 0;
    var text = obj.value;
    if(text.length < max)
    {
        return true;        
    }
    else
    {
        var ignoreKeys = [8,13,16,17,18];
        for(i=0;i<ignoreKeys.length;i++)
        {
            if(charCode==ignoreKeys[i])
            {                        
                return true;                        
            }
        }
        return false;
    }
} 

function scrapMaxLength(txtId,count)
{
   fieldlimiter.setup({
    thefield: document.getElementById(txtId), 
    maxlength: 300,
    statusids: [count], 
    onkeypress:function(maxlength, curlength){}
    })       
} 
function messageMaxLength(txtId,count)
{   
   fieldlimiter.setup({
    thefield: document.getElementById(txtId), 
    maxlength: 1000,
    statusids: [count], 
    onkeypress:function(maxlength, curlength){}
    })       
} 
function smsMaxLength(txtId,count)
{
   fieldlimiter.setup({
    thefield: document.getElementById(txtId), 
    maxlength: 140,
    statusids: [count], 
    onkeypress:function(maxlength, curlength){}
    })       
}  

function emailMaxLength(txtId,count)
{
   fieldlimiter.setup({
    thefield: document.getElementById(txtId), 
    maxlength: 1000,
    statusids: [count], 
    onkeypress:function(maxlength, curlength){}
    })       
}  


var fieldlimiter={

defaultoutput: "<b>[int]</b> characters left.", //default message that gets output to statusid element

uncheckedkeycodes: /(8)|(13)|(16)|(17)|(18)/, //keycodes that are not checked, even when limit has been reached. See http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml for avail keycodes

limitinput:function(e, config){
	var e=window.event || e
	var thefield=config.thefield
	var keyunicode=e.charCode || e.keyCode
	if (!this.uncheckedkeycodes.test(keyunicode)){
		if (thefield.value.length>=config.maxlength){
			if (e.preventDefault)
				e.preventDefault()
			return false
		}
	}
},

showlimit:function(config){
	var thefield=config.thefield
	var statusids=config.statusids
	var charsleft=config.maxlength-thefield.value.length	
	
	if (charsleft<0) //if user has exceeded input limit (possible if cut and paste text into field)
		thefield.value=thefield.value.substring(0, config.maxlength) //trim input
	for (var i=0; i<statusids.length; i++){
		var statusdiv=document.getElementById(statusids[i])
		if (statusdiv) //if status DIV defined
			statusdiv.innerHTML=this.defaultoutput.replace("[int]", Math.max(0, charsleft))
	}
	config.onkeypress.call(thefield, config.maxlength, thefield.value.length)
},

cleanup:function(config){
	for (var prop in config){
		config[prop]=null
	}
},


addEvent:function(targetarr, functionref, tasktype){
	if (targetarr.length>0){
		var target=targetarr.shift()
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
		this.addEvent(targetarr, functionref, tasktype)
	}
},

setup:function(config){
	if (config.thefield){ //if form field exists
		config.onkeypress=config.onkeypress || function(){}
		config.thefield.value=config.thefield.value
		this.showlimit(config)
		this.addEvent([window], function(e){fieldlimiter.showlimit(config)}, "load")
		this.addEvent([window], function(e){fieldlimiter.cleanup(config)}, "unload")		
		this.addEvent([config.thefield], function(e){return fieldlimiter.limitinput(e, config)}, "keypress")
		this.addEvent([config.thefield], function(){fieldlimiter.showlimit(config)}, "keyup")
	}
}

}




 

