function PopupWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu)
{
	if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
	popupWin=window.open(aUrl,"PopupWin","scrollbars="+sb+",resizable="+rs+",toolbar="+tb+",directories="+dir+",status="+st+",menubar="+mnu+",width="+w+",height="+h+",resizable=yes");
	popupWin.self.focus();
}

function PopupNamedWindow(aName, aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, aName, "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupUniqueWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin" + (new Date()).getTime(), "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function Roll(img_name, img_src)
{
   document.getElementById(img_name).src = img_src;
}

function SetText(lbl, txt)
{
   document.getElementById(lbl).innerHTML = txt;
}

function RollSetText(img_name, img_src, lbl, txt)
{
	Roll(img_name, img_src);
	SetText(lbl, txt);
}

function CountLeft(field, count, max) {
    var len = $(field).val().length;
    $(count).val(len);
    if (len > max) $(count).attr('class', 'warning');
    else $(count).attr('class', '');
}

/* Browser independent position locator */
function findPosX(obj) {
var curleft = 0;
if (obj.offsetParent) {
	while (obj.offsetParent) {
		curleft += obj.offsetLeft
		obj = obj.offsetParent;
	}
} else if (obj.x) {
	curleft += obj.x;
}
return curleft;
}
		
function findPosY(obj) {
var curtop = 0;
if (obj.offsetParent) {
	while (obj.offsetParent) {
		curtop += obj.offsetTop
		obj = obj.offsetParent;
	}
} else if (obj.y) {
	curtop += obj.y;
}
return curtop;
}
		
function findWidth(obj) {
var width = 0;
if (obj.offsetWidth) {
	width = obj.offsetWidth;
} else if (document.defaultView) {
	width = document.defaultView.getComputedStyle(obj, "").getPropertyValue("width");
}
return width;
}

function findHeight(obj) {
var height = 0;
if (obj.offsetHeight) {
	height = obj.offsetHeight;
} else if (document.defaultView) {
	height = document.defaultView.getComputedStyle(obj, "").getPropertyValue("height");
}
return height;
}		
/* End cross-browser code */

function ShowToolLayer(ctrlid, ctrllocid, imgid, xadj, yadj, txt)
{
	var ctrl = document.getElementById(ctrlid);
	var ctrlloc = document.getElementById(ctrllocid);
    var img = document.getElementById(imgid);
    ctrl.innerHTML = txt;
    ctrl.style.display = "inline";
	ctrl.style.left = findPosX(ctrlloc) + xadj;
    ctrl.style.top = findPosY(ctrlloc) + yadj; 
    ctrl.style.visibility = "visible";    
}

function HideLayer(ctrlid) 
{ 
	var ctrl = document.getElementById(ctrlid);
	ctrl.style.visibility = "hidden";
	ctrl.style.display = "none"; 
}

function LogClick(stattype, prefixurl) {
    if (document.images) {
        var curDT = new Date();
        var curHr = curDT.getHours();
        var curMin = curDT.getMinutes();
        var curSec = curDT.getSeconds();

        if (prefixurl == null) prefixurl = "";

        (new Image).src = prefixurl + "LogStat.aspx?stattype=" + stattype + "&companyid=na" +
			"&" + curHr + curMin + curSec;
    }
    return true;
}

function StatCompany(companyid, stattype, prefixurl) {
	if (document.images)
	{
	    var curDT = new Date();
	    var curHr = curDT.getHours();
	    var curMin = curDT.getMinutes();
	    var curSec = curDT.getSeconds();
	    
	    if (prefixurl == null) prefixurl = "";
	    
		(new Image).src = prefixurl+"LogStat.aspx?stattype="+stattype+"&companyid="+companyid+
			"&"+curHr+curMin+curSec;
	}
	return true;
}

function BannerAdStat(companyid, stattype, token, prefixurl) {
    if (document.images) {
        var curDT = new Date();
        var curHr = curDT.getHours();
        var curMin = curDT.getMinutes();
        var curSec = curDT.getSeconds();

        if (prefixurl == null) prefixurl = "";

        (new Image).src = prefixurl + "LogStat.aspx?stattype=" + stattype + "&companyid=" + companyid +
			"&" + curHr + curMin + curSec + "&token="+token;
    }
    return true;
}

function SetMyToolTab(tab, prefixurl)
{
	if (document.images)
	{
	    var curDT = new Date();
	    var curHr = curDT.getHours();
	    var curMin = curDT.getMinutes();
	    var curSec = curDT.getSeconds();
	    
	    if (prefixurl == null) prefixurl = "";
	    
		(new Image).src = prefixurl+"SetMyToolTab.aspx?tab="+tab+"&"+curHr+curMin+curSec;
	}
	return true;
}

function HideShowControl(ctrlid)
{
	var ctrl = document.getElementById(ctrlid);
	if (ctrl.style.display == "none")
	{
	    ctrl.style.display = "";
	}
	else
	{
		ctrl.style.display = "none";
	}
}

function HideControl()
{
	var ctrl;
	
	for (i=0; i<arguments.length; i++)
	{
		ctrl = document.getElementById(arguments[i]);
		if (ctrl.style.display != "none")
		{
			ctrl.style.display = "none";
		}
	}
}

function ShowControl()
{
	var ctrl;
	
	for (i=0; i<arguments.length; i++)
	{
		ctrl = document.getElementById(arguments[i]);
		
		if (ctrl.style.display == "none")
		{
			ctrl.style.display = "";
		}
	}
}
function HideShowControlAndArrows(ctrlid, expand, collapse, description)
{
	var ctrl = document.getElementById(ctrlid);
	var aexpand = document.getElementById(expand);
	var acollapse = document.getElementById(collapse);
	var adescription = document.getElementById(description);
	if (ctrl.style.display == "none")
	{
	    ctrl.style.display = "";
	    
	    aexpand.style.display = ""
	    acollapse.style.display = "none";
	    adescription.style.display = "none";
	}
	else
	{
		ctrl.style.display = "none";
		aexpand.style.display = "none"
	    acollapse.style.display = "";
	    adescription.style.display = "";
	}
}



function SetSelectedText(listctrl, textctrl, defaulttext)
{
	var list = document.getElementById(listctrl);
	var textctrl = document.getElementById(textctrl);
	var textval = '';
	
	for (var i = 0; i < list.length; i++)
		if (list.options[i].selected)
		{
			if (textval != '') textval = textval + ', ';
			textval = textval + list.options[i].text;
		}
		
	if (textval != '') textval = '('+textval+')';
	else textval = defaulttext;
	
	textctrl.innerHTML = textval;
}

function SetSelectedCheckText(listctrl, textctrl, defaulttext, count)
{
    var check;
    var table;
    var labels;
	var textctrl = document.getElementById(textctrl);
	var textval = '';
	
	for (var i = 0; i < count; i++)
	{
	    table = document.getElementById(listctrl);
		check = document.getElementById(listctrl+'_'+i);
			
		if (check && check.checked)
		{
			if (textval != '') textval = textval + ', ';
			labels = table.getElementsByTagName('label');
			
			for (var c = 0; c < labels.length; c++)
				if (labels[c].attributes['for'].value == listctrl+'_'+i)
					textval = textval + labels[c].innerHTML;
		}
	}
		
	if (textval != '') textval = '('+textval+')';
	else textval = defaulttext;
	
	textctrl.innerHTML = textval;
}

function IsChecked(checkctrl)
{
    var checkbox = document.getElementById(checkctrl);
    
    if (checkbox) return checkbox.checked;
    else return false;
}

function ToggleCtrlOnCheckbox(checkctrl)
{
	if (IsChecked(checkctrl)) 
		for (i=1; i<arguments.length; i++)
		{
			ctrl = document.getElementById(arguments[i]);
		
			if (ctrl.style.display == "none")
				ctrl.style.display = "";
		}
	else 
		for (i=1; i<arguments.length; i++)
		{
			ctrl = document.getElementById(arguments[i]);
			if (ctrl.style.display != "none")
				ctrl.style.display = "none";
		}
}
function HideShowControlPersistent(ctrlid, expand, collapse) {
    var ctrl = "#" + ctrlid;
    var flagValue = "false";

    if ($(ctrl).hasClass("form_row_hidden") == true) { // If Collapsed 
        $(".mtexpand").removeClass("form_row_hidden"); //show expand classes
        $(".mtcollapse").addClass("form_row_hidden"); //hide collapse classes
        flagValue = "true";
    }
    else { //If NOT Collapsed
        $(".mtexpand").addClass("form_row_hidden"); //hide expand classes
        $(".mtcollapse").removeClass("form_row_hidden"); //show collapse classes
        flagValue = "false";
    }

    $.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        url: (applicationUrl + "/Services/AJAX.asmx/SetFlag"),
        data: "{ 'flagType': 'MyTools', 'flagId': 'Show', 'flagValue': '"+flagValue+"' }",
        success: function (msg) {
        }
    });
}

