String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
};
YAHOO.namespace("mastop");
YAHOO.mastop.ShareVideo = function(){
    var yud = YAHOO.util.Dom;
    var yue = YAHOO.util.Event;
    var yuc = YAHOO.util.Connect;
    var dialog = YAHOO.My.UI.Dialog;
    var oResult = false;
    var theForm = '\
    	<div id="at16pib">\
    		<div id="at16pi">\
    			<div style="background-color: rgb(0, 0, 0);" id="at16pt">\
    				<h4 style="color: #1C9CFF;" id="at16ptc">Enviar e-mail para amigo</h4>\
    			</div>\
    			<div id="at16pc">\
    				<div style="" id="at_email">\
    					<div class="tmsg" id="at_head">\
    						Vários endereços? Use vírgulas.\
    					</div>\
    					<form onsubmit="YAHOO.mastop.ShareVideo.ShareVideoSend(this); return false;" id="ShareVideoForm">\
    						<label for="at_para">Para:</label>\
    						<input type="text" onblur="if(this.value == \'\')this.value=\'endereco de e-mail\'" onfocus="if(this.value == \'endereco de e-mail\')this.value=\'\'" size="30" value="endereco de e-mail" tabindex="2" name="at_para" id="at_para" class=""/>\
    						<br clear="all"/>\
    						<label for="at_nome">Nome:</label>\
    						<input type="text" onblur="if(this.value == \'\')this.value=\'digite seu nome\'" onfocus="if(this.value == \'digite seu nome\')this.value=\'\'" size="30" value="digite seu nome" tabindex="3" name="at_nome" id="at_nome" class=""/>\
    						<br clear="all"/>\
    						<label for="at_de">E-mail:</label>\
    						<input type="text" onblur="if(this.value == \'\')this.value=\'seu endereco de e-mail\'" onfocus="if(this.value == \'seu endereco de e-mail\')this.value=\'\'" size="30" value="seu endereco de e-mail" tabindex="4" name="at_de" id="at_de" class=""/>\
    						<br clear="all"/>\
    						<label for="at_mensagem">Mensagem:</label>\
    						<textarea onblur="if(this.value == \'\')this.value=\'opcional\'" onfocus="if(this.value == \'opcional\')this.value=\'\'" tabindex="5" rows="4" cols="38" style="" id="at_mensagem">opcional</textarea>\
    						<div class="form-char"><small>Máximo de 255 letras</small></div>\
    						<div class="form-button"><button id="at_send" value="" type="submit" class="atbtn" tabindex="5">Enviar</button><br clear="all"/></div>\
    					</form>\
    				</div>\
    			</div>\
    		</div>\
    	</div>\
    	';

    return {    	
    	init: function(){
            yue.onDOMReady(this.loadShareVideo, this, true);
        },
        loadShareVideo: function(){
            yue.on("ShareVideoBtn", "click", this.writeShareVideo, null, true);
        },
        ShareVideoSend: function(e){
        	var at_para = yud.get("at_para");
			var at_nome = yud.get("at_nome");
			var at_de = yud.get("at_de");
			var at_mensagem = yud.get("at_mensagem");
			var divShareVideoForm = yud.get("divShareVideoForm");
			var error = false;
			var errorMsg = '';
			if(at_para.value.trim() === "endereco de e-mail"){
				errorMsg = errorMsg+"\n» Digite o e-mail do destinatário<br />";
				error = true;
			}
			if(at_nome.value.trim() === "digite seu nome"){
				errorMsg = errorMsg+"\n» Digite seu nome<br />";
				error = true;
			}
			if(at_de.value.trim() === "seu endereco de e-mail"){
				errorMsg = errorMsg+"\n» Digite seu e-mail<br />";
				error = true;
			}else if(!at_de.value.match(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/)){
				errorMsg = errorMsg+"\n» Digite um e-mail válido<br />";
				error = true;
			}
		    if(error){
		        var cfg = {width:450, html : "<b>Erro! Verifique os seguintes itens e tente novamente:</b><br /><br />"+errorMsg};
		        if(msgError && typeof(msgError.exit) == 'function'){
		            msgError.exit();
		        }
		        var msgError = dialog.alert(cfg);
		        yue.stopEvent(e);
		        return false;
		    }else{
		    	var postData = "at_para="+at_para.value+"&at_nome="+at_nome.value+"&at_de="+at_de.value+"&at_mensagem="+at_mensagem.value;
				divShareVideoForm.innerHTML = '<img src="'+mastop_url+'/images/loader.gif" align="absmiddle"> <span style="color:red; font-weight:bold">Enviando dados...</span>';
				var sucesso = function(o){
					ajxRet = o.responseText;
					if(ajxRet == '1'){
						divShareVideoForm.innerHTML = '\
						<div class="okMsg">O vídeo foi enviado com sucesso. Porém, isto <b>não</b> quer dizer que ela vá chegar até esta caixa postal.</div>\
						<b>Os motivos mais comuns de erro são:</b>\
						<br/>\
						<ul>\
						<li>Se seu amigo assina algum anti-spam, a mensagem pode ser bloqueada. </li>\
						<li>Se seu amigo estiver com a sua caixa postal cheia, a mensagem não vai chegar. </li>\
						<li>Se seu amigo usa Hotmail, é preciso verificar se a mensagem não está na pasta "Lixo Eletrônico". </li>\
						<li>90% dos emails são enviados sem problemas. Se seu amigo não receber a mensagem, tente novamente utilizando outro endereço de email.</li>\
						</ul>\
						<div style="width: 150px; margin: 20px auto; text-align:center;"><button onclick="YAHOO.mastop.ShareVideo.closeShareVideo();">Fechar</button></div>\
						';
					}else{
						divShareVideoForm.innerHTML = "Erros: "+ajxRet+'<div style="width: 150px; margin: 20px auto; text-align:center;"><button onclick="YAHOO.mastop.ShareVideo.closeShareVideo();">Fechar</button></div>';
					}
				};
				var falha = function(o){
					divShareVideoForm.innerHTML = "Erro ao enviar dados. Tente novamente.<br />"+theForm;
				};
				var callback =
				{
					success:sucesso,
					failure:falha
				};
				var cObj = yuc.asyncRequest('POST', mastop_url+"/share.php", callback, postData);
		    }
        
            yue.stopEvent(e);
            return false;
        	
        },
        closeShareVideo: function(){
        	if(oResult && typeof(oResult.exit == "function")){
        		oResult.exit();
        		return true;
        	}
        },
        writeShareVideo: function(){
            var oConfig = {
            		width: 535,
                    height: 435,
                    dragDrop: false,
                    resize: false,
                    //buttonText: 'Fechar',
                    html: "<div id='divShareVideoForm'>"+theForm+"</div>"
                };
             oResult = dialog.modal(oConfig);
             oResult.id = 'ShareVideoBox';
             yue.on("ShareVideoForm", "submit", this.ShareVideoSend, null, true);
       return true;
    }};
}();
YAHOO.mastop.ShareVideo.init();