﻿function validateLoginFields()
{
    var username = document.getElementById('txtUserName');
    var password = document.getElementById('txtPassword');
    
    if (username.value == '')
        return false;
    
    if (password.value == '')
        return false;
    
    return true;
}

function getLoginParameters(usernameId, passwordId)
{ 
    var parameters = '';
    var txtLogin = document.getElementById(usernameId);
    var txtPassword = document.getElementById(passwordId);

    parameters += 'username=' + txtLogin.value;
    parameters += '&password=' + txtPassword.value;
    return parameters;
}

function showLoading(loadingId, hideId)
{
    var loading = document.getElementById(loadingId);
    
    loading.style.display = '';
    
    if (hideId != '')
    {
        var hide = document.getElementById(hideId);

        hide.style.display = 'none';
    }
}

function hideLoading(loadingId, showId)
{
    var loading = document.getElementById(loadingId);

    loading.style.display = 'none';
    
    if (showId != '')
    {
        var show = document.getElementById(showId);
 
        show.style.display = '';
    }
}

function changeLoginBar(response)
{ 
    //arr = status, email
    var arr = response.split('|');
    if (arr[0] == '0'){
        document.getElementById('trLogged').style.display = 'none';
        document.getElementById('trError').style.display = 'none';
        document.getElementById('trLogIn').style.display = '';
        document.getElementById('txtPassword').value = '';
    }
    else if (arr[0] == '1'){
        document.getElementById('trLogged').style.display = '';
        document.getElementById('trError').style.display = 'none';
        document.getElementById('trLogIn').style.display = 'none';
        
	document.getElementById('lblEmail').title = arr[1];

        if (arr[1].length > 10)
            arr[1] = arr[1].substring(0,10) + '...';
        
        document.getElementById('lblEmail').innerHTML = arr[1];
	
    }
    else{
        document.getElementById('trLogged').style.display = 'none';
        document.getElementById('trError').style.display = '';
        document.getElementById('trLogIn').style.display = 'none';        
    }
    
    hideLoading('trLoading','');
}


function clearText(textId, textToClear)
{
    var textBox = document.getElementById(textId);

    if (textBox.value == textToClear)
        textBox.value = '';
}

function openAlert(text)
{
    document.getElementById('alertText').innerHTML = text;
    openBox('boxAlert');
}

function openFrameBox(frameId, frameSrc, boxId)
{
    openBox(boxId);
    
    terms = document.getElementById(frameId);

    if (terms.src == '')
        terms.src = frameSrc;
}


var buttonToClick;
function enterSubmit(e)
{
    var targ;
    
    if(window.event) // IE
    {
        if (e.keyCode == 13)
            document.getElementById(buttonToClick).click();
    }     
    else // Netscape/Firefox/Opera
    {
        if (e.which == 13)
            document.getElementById(buttonToClick).onclick();
    }
     
}

//SIGNUP
function getImportAccountParameters(loginId, passwordId)
{ 
    var parameters = '';
    var txtLogin = document.getElementById(loginId);
    var txtPassword = document.getElementById(passwordId);
    var rdbMySpace = document.getElementById('rdbMySpace');
    var rdbFacebook = document.getElementById('rdbFacebook');
    var rdbBlogger = document.getElementById('rdbBlogger');
    
    if (rdbMySpace.checked = 'checked')
        parameters += 'network=MYSPACE';
    else if (rdbFacebook.checked == 'checked')
        parameters += 'network=FACEBOOK';
    else
        parameters += 'network=BLOGGER';
    
    parameters += '&username=' + txtLogin.value;
    parameters += '&password=' + txtPassword.value;
    return parameters;
}

function verifyImport(response)
{
    var arr = response.split('|');
    if (arr[0] == '1')
    {
        parent.goSettings(); 
    }
    else 
        showMsg('msgImport', arr[1])
}

function verifyLogin(response)
{
    var arr = response.split('|');
    if (arr[0] == '1')
    {
        parent.changeLoginBar(response);    
        parent.goSettings(); 
    }
    else 
        showMsg('msgLog', 'Invalid login and/or password.')
}


function showMsg(elementId, message)
{
    document.getElementById(elementId).display = '';
    document.getElementById(elementId).value = message;
    document.getElementById(elementId).innerHTML = message;
}

