var dialog_callback = false;
var logged_in = false;
var logged_out = false;
var selected_tab = null;
var iframe = true;

function login_redirect(urlstr, msgstr)
{	
	var message = "Please Login to Continue";
	if(msgstr) message = msgstr;

	if(!logged_in)
	{
		Login.Value = '/user/login.aspx?ReturnUrl='+urlstr+'&message='+message;
		Login.show();
	}
	else
	{
		window.location.href = urlstr;
	}
}

window.redirect = function(url)
{
	window.location.href = url;
}

function toggle_ribbon(sender,args) 
{
	
	var tab = args.get_tab().get_id();
	
	var container = document.getElementById("MenuRibbonContainer");
	var frame = frames["frame"] ? frames["frame"] : document.getElementById('frame');
	if (frame.MenuRibbonControl) var ribbon = frame.MenuRibbonControl;
	else return false;
	if (tab != "tab1" && tab != "tab5"){
		ribbon.setPageId(tab + 'Ribbon');
		if (container.className == "ribbon-collapsed") { container.className = "ribbon-expanded"; setTimeout("document.onmouseup = hide_ribbon;",10); }
		
    }
    else{
		
		hide_ribbon();
    
    }
}

function show_tab_main(sender,args){

	var tab = args.get_tab().get_id();
	if(tab == "tab2"){
		document.location = "/Programs.aspx";
	}
	else if(tab == "tab3"){
		document.location = "/card/CardGallery.aspx";
	}
	else if(tab == "tab4"){
		document.location = "/CustomerSupport.aspx";
	}
}

// Hide ribbon on document click
function hide_ribbon(e) 
{
	var container = document.getElementById("MenuRibbonContainer");
	if (container.className == "ribbon-expanded") 
	{
		
		container.className = "ribbon-collapsed";
		document.onmouseup = null;
	}
	//setTimeout("if (document.getElementById('MenuRibbonContainer').className == 'ribbon-collapsed') tabMenu.selectTabById(selected_tab);",1);
}

// Select the "Home" tab
function select_home() 
{
	if (selected_tab) 
	{
		if (selected_tab.toLowerCase() != "tab1") window.open("/","_self");
	}
	window.open("/","_self");
}

function page_load(e) 
{
    try
    {
	    var tab = tabMenu.getSelectedTab();
	    selected_tab = (tab == null) ? "tab1" : tab.get_id();
	}
	catch(e){}
	try
	{
	    prepareImageSwap(document.body);
	}
	catch(e){}
}

window.onload = page_load;

function prepareImageSwap(elem, mouseOver, mouseOutRestore, mouseDown, mouseUpRestore, mouseOut, mouseUp) 
{ 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_ro\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) 
    { 
        if (!img.rolloverSet && img.src.match(regg)) 
        { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_Over.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') 
            { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_Over.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
            } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) 
    { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
}
 
function imgHoverSwap() 
{
    this.src = this.hoverSRC;
} 

function imgOutSwap() 
{
    this.src = this.outSRC;
} 

function imgMouseDownSwap() 
{
    this.src = this.mdownSRC;
} 

function imgMouseUpSwap() 
{
    this.src = this.mupSRC;
}

function focus_input(element) 
{
	var classname = (element.className == "error") ? "error-focused" : "focused";
	element.className = classname;
}

function blur_input(element) 
{
	var classname = (element.className == "error-focused") ? "error" : "";
	element.className = classname;
}


