/* This function needs 3 parameters :
*  - The ID of the dropdownlist that contains alist of states
*  - The ID of the dropdownlist that contains a list of countries
*  - The ID of the DIV containing the state dropdownlist
*  
*  This function enables hides the state DropDownList if the current selected 
*  country is not "United States"
*/
function enableStates(StateDropDownName, CountryDropDownName, DivId)
{
    StateDropDown = GetElementsByName(StateDropDownName);
    CountryDropDown = GetElementsByName(CountryDropDownName);
    MyDiv = document.getElementById(DivId);

    if (MyDiv != null)
    {
	    if (CountryDropDown[0].value == 'US')
	    {		
		    MyDiv.style.visibility = 'visible';
		    MyDiv.style.display = 'block';
		    StateDropDown[0].disabled = false;
	    } 
	    else 
	    {
		    MyDiv.style.visibility = 'hidden';
		    MyDiv.style.display = 'none';
		    StateDropDown[0].disabled = true;
		    StateDropDown[0].selectedIndex = 0;
	    }
    }
}
	    
function GetElementsByName(SearchName)
{
    var MainForm = document.forms[0];
    var ResultElements = new Array();

    for(i=0; i < MainForm.elements.length; i++)
    {
	    if (MainForm.elements[i].name.indexOf(SearchName) != -1)
		    ResultElements.push(MainForm.elements[i]);
    }
    return ResultElements;
}


/*---------------------------------------------------------------*/
/*                      POPUP FUNCTIONS                          */
/*---------------------------------------------------------------*/

function SRPopupShow(PopId, DivId) {
    var obj = document.getElementById('addressEdit');
    if (obj != null)
        obj.style.display = 'none';
    
    document.getElementById(PopId).style.display = 'block' ;
    document.getElementById(DivId).style.display = 'block' ;
}

function SRPopupHide(PopId, DivId) {
    var obj = document.getElementById('addressEdit');
    if (obj != null)
        obj.style.display = 'block';
	document.getElementById(PopId).style.display = 'none' ;
	document.getElementById(DivId).style.display = 'none' ;
}

function ShowPopup (div,link, sec)
{
    var popup = new Popup(div,link,{modal:true,duration:sec, auto_open:true})
    var ie = (document.all) ? true:false
    if (ie)
        document.getElementById(link).click();
    else
        popup.show();
}

function Show (div, link, sec)
{
    document.getElementById (div).style.display='block';
    ShowPopup (div, link, sec);
}

function Hide (div)
{
   document.getElementById (div).style.display='none';
}

function getCurrentPage ()
{
    return location.href;
}    

String.prototype.trim = function()
{ return this.replace(/(^\s*)|(\s*$)/g, ""); }