function hideMsg(elementId)
{
    document.getElementById(elementId).display = 'none';
    document.getElementById(elementId).value = '';
    document.getElementById(elementId).innerHTML = '';
}

function changeDisplayForgot()
{
    area = document.getElementById('trForgot');
    msg = document.getElementById('tdForgot');
    
    if (area.style.display == '')
    {
        area.style.display = 'none';
        msg.style.display = 'none'
    }
    else
    {
        area.style.display = '';
        msg.style.display = ''
    }
}

function checkTermsNew(source, args)
{
    if (document.getElementById('chkTermsNew').checked == '')
        args.IsValid = false;
    else
        args.IsValid = true;
}

function checkTerms(source, args)
{
    if (document.getElementById('chkTerms').checked == '')
        args.IsValid = false;
    else
        args.IsValid = true;
}

//SETTINGS
function under18(source, args)
{
    var dateBirth = document.getElementById('ctl00_ContentPlaceHolder1_txtDateBirth');
    
    var day = dateBirth.value.substr(3,2);
    var month = dateBirth.value.substr(0,2);
    var year = dateBirth.value.substr(6,4);
    
    var date = new Date(year, month-1, day);
    var now = new Date();
    
    if (date <= now)
        args.IsValid = true;
    else
        args.IsValid = false;
}

//SEARCH
function arrowMenu(arrowId, menuId, selectedId, text)
{
    var arrow = document.getElementById(arrowId);
    var menu = document.getElementById(menuId);
    
    if (arrow.className == 'act')
    {
        arrow.className = '';
        menu.style.display = 'none';
    }
    else
    {
        arrow.className = 'act';
        menu.style.display = '';
    }
    
    if (text != '')
    {
        document.getElementById(selectedId).innerHTML = text;
    }
}

//WATCH
function expand(area, btShow, btHide)
{
    document.getElementById(area).style.display = '';
    document.getElementById(btShow).style.display = '';
    document.getElementById(btHide).style.display = 'none';  
}

function supress(area, btShow, btHide)
{
    document.getElementById(area).style.display = 'none';
    document.getElementById(btShow).style.display = '';
    document.getElementById(btHide).style.display = 'none';
}

//CREATION
function showHide(show, hide)
{
    document.getElementById(show).style.display = '';
    document.getElementById(hide).style.display = 'none';
}

function changeSignUp()
{
    document.getElementById('boxLogIn').style.display = 'none';
    document.getElementById('boxSignUp').style.display = '';
    document.getElementById('boxSignUp').style.display = '';
}

function changeLogIn()
{   
    document.getElementById('boxLogIn').style.display = '';
    document.getElementById('boxSignUp').style.display = 'none';
    document.getElementById('boxSignUp').style.display = 'none';
}

function changeMethod(method)
{
    var divYouTube = document.getElementById('divYouTube');
    var divUpload = document.getElementById('divUpload');
    var titleYouTube = document.getElementById('fromYouTube');
    var titleUpload = document.getElementById('fromUpload');

    if (method == 'fromUpload')
    {
        divYouTube.style.display = 'none';
        divUpload.style.display = '';
        titleYouTube.className = '';
        titleUpload.className = 'act';
    }
    else
    {
        divYouTube.style.display = '';
        divUpload.style.display = 'none';
        titleYouTube.className = 'act';
        titleUpload.className = '';
    }
}


//STEP3
function changeNetwork(action, network)
{
    if (network == '')
    {
        document.getElementById('ctl00_ContentPlaceHolder1_table' + action + 'To').style.display = '';
        document.getElementById('ctl00_ContentPlaceHolder1_table' + action + 'Login').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_hid' + action + 'Selected').value = '';
    }
    else
    {
        if (action == 'Embed')
        {
            if (network == 'MySpace')
            {
                document.getElementById('titleSection').style.display = '';
                document.getElementById('ctl00_ContentPlaceHolder1_cmbMyspaceSections').style.display = '';
            }
            else
            {
                document.getElementById('titleSection').style.display = 'none';
                document.getElementById('ctl00_ContentPlaceHolder1_cmbMyspaceSections').style.display = 'none';
            }
        }
        
        document.getElementById('ctl00_ContentPlaceHolder1_table' + action + 'To').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_table' + action + 'Login').style.display = '';
        document.getElementById('ctl00_ContentPlaceHolder1_hid' + action + 'Selected').value = network;
        var hidNetwork = document.getElementById('ctl00_ContentPlaceHolder1_hid' + action + network);
        var txtEmail = document.getElementById('ctl00_ContentPlaceHolder1_txt' + action + 'Email');
        var txtPassword = document.getElementById('ctl00_ContentPlaceHolder1_txt' + action + 'Password');
        var lblEmail = document.getElementById('lblEmail' + action);
        var lblPassword = document.getElementById('lblPassword' + action);
        
        if (hidNetwork.value != '')
        {
           txtEmail.value = hidNetwork.value.split('|')[0];
           txtPassword.value = hidNetwork.value.split('|')[1];
        }
        else
        {
           txtEmail.value = '';
           txtPassword.value = '';
        }
        
        lblEmail.innerHTML = network;
        lblPassword.innerHTML = network;
    }
}

