﻿function itemShow(item){
    theImage = document.getElementById('img' + item);
    
    if($('#' + item).is(':visible')){
        $('#' + item).slideUp('fast');
        if (theImage != null)
        {
            theImage.src = 'img/down.gif';
        }   
    }
    else{
        $('#' + item).slideDown('fast');
        if (theImage != null)
        {
            theImage.src = 'img/up.gif';
        }
    }
}

function inputFocus(inp, num){
    if (num == 1){
        if(inp.value == "Your name here"){
            inputClear(inp);
        }
    }
    else if (num == 2){
        if(inp.value == "Your e-mail here"){
            inputClear(inp);
        }
    }
    else if (num == 3){
        if(inp.value == "Your message here"){
            inputClear(inp);
        }
    }
}
function inputBlur(inp, num){
    if (num == 1){
        if(inp.value == ""){
            inputUnClear(inp, "Your name here");
        }
    }
    else if (num == 2){
        if(inp.value == ""){
            inputUnClear(inp, "Your e-mail here");
        }
    }
    else if (num == 3){
        if(inp.value == ""){
            inputUnClear(inp, "Your message here");
        }
    }
}
function inputClear(inp){
    $(inp).val('');
    $(inp).css('color', '#000000');
}
function inputUnClear(inp, value){
    $(inp).val(value);
    $(inp).css('color', 'gray');
}

function staffMessage(id)
{
    if($('#divMsgBox' + id).is(':visible')){
        $('#divMsgBox' + id).slideUp('fast');
    }
    else{
        $('#divMsgBox' + id).slideDown('fast');
    }
}


//E-MAIL VALIDATION
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	 return true					
}
function validEmail(emailID){	
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email");
        emailID.focus();
        return false
    }
    if (echeck(emailID.value)==false){
        alert("Invalid E-Mail Address");
        emailID.focus();        
        return false;
    }
    return true
}

function sendAboutMessage(id)
{
    if(validEmail(document.getElementById('txtEmail' + id))){
        var theurl = 'emailstaff.aspx';

        $.ajax({
            type: "POST",
            url: theurl,
            data: "id=" + id + "&email=" + $('#txtEmail' + id).val() + "&name=" + $('#txtName' + id).val() + "&msg=" + $('#txtMessage' + id).val(),
            success: function(data) {
                emailResponse(data, id);
            }
        });
        
    }
}
function emailResponse(data, id)
{
    alert(data);    
    staffMessage(id);
}