/***************************************************************************
 *       ___ _   _                    ____           _       _
 *      |  _| | | |_ __  _ _  ___    / ___|  ___ _ _(_)_ __ | |_
 *      | |_| |_| | '_ \| '_)/ _ \   \___ \ / __| '_) | '_ \| __| 
 *      |  _|  _  | |_) | | | (_) |   ___) | (__| | | | |_) | |_ 
 *      |_| |_| |_| .__/|_|  \___/   |____/ \___|_| |_| .__/ \__|
 *                |_|  www.fhpro.de                   |_|
 *
 *   Copyright            : (c) 2006 Frank Hinkel
 *   Kontakt              : info@fhpro.de
 *
 ***************************************************************************/

FhproWeb2Ajax.prototype.CallBackEmpfehlung = function()
{ 
    try 
    {
    	eval(this.request.responseText);
    	 
	    // Bei Fehler abbrechen
	    if (cbObj[1].Content == '-1')
	    {
            var msg = '';
            msg += '<div style="margin:10px;" align="center">';        
            msg += '<b>Empfehlung wurde gesendet.</b>';            
            msg += '</div>';	        
        	CLempfehlung.showMsgBox(msg, true);
    	}    
    	else
    	{
    	   CLempfehlung.writeError(cbObj[1].Content);   
    	}
    }
    catch (e) 
    {
    	alert("Konnte Empfehlung nicht senden."); 
		return;
    }    
}

/*** EMPFEHLUNG ***/
function FhproEmpfehlung() {
    this._boxVisible;
    this._videoId;    
}
FhproEmpfehlung.prototype = {  
    initialize: function() 
    {
        this._videoId = 1172;
        this._boxVisible = false;
        
        var objpreBox = CLweb2.getElem('EmpfehlungsBox');                        
		var objAlpha  = document.createElement("div");
		objAlpha.setAttribute('id','EmpfehlungsBoxAlpha');		
		objAlpha.style.display = 'none';
		objAlpha.style.zIndex = 10;
		objpreBox.appendChild(objAlpha);   

		var objClip = document.createElement("div");
		objClip.setAttribute('id','EmpfehlungsBoxClip');  
		objClip.style.display = 'none';
		objClip.style.zIndex = 20;
		objpreBox.appendChild(objClip);					
    },
    switchEmpfehlung: function()
    {
        if (this._boxVisible)
            this.hideMsgBox();
        else
            this.showEmpfehlung();   
    },
    showEmpfehlung: function()
    {
        this._boxVisible = true;
        
        var msg = '';
        msg += '<form name="SendFormEmpfehlung">';        
        msg += '<div style="margin:10px;">';
        msg += '<b>Video weiterempfehlen</b><br/>';
        msg += '<span style="color:#dc0000"><div id="EmpfehlungStatus">&nbsp;</div></span>';
        msg += '<div>';
        msg += 'Empfänger E-Mail-Adresse<br/>';
        msg += '<input type="text" class="text" style="width:218px;" maxlength="200" name="EmpfehlungEmail" size="20" value=""><br/>';
        msg += 'Empfänger Name<br/>';
        msg += '<input type="text" class="text" style="width:218px;" maxlength="200" name="EmpfehlungName" size="20" value=""><br/>';
        msg += 'Dein Kommentar<br/>';
        msg += '<textarea name="EmpfehlungBesch" rows="3" cols="30" wrap="virtual" class="text" style="width:218px;height:50px;"></textarea>';               
        msg += '<table style="padding-top:4px" border="0" cellspacing="0" cellpadding="0">';
        msg += '<tr>';
        msg += '<td><input type="button" class="button stop" onclick="CLempfehlung.hideMsgBox();" style="width:90px" value="Abbrechen" /></td>';
        msg += '<td width="131" align="right"><input type="button" class="button r" onclick="CLempfehlung.submitForm();" style="width:90px" value="Senden" /></td>';
        msg += '</tr>';
        msg += '</table>';
        msg += '</div>';
        msg += '</div></form>';                
        this.showMsgBox(msg, false);  
    },
    hideMsgBox: function()
    {        
        this._boxVisible = false;
        CLweb2.getElem('EmpfehlungsBoxAlpha').style.display = 'none';
        CLweb2.getElem('EmpfehlungsBoxClip').style.display = 'none';
    },
    showMsgBox: function(msg, closeButton)
    {
        //this.setPosition();
        
        if (closeButton)
            msg += '<div style="text-align:center;margin-top:10px"><img src="/templates/default/images/gif/schliessen.gif" width="68" height="16" style="cursor:pointer" onclick="CLempfehlung.hideMsgBox();" /></div>';
        
        var el = CLweb2.getElem('EmpfehlungsBoxClip');
        el.innerHTML = msg;
        
        CLweb2.getElem('EmpfehlungsBoxAlpha').style.display = 'block';
        CLweb2.getElem('EmpfehlungsBoxClip').style.display = 'block';        
    },
    setPosition: function()
    {
		if (!window.event)
		    // FF
			topHeight = document.body.scrollTop ? document.body.scrollTop : window.pageYOffset;
		else
		    // IE
            topHeight = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;

        CLweb2.getElem('EmpfehlungsBoxAlpha').style.top = topHeight + 'px';
        CLweb2.getElem('EmpfehlungsBoxClip').style.top = topHeight + 'px'; 		
    },
    writeError: function(msg)
    {
        var elem = CLweb2.getElem('EmpfehlungStatus');   
        elem.innerHTML = msg;
    },
    isEmail: function(elm) 
    {
        if (elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1")
            return true;
        else
            return false;
    },    
	submitForm: function()
	{
        if (this._videoId < 1 || this._videoId == undefined)
        {
            this.writeError("Video wurde nicht gefunden.");
            return;
        }	    
        var elem = CLweb2.getElem('EmpfehlungEmail');                
        if (!this.isEmail(elem))
        {
            this.writeError("Bitte gib eine E-Mail-Adresse ein.");
            return;
        }   
        elem = CLweb2.getElem('EmpfehlungName');                
        if (elem.value.length < 1)
        {
            this.writeError("Bitte gib einen Namen ein.");
            return;
        }        
        elem = CLweb2.getElem('EmpfehlungBesch');                
        if (elem.value.length < 1)
        {
            this.writeError("Bitte gib einen Kommentar ein.");
            return;
        }        
        
        var writeCommentsObj = new FhproWeb2Ajax();
	    writeCommentsObj.debug = false;
	    writeCommentsObj.Request('CallBackEmpfehlung','post','/ajax/362','SendFormEmpfehlung','do=empfehlung&subdo=sendEmpfehlung&videoId=' + this._videoId);	    	    	    
	}    
}
var CLempfehlung = new FhproEmpfehlung();
//CLweb2.setOnLoad("CLempfehlung.initialize();"); 
