tipz = 1;
function hideTip(id){
    $(id).fadeOut('normal', function(){
		$(id).css('z-index','1')
	});
}

function showTip(id){
	var elementOffset = $('#' + id.replace('#', 'a')).offset();
	var contentOffset = $('#contentnav').offset();
	
	$(id).css("top", elementOffset.top - contentOffset.top + 45 + "px").css("left", elementOffset.left - contentOffset.left + 105 + "px").css('z-index',tipz);
	$(id).fadeIn('normal');
	tipz++;
}
function showHideQ(item)
{
    if($('#answer_' + item).is(':visible')){
		$('#answer_' + item).slideUp('normal');
    }
    else{
		$('#answer_' + item).slideDown('normal');
    }
}
function data_copy()
{
    document.form1.current_street1.value=document.form1.street1.value;
    document.form1.current_street2.value=document.form1.street2.value;
    document.form1.current_city.value=document.form1.city.value;
    document.form1.current_state.value=document.form1.state.value;
    document.form1.current_zipcode.value=document.form1.zipcode.value;
}

function data_copy1()
{
    document.form1.current_street1.value=document.form1.street1.value;
    document.form1.current_street2.value=document.form1.street2.value;
    document.form1.current_city.value=document.form1.city.value;
    document.form1.current_state.value=document.form1.state.value;
    document.form1.current_zipcode.value=document.form1.zipcode.value;
}

function validate() {
    var theVal = '';
    var anAlert = false;
    var fields = document.form1.getElementsByTagName('input');
    for (var i = 0; i < fields.length; i++) {
        if (fields[i].getAttribute('type') == 'text' || fields[i].getAttribute('type') == 'password') {
            var exceptions = new Array('street2', 'current_street2' )
            var anException = false;
            for (var f_i = 0; f_i < exceptions.length; f_i++) {
                if (fields[i].getAttribute('name') == exceptions[f_i]) {
                    anException = true;
                }
            }

            if(fields[i].value == '' && anException == false)
            {
                fields[i].style.borderColor = 'red';
                anAlert = true;
            }
            else
            {
                fields[i].style.borderColor = '#c0c0c0';
            }

            //USERNAME VALIDATION
            if(fields[i].getAttribute('name') == 'username')
            {
                if (fields[i].value == '') {
                    theVal += 'Please enter your requested username.<br /><br />';
                    fields[i].style.borderColor = 'red';
                }
                else
                {
                    if (!fields[i].value.match(/^[a-z][a-z0-9]{2,7}$/)) {
         //               theVal += 'Please only use 3-8 alphanumeric characters in the username field. The first character can only be a letter and the letters must be lower case.<br /><br />';
                        fields[i].style.borderColor = 'red';
                    }
                    else
                    {
                        fields[i].style.borderColor = '#c0c0c0';
                    }
                }
            }

           
            //E-MAIL VALIDATION
            if (fields[i].getAttribute('name') == 'email') {
                if (fields[i].value.value == '')
                {
                    theVal += 'Please enter an e-mail address.<br /><br />';
                    fields[i].style.borderColor = 'red';
                }
                else
                {
                    if (!fields[i].value.match(/^[0-9a-zA-Z\.\_\+-]+\@[A-Za-z0-9\.-]+$/)) {
                        theVal += 'Please enter a valid e-mail address.<br /><br />';
                        fields[i].style.borderColor = 'red';
                    }
                    else
                    {
                        fields[i].style.borderColor = '#c0c0c0';
                    }
                }
            }
        }
    }

    if(anAlert)
    {
        theVal = 'Please fill in all the required fields.<br /><br />' + theVal;
    }
    if(theVal == '')
    {
        $("#valalert").fadeOut('normal');
        document.form1.submit();
    }
    else
    {
        $("#valalert .msg").html(theVal);
        $("#valalert").fadeIn('normal');
    }
}
function validate_user(username){
    if(username!= '')
    {
        $.ajax({
            type: "POST",
            url: "validate_user.php",
            data: "username=" + username,
            success: function(msg) {
                if(msg != '')
                {
                    alert(msg);
                    document.form1.username.focus();
                }
            }
        });
    }
}
