function openTFContainer(){
    Effect.BlindUp('tf-open');
    Effect.BlindDown('tellFriendContainer');
    document.forms['tellFriendForm'].sName.value = defaultsNameVal;
    document.forms['tellFriendForm'].rName.value = defaultrNameVal;
    document.forms['tellFriendForm'].rMail.value = defaultrMailVal;
    document.forms['tellFriendForm'].sName.style.border = "none";
    document.forms['tellFriendForm'].rName.style.border = "none";
    document.forms['tellFriendForm'].rMail.style.border = "none";
    //$("tf-open").style.display = "none";
    return false;
}
function closeTFContainer(){
    //$("tf-open").style.display = "block";
    //$("tellFriendContainer").style.display = "none";
    Effect.BlindDown('tf-open');
    Effect.BlindUp('tellFriendContainer'); return false;
}
function sNameEmpty(){
    if(document.forms['tellFriendForm'].sName.value == defaultsNameVal){
        document.forms['tellFriendForm'].sName.value = "";
    }
}
function rNameEmpty(){
    if(document.forms['tellFriendForm'].rName.value == defaultrNameVal){
        document.forms['tellFriendForm'].rName.value = "";
    }
}
function rMailEmpty(){
    if(document.forms['tellFriendForm'].rMail.value == defaultrMailVal){
        document.forms['tellFriendForm'].rMail.value = "";
    }
}

function sNameReset(){
    if(document.forms['tellFriendForm'].sName.value == ""){
        document.forms['tellFriendForm'].sName.value = defaultsNameVal;
    }
}
function rNameReset(){
    if(document.forms['tellFriendForm'].rName.value == "" ){
        document.forms['tellFriendForm'].rName.value = defaultrNameVal;
    }
}
function rMailReset(){
    if(document.forms['tellFriendForm'].rMail.value == ""){
        document.forms['tellFriendForm'].rMail.value = defaultrMailVal ;
    }
}

function backToDefault(){
    $("tellFriendFormDiv").style.display = "block";
    $("tellFriendBack").style.display = "none";
    $("tellFriendStatus").style.display = "none";
    document.forms['tellFriendForm'].sName.value = defaultsNameVal;
    document.forms['tellFriendForm'].rName.value = defaultrNameVal;
    document.forms['tellFriendForm'].rMail.value = defaultrMailVal;
}
function validateData(){

    if (validate_required(document.tellFriendForm.sName, defaultsNameVal)==false){
        document.tellFriendForm.sName.focus();
	return false;
    }
   if (validate_required(document.tellFriendForm.rName, defaultrNameVal)==false){
        document.tellFriendForm.rName.focus();return false;
    }

    if (validate_email(document.tellFriendForm.rMail)==false){
        document.tellFriendForm.rMail.focus();return false;
    }
    else{
        sendData();
    }
}
function validate_required(field, defaultValue){
    with (field){
    if (value==null||value==""||value==defaultValue){	
        $(id).style.border = "1px solid red"; return false;
        }
    else{
        $(id).style.border = "none"; return true;
        }
    }
}
function validate_email(field){
    with (field){
    apos=value.indexOf("@");
    dotpos=value.lastIndexOf(".");
    if (apos<1||dotpos-apos<2){
        $(id).style.border = "1px solid red"; return false;
        }
    else{
        $(id).style.border = "none"; return true;
        }
    }
}

function sendData () {
    var url = "typo3conf/ext/merea_tellafriend/pi1/process.php";
    var pars = Form.serialize("tellFriendForm");
    var myAjax = new Ajax.Request( url, {method: "get", parameters: pars,onComplete: showResponse} );
}

function showResponse (originalRequest) {
    $("tellFriendFormDiv").style.display = "none";
    $("tellFriendBack").style.display = "block";
    $("tellFriendStatus").style.display = "block";
    var newData = originalRequest.responseText;
    $("tellFriendStatus").innerHTML = newData;
}
