﻿function Common_SetImage(id, file)
{
    var image = document.getElementById(id);
    image.src = "/UserAccountMaintenance/Images/" + file + ".gif";
    image.style.cursor="pointer";
}

function Common_SetImageHand(id, file)
{
    var image = document.getElementById(id);
    image.src = "/UserAccountMaintenance/Images/" + file + ".gif";
    image.style.cursor="hand";
}

function Common_ValidateOr(orIDs, lblIDs, ddlCountry)
{
    var isValid = true;
    
    // special case if US is selected: state required, region unrequired
    if(ddlCountry.options[ddlCountry.selectedIndex].value == 227)
    {
        Common_SetRequiredFieldHint(lblIDs[1], true);
        document.getElementById(orIDs[0]).removeAttribute("disabled");
        document.getElementById(orIDs[1]).value = '';
        document.getElementById(orIDs[1]).setAttribute("disabled","disabled");
        if(document.getElementById(orIDs[0])!=null && (document.getElementById(orIDs[0]).selectedIndex == 0))
        {
            Common_SetRequiredFieldHint(lblIDs[0], false);
            isValid = false;
        }
        else
        {
            Common_SetRequiredFieldHint(lblIDs[0], true);
        }
    }
    else if(ddlCountry.selectedIndex != 0) // some other country selected, so require region, not state
    {   
        Common_SetRequiredFieldHint(lblIDs[0], true);
        document.getElementById(orIDs[0]).selectedIndex=0;
        document.getElementById(orIDs[0]).setAttribute("disabled","disabled");
        document.getElementById(orIDs[1]).removeAttribute("disabled");
        if(document.getElementById(orIDs[1])!=null && (document.getElementById(orIDs[1]).value.length == 0))
        {
            Common_SetRequiredFieldHint(lblIDs[1], false);
            isValid = false;
        }
        else
            Common_SetRequiredFieldHint(lblIDs[1], true);
    }
    else // country unselected (never display region required)
    { 
        Common_SetRequiredFieldHint(lblIDs[1], true);
        document.getElementById(orIDs[0]).removeAttribute("disabled");
        document.getElementById(orIDs[1]).removeAttribute("disabled");
        if(document.getElementById(orIDs[0])!=null && (document.getElementById(orIDs[0]).selectedIndex == 0))
        {// no state selected, so require region
            if(document.getElementById(orIDs[1])!=null && (document.getElementById(orIDs[1]).value.length == 0))
            {
                Common_SetRequiredFieldHint(lblIDs[0], false);
                isValid = false;
            }
            else
                Common_SetRequiredFieldHint(lblIDs[0], true);
        }
        else
            Common_SetRequiredFieldHint(lblIDs[0], true);
    }
    
    return isValid;
}

function Common_EnableButton(button, srcName, title)
{
    var src = button.getAttribute("src");
    var index = src.indexOf("_5.gif");
    if(index > -1)
    {
        src = src.substring(0, index) + "_1.gif";
        button.setAttribute("src", src);
        Common_EnableButtonAttributes(button, srcName, title);
    }
}

function Common_DisableButton(button)
{
    var src = button.getAttribute("src");
    var index = src.indexOf("_1.gif");
    if(index > -1)
    {
        src = src.substring(0, index) + "_5.gif";
        button.setAttribute("src", src);
        Common_DisableButtonAttributes(button);
    }
}

function Common_LoadBtnDynamic(id, srcName, srcIndex)
{
    Common_SetImageHand(id, srcName + srcIndex);
}

function Common_EnableButtonAttributes(button, srcName, title)
{    
    button.onmouseover = function MouseOver(){ Common_LoadBtnDynamic(button.id, srcName, 2); };
    button.onmouseout = function MouseOut(){ Common_LoadBtnDynamic(button.id, srcName, 1); };
    
    if(Common_IsIE())
    {// ie
       button.onmousedown = function MouseDown(){ Common_LoadBtnDynamic(button.id, srcName, 3); };
       button.onmouseup = function MouseUp(){ Common_LoadBtnDynamic(button.id, srcName, 2); };
    }
    else
    {// firefox
        button.setAttribute("onmousedown", "javascript:Common_SetImageHand('" + button.id + "', '" + srcName + "3')");
        button.setAttribute("onmouseup", "javascript:Common_SetImageHand('" + button.id + "', '" + srcName + "2')");
    }
    
    button.setAttribute("title", title);
}

function Common_DisableButtonAttributes(button, index)
{
    button.onmouseover = null;
    button.onmouseout = null;
    
    if(Common_IsIE())
    {// ie
        button.onmousedown = null;
        button.onmouseup = null;
    }
    else
    {// firefox
        button.removeAttribute("onmousedown");
        button.removeAttribute("onmouseup");
    }
    
    button.removeAttribute("title");
}

function Common_DisableButtonAttributes(button)
{
    button.onmouseover = null;
    button.onmouseout = null;
    
    if(document.createEventObject)
    {// ie
        button.onmousedown = null;
        button.onmouseup = null;
    }
    else
    {// firefox
        button.removeAttribute("onmousedown");
        button.removeAttribute("onmouseup");
    }
    
    button.removeAttribute("title");
}