function fillPasswords()
{
    var hidNetwork = document.getElementById('ctl00_ContentPlaceHolder1_hidSendMySpace');
    var txtPassword = document.getElementById('ctl00_ContentPlaceHolder1_txtSendPassword');
    
    if (hidNetwork.value != '')
       txtPassword.value = hidNetwork.value.split('|')[1];
    else
       txtPassword.value = '';
       
    hidNetwork = document.getElementById('ctl00_ContentPlaceHolder1_hidEmbedMySpace');
    txtPassword = document.getElementById('ctl00_ContentPlaceHolder1_txtEmbedPassword');
    
    if (hidNetwork.value != '')
       txtPassword.value = hidNetwork.value.split('|')[1];
    else
       txtPassword.value = '';
}

function copy(textId) 
{  
    inElement = document.getElementById(textId);
    
    if (inElement.createTextRange) 
    {   
        var range = inElement.createTextRange();  
        if (range) 
            range.execCommand('Copy');  
    } 
    else 
    {  
        var flashcopier = 'flashcopier';  
        if(!document.getElementById(flashcopier)) 
        {  
            var divholder = document.createElement('div');  
            divholder.id = flashcopier;  
            document.body.appendChild(divholder);  
        }  
    
        document.getElementById(flashcopier).innerHTML = '';  
        var divinfo = '<embed src="http://static.tubespree.com/swf/clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo; 
    }  
    
    inElement.focus();
    inElement.select();  
} 

//FRAME
function resizeFrame(frameId)
{
    if (!window.opera && !document.mimeType && document.all && document.getElementById)
    {
        parent.document.getElementById(frameId).style.height=document.body.offsetHeight+"px";
    }
    else if(document.getElementById) 
    {
        parent.document.getElementById(frameId).style.height=document.body.scrollHeight+"px"
    }
}

//FLASH
function powerFlashRender (flashFileName, flashWidth, flashHeight, flashVars, flashWMode, flashObjectId, flashTagContainerId)  {
	var renderString;
	
	renderString = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" ";
	renderString += "width=\""+flashWidth+"\" height=\""+flashHeight+"\" "; 
	
	if (navigator.appName.indexOf("Microsoft") != -1) {
		if (flashObjectId != "" && flashObjectId != undefined) renderString += " id=\""+flashObjectId + "\" ";
	}
	renderString += " > ";
	
	renderString += "<param name=\"movie\" value=\""+flashFileName+"\">";
	renderString += "<param name=\"quality\" value=\"high\">";
	renderString += "<param name=\"allowScriptAccess\" value=\"always\">";
	
	if (flashVars != "" && flashVars != undefined) renderString += "<param name=\"FlashVars\" value=\""+flashVars+"\">";
	if (flashWMode != "" && flashWMode != undefined) renderString += "<param name=\"wmode\" value=\""+flashWMode+"\">";
	
	renderString += "<embed src=\""+flashFileName+"\" ";
	renderString += "width=\""+flashWidth+"\" height=\""+flashHeight+"\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" ";
	renderString += "allowscriptaccess=\"always\" ";
	
	if (navigator.appName.indexOf("Microsoft") == -1) {
		if (flashObjectId != "" && flashObjectId != undefined) renderString += "name=\""+flashObjectId+"\" id=\""+flashObjectId+"\" ";
	}
	
	if (flashVars != "" && flashVars != undefined) renderString += "flashvars=\""+flashVars+"\" ";
	if (flashWMode != "" && flashWMode != undefined) renderString += "wmode=\""+flashWMode+"\" ";
	
	renderString += " ></embed></object>";
	
	if (flashTagContainerId != "" && flashTagContainerId != undefined) {
		document.getElementById(flashTagContainerId).innerHTML = renderString;
	} else {
		document.write(renderString);
	}
	
	if (flashObjectId != "" && flashObjectId != undefined) {
	  if (navigator.appName.indexOf("Microsoft") != -1) {
		  window[flashObjectId] = document.getElementById(flashObjectId);
	  } else {
		document[flashObjectId] = document.getElementById(flashObjectId);
	  }
	}
	return true;
}

