// Define Browse Vars
var ie       = (navigator.appVersion.indexOf('MSIE')    != -1)                    ? true : false;
var ns       = ((typeof(document.all) == 'undefined') && document.getElementById) ? true : false;
var ie5      = (navigator.appVersion.indexOf('MSIE 5.') != -1)                    ? true : false;
var aboveIE5 = (!ie5 && !ns)                                                      ? true : false;

function checkMail(m_oFrm)
{
	var m_sEmailAddress = m_oFrm.Email.value;
	var m_oRegEx = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	var m_bIsValid = m_oRegEx.test(m_sEmailAddress);
	
	if(!m_bIsValid)
	{
		alert("Sorry bud. Invalid email. Please try again.");
		m_oFrm.Email.value = "";
		m_oFrm.Email.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function validateMail(m_sEmailAddress)
{
	var m_oRegEx = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	var m_bIsValid = m_oRegEx.test(m_sEmailAddress);

	return m_bIsValid;
}

function checkMobileNumber(m_sMobileNumber)
{
	var m_oRegEx = /^[0-9]{7,30}$/;
	var m_bIsValid = m_oRegEx.test(m_sMobileNumber);
	
	return m_bIsValid;
}

function clearForm(m_oFrm)
{
	m_oFrm.reset();
}

function checkThis(m_oElement)
{
	if(m_oElement.checked)
	{
		m_oElement.checked = false;
	}
	else
	{
		m_oElement.checked = true;	
	}
	return false;	
}

function openWindow(e, url, width, height, attrs, optional_name)
{
    ah = screen.availHeight - 30;
    aw = screen.availWidth - 10;

    xc = (aw - width) / 2;
    yc = (ah - height) / 2;

    //Make up a window name based on the URL.
    window_name = optional_name ? optional_name : url.replace(/[^a-z]*/gi,'');

    if (ie) {
        //Status=yes is forced for SP2 compatibility.
        attrs += ',status=yes,location=no';
    }

    //Status=yes is forced for SP2 compatibility.
    w = window.open(url, window_name, 'width='+width+',height='+height+',left='+xc+',top='+yc+','+attrs);

    //Test that it worked!
    if(!w)
	{
        alert(blocked_popup_msg);
    }
	else
	{
        w.focus();
    }
    return w;
}

function switchState(id)
{
	content = ''; //Nullify the content variable

	if( text[id] != 1 ) //Check if text['id'] is set to 1 (explained later)
	{
	     content = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
	     new_html = '<input type="text" id="child' + id + '" value="' + content + '" />'; //Define the new HTML (textbox)
	     document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
	     text[id] = 1; //We set this variable for the script to remember that we already set it to a text box
	}
	else
	{
	    //So with this case we will be doing the opposite and switching back to a div
	    content = document.getElementById('child' + id).value; //Define content as the value of the textbox
	    new_html = '<div id="child' + id + '">' + content + '</div>'; //Define the new HTML (div)
	    document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
	    text[id] = 0; //We set this variable for the script to remember that we have set it back to a div
	}
}

function highSelect(m_oFrm)
{
	if(m_oFrm.value == "")
	{
		m_oFrm.focus();
	}
	else
	{
		m_oFrm.select();
	}
}

function checkMail(m_sEmail)
{
	var m_oRegEx = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	var m_bIsValid = m_oRegEx.test(m_sEmail);

	return m_bIsValid;
}