function Common_SetRequiredFieldHint(id, isValid)
{
    if(document.getElementById(id)!=null)
    {
        var lbl = document.getElementById(id);
        var txt;
        if(isValid)
            txt = '';
        else
            txt = '*';
        if(Common_IsIE())
            lbl.innerText = txt;
        else
            lbl.textContent = txt;
    }
}

function Common_ClearInput(id)
{
    document.getElementById(id).value = "";
}

function Common_IsIE()
{
    if (navigator.userAgent.indexOf("MSIE") != -1)
        return true;
    else
        return false;
}

function Common_IsGecko()
{
    if (navigator.userAgent.indexOf("Gecko") != -1)
        return true;
    else
        return false;
}

function Common_FirefoxKeyUpEventHandler(e)
{
	// prevent tab, alt, ctrl keys from fireing onchange
	if (e.keyCode && (e.keyCode == 1 || e.keyCode == 9 || 
	    e.keyCode == 16 || e.altKey || e.ctrlKey))
		return true;
	e.target.onchange();
	return true;
}

function Common_InitFirefoxSelectFix() 
{
	var selects = document.getElementsByTagName("SELECT");
	for(i=0; i<selects.length; i++)
		if (selects.item(i).getAttribute("size") == 1)
			selects.item(i).addEventListener("keyup", Common_FirefoxKeyUpEventHandler, false);
	return true;
}

function Common_CloseRadWindow()
{
    GetRadWindow().Close();
}

function Common_GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}

function Common_AddWhiteSpace(id)
{
    document.getElementById(id).value += " ";
}

function OpenFeedbackWindow(feedbackType, windowName)
{
    //this handles showing the window
    window.radopen("/UserAccountMaintenance/UAMWindow.aspx?_Forms=feedback&_Type=" + feedbackType, windowName);
}

function CloseRadWindow()
{
    //closes the window
    GetRadWindow().Close();
}

function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}   

function openWindow(/*what, specID, type*/feedbackType, windowName)
{  
    var divWindow = document.getElementById("divWindow");
    divWindow.style.visibility = "";
    divWindow.style.display = "";
    
    var frame = document.getElementById("divWindowFrame");
    frame.style.visibility = "";
    
    var table = document.getElementById("divWindowTable");
    table.style.visibility = "";
        
    divWindow.style.left = "120px";
    divWindow.style.top = "75px";
    
    var windowLabel = document.getElementById("MainWindowLabel");
    
    frame.src = "/UserAccountMaintenance/UAMWindow.aspx?_Forms=feedback&_Type=" + feedbackType;
    windowLabel.innerHTML = "<font face='Arial' size ='x-small'>" + windowName + "</font>";
    
    
    //CloseMenu();
}


function HideDivWindow()
{
    if (window.frameElement != null)
    {
        var frame = window.frameElement;
        frame.src = "";
        frame.style.visibility = "hidden";
        
        var divWindow = frame.parentNode.parentNode.parentNode.parentNode.parentNode;
        divWindow.style.visibility = "hidden";   
        
        var table = frame.parentNode.parentNode.parentNode.parentNode;
        table.style.visibility = "hidden";
    }
    else
    {
        var frame = document.getElementById("divWindowFrame");   
        frame.src = "";
        frame.style.visibility = "hidden";
            
        var divWindow = document.getElementById("divWindow");
        divWindow.style.visibility = "hidden"; 
        
        var table = document.getElementById("divWindowTable");
        table.style.visibility = "hidden"; 
    }
 
}

/////////////////////////////////////////////////////////////////////////////////////

//************************************************************************-->
//<!--* Generic Drag Demo                                                    *-->
//<!--*                                                                      *-->
//<!--* Copyright 2001 by Mike Hall                                          *-->
//<!--* Please see http://www.brainjar.com for terms of use.                 *-->
//<!--************************************************************************-->

// Determine browser and version.

function Browser() 
{

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 200;


function dragStart(event, id) 
{

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else 
  {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
    }
      // Get cursor position with respect to the page.

  if (browser.isIE) 
  {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  if (browser.isNS) 
  {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 300; // 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 200; //0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) 
  {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) 
  {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }

}


function dragGo(event) 
{
  var x, y;

  // Get cursor position with respect to the page.
  if (browser.isIE) 
  {
        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  if (browser.isNS) 
  {
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
  }
  
  
  // Move drag element by the same amount the cursor has moved.
  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

   if (browser.isIE) 
   {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
   }
  if (browser.isNS)
        event.preventDefault();
}
  
  
function dragStop(event) 
{
  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) 
  {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) 
  {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function SetButtonHover(what)
{
    var btn;
    switch(what)
    {
        case "Close":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_close_win_2.gif";
        break; 
        
        case "Submit":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_submit_2.gif";
        break;
    }         
}


function SetButtonRegular(what)
{
    var btn;
    switch(what)
    {
        case "Close":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_close_win_1.gif";
        break; 
        
        case "Submit":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_submit_5.gif";
        break;
        
    }   
    
    
    return;  
}

function SetButtonClick(what)
{
    var btn;
    switch(what)
    {
        case "Close":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_close_win_3.gif";
        break; 
        
        case "Submit":
        btn = document.getElementById("imgCloseWindow");  
        btn.src = "/UserAccountMaintenance/Images/btn_submit_3.gif";
        break;
    }  
}


        
    
        
       
    