//BOX
function $(v) 
{ 
    return(document.getElementById(v)); 
}

function $S(v) 
{ 
    return($(v).style); 
}

function agent(v) 
{ 
    return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); 
}

function isset(v) 
{ 
    return((typeof(v)=='undefined' || v.length==0)?false:true); 
}

function XYwin(v) 
{ 
    var z=agent('msie')?Array(document.body.clientHeight,document.body.clientWidth):Array(window.innerHeight,window.innerWidth); return(isset(v)?z[v]:z); 
}

function openBox(boxId) 
{ 
    $S('boxBackground').display = ''; 
    $S(boxId).display = '';    
}

function closeBox(boxId) 
{ 
    $S('boxBackground').display = 'none'; 
    $S(boxId).display = 'none';
}

//CALLBACK (AJAX)
function PowerXMLRequest(){ 
    this.xmlHttp = null; 
} 
PowerXMLRequest.prototype.Get = function(url, aSync, handler, params){ 
    this.xmlHttp = this.Instantiate(); 

    //Se for async, configura a chamada do handler 
    if (aSync && handler){ this.RegisterHandler(handler, params); } 

    //Faz a requisição 
    this.xmlHttp.open("GET", url, aSync); 
    this.xmlHttp.send(null); 

    //Se for sync, retorna o valor obtido     
    if (!aSync) { return this.xmlHttp.responseText; } 
}; 
PowerXMLRequest.prototype.Post = function(url, paramsColStr, aSync, handler, params){ 
    this.xmlHttp = this.Instantiate(); 

    //Se for async, configura a chamada do handler 
    if (aSync && handler){ this.RegisterHandler(handler, params); } 

    //Faz a requisição 
    this.xmlHttp.open("POST", url, aSync); 
    this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    this.xmlHttp.send(paramsColStr); 

    //Se for sync, retorna o valor obtido     
    if (!aSync) { return this.xmlHttp.responseText; } 
}; 
PowerXMLRequest.prototype.Instantiate = function(){ 
    var _xmlhttp; 
    //Try to instantiate the xml http object 
    if (window.XMLHttpRequest) {// code for all new browsers 
        try{ 
            _xmlhttp=new XMLHttpRequest(); 
        } catch (e) {_xmlhttp=false;} 
    } 
    else if (window.ActiveXObject){// code for IE5 and IE6 
        try{ 
            _xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try{ 
                _xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e) {_xmlhttp=false;} 
        } 
    } 

    //If its failed to load the object abort     
    if (_xmlhttp===null){ 
        throw "Your browser does not support XMLHTTP."; 
    } 

    return _xmlhttp; 
}; 
PowerXMLRequest.prototype.RegisterHandler = function(handler, params){ 
    this.xmlHttp.onreadystatechange = function(){ 
        //If the get is loaded (state 4) 
        if (powerXMLRequest.xmlHttp.readyState==4){ 
            if (powerXMLRequest.xmlHttp.status==200){ 
                handler.call(this, powerXMLRequest.xmlHttp.responseText, params); 
            } 
            else{ throw "Problem retrieving XML data"; } 
        } 
    }; 
}; 
var powerXMLRequest = new PowerXMLRequest(); 


function ClientCallBack(clientCallBackPageUrl) 
{ 
    this.PageUrl = clientCallBackPageUrl; 
} 

ClientCallBack.prototype.Call = function(powerMethod, httpMethod, params, listener)
{ 
    var url = this.PageUrl + '?PowerMethod=' + powerMethod; 
    var bodyRequest; 

    if(httpMethod == 'GET')
    { 
        url = url + '&' + params;
        powerXMLRequest.Get(url, true, listener, this); 
    } 
    else if(httpMethod == 'POST') 
    { 
        bodyRequest = params; 
        powerXMLRequest.Post(url, bodyRequest, true, listener, this); 
    }
}; 