var applicationUrl = "";

function initializeJQueryCode() {
    $(".autocomplete").autocomplete({
        source: function (request, response) {
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                url: (applicationUrl + "/Services/Lookup.asmx/GetLookupResults"),
                data: "{ 'lookupTable': '" + this.element.attr("LookupTable") + "', 'lookupField': '" + this.element.attr("LookupField") +
                    "', 'term': '" + request.term + "' }",
                success: function (data, XMLHttpRequest, textStatus) {
                    response($.map(data.d, function (item) {
                        return {
                            value: item.Result
                        }
                    }))
                }
            });
        },
        minLength: 1
    });

    $(".autocomplete").keypress(function (event) {
        if (event.keyCode == '13') return;
        if (event.keyCode == '9') return;
    });


    $("#tS2").thumbnailScroller({
        scrollerType: "clickButtons",
        scrollerOrientation: "horizontal",
        scrollSpeed: 2,
        scrollEasing: "easeOutCirc",
        scrollEasingAmount: 600,
        acceleration: 4,
        scrollSpeed: 800,
        noScrollCenterSpace: 10,
        autoScrolling: 0,
        autoScrollingSpeed: 2000,
        autoScrollingEasing: "easeInOutQuad",
        autoScrollingDelay: 500
    });

    $("a[rel='colorbox_weather']").colorbox({
        transition: "none",
        iframe: true,
        width: "600",
        height: "600"
    });

    $("a[rel='colorbox_contact']").colorbox({
        transition: "none",
        iframe: true,
        width: "650",
        height: "700"
    });

    $("a[rel='colorbox_special_offer']").colorbox({
        transition: "none",
        iframe: true,
        innerWidth: "500",
        innerHeight: "350"
    });

    $("a[rel='colorbox_video']").colorbox({
        transition: "none",
        iframe: true,
        innerWidth: "560",
        innerHeight: "349"
    });

    $("a[rel='colorbox_profile_video']").colorbox({
        transition: "none",
        iframe: true,
        innerWidth: "560",
        innerHeight: "349",
        rel: 'nofollow'
    });

    $("a[rel='colorbox_photo']").colorbox({
        transition: "none",
        iframe: true,
        innerWidth: "700",
        innerHeight: "660",
        rel: 'nofollow'
    });

    $("a[rel='colorbox_update']").colorbox({
        transition: "none",
        iframe: true,
        innerWidth: "750",
        innerHeight: "700",
        current: "meetingpages Update {current} of {total}"
    });

    $("a[rel='colorbox_profile_photo']").colorbox({
        transition: "none",
        maxWidth: "600",
        maxHeight: "600"
    });

    $('.hoverbox').hoverbox();


    $('span.grouped_results > :checkbox').click(function () {
        var companyId = $(this).parent().attr('CompanyId');
        if ($(this).is(':checked')) {
            $('span.grouped_results[CompanyId=' + companyId + '] > input:checkbox').not(this).attr('checked', 'checked');
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                url: (applicationUrl + "/Services/AJAX.asmx/SetFlag"),
                data: "{ 'flagType': 'Company.Select', 'flagId': '" + companyId +
                    "', 'flagValue': 'true' }",
                success: function (msg) {
                }
            });
        }
        else {
            $('span.grouped_results[CompanyId=' + companyId + '] > input:checkbox').not(this).removeAttr('checked');
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                url: (applicationUrl + "/Services/AJAX.asmx/SetFlag"),
                data: "{ 'flagType': 'Company.Select', 'flagId': '" + companyId +
                    "', 'flagValue': 'false' }",
                success: function (msg) {
                }
            });
        }
    });

    $('.banner_ad_cycle').cycle({
        fx: 'fade',
        timeout: 7000,
        after: onBannerAdRecordStat
    });

    $(function () { $('.banner_ad_cycle > div[companyid]:first-child').each(onBannerAdRecordStat); });
}

$(document).ready(function () { 
    initializeJQueryCode();
});

function onBannerAdRecordStat() {
    try
    {
        var companyid = $(this).attr("companyid");
        var stattype = $(this).attr("stattype");
        var token = $(this).attr("stattoken");

        if (document.images) {
            var curDT = new Date();
            var curHr = curDT.getHours();
            var curMin = curDT.getMinutes();
            var curSec = curDT.getSeconds();

            (new Image).src = applicationUrl + "/LogStat.ashx?stattype=" + stattype + "&companyid=" + companyid +
			    "&" + curHr + curMin + curSec + "&token="+token;
        }
    }
    catch (e) {alert(e); }
    return true;
}

function get_cookies_array() {

    var cookies = {};

    if (document.cookie && document.cookie != '') {
        var split = document.cookie.split(';');
        for (var i = 0; i < split.length; i++) {
            var name_value = split[i].split("=");
            name_value[0] = name_value[0].replace(/^ /, '');
            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
        }
    }

    return cookies;

}
