﻿/*
*
* upondo.net JS 2010
*
*/

/* 
 *
 * General functions: Hide/Show, GetEelement etc. 
 *
 */
 function GetElementByID( name )
{
    return document.getElementById( name );
}

function ShowElement( name )
{
    var element =GetElementByID( name );
    if(element!=null) element.style.visibility = 'visible';
}
function HideElement( name )
{
    var element =GetElementByID( name );
    if(element!=null) element.style.visibility = 'hidden';
}

function GetXmlHttpReq() { 
    if(window.XMLHttpRequest) { // FF&co
        try { 
            req = new XMLHttpRequest(); 
        } 
        catch(e) {
            req = false;
        }
    }
    else if(window.ActiveXObject) { //IE
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e) {
                req = false;
            }
        }
    }
    if( req ) return req;
    else return null;
}


/* 
 *
 * upondo specific functions: profile, webservice etc.
 *
 */
function opw( UserID ) {
    var jswin = window.open('viewProfile.aspx?VID='+UserID,UserID,'left=0,top=0,width=620,height=550,status=yes,menubar=no,scrollbars=no,toolbar=no,dependent=yes');
    jswin.focus();
}
 
    
var req; // the httpReq object itself...

function XASF2( Param0, Param1, Param2, Param3 )
{
    var parameters = "Param1=" + Param1.toString();                     
    if( Param2.length > 0 ) parameters += "&Param2=" + Param2.toString();
    if( Param3.length > 0 ) parameters += "&Param3=" + Param3.toString();
    
    var fullurl = "XRSF2.asmx/" +Param0.toString() +"?"+ parameters;
    if( req == null ) req = GetXmlHttpReq();
    
    req.open("GET", fullurl, false); // false = not synchronous! // TODO:insert statehandling function if necessary...
    req.setRequestHeader("Content-Type", "text/xml; charset=UTF-8"); 
    req.setRequestHeader("Connection","close");
    req.send(null);
    
    if (req.readyState == 4) {
        if (req.status == 200) {
    
            // This is required because of the following bug: 
            // https://bugzilla.mozilla.org/show_bug.cgi?id=194231 (see: http://forum.de.selfhtml.org/archiv/2008/3/t168370/)
    
            var finaloutput='';          
            for(var i = 0; i < req.responseXML.getElementsByTagName('string')[0].childNodes.length; i++) {
                finaloutput += req.responseXML.getElementsByTagName('string')[0].childNodes[i].nodeValue;
            }
            if( finaloutput.length > 0 ) return finaloutput;
  
            return "[XmlHttp] Content error.";
        }
        else return "[XmlHttp] Request error: " + req.status;
    }
    else return "[XmlHttp] Request not completed!";
}



function PCC( BID, VID ) {
    GetElementByID('ActionFavBlock').innerHTML=XASF2('PCC',BID.toString(),VID.toString(),'');
}

function PCL( BID, PID ) { 
    GetElementByID('ContactList').innerHTML = XASF2('PCL',BID.toString(),PID.toString(),'');
}
function PRC( VID ) { 
    GetElementByID('ActionReport').innerHTML=XASF2('PRC',VID.toString(),'','');
}
function DC( BID, CID, PID ) { 
    GetElementByID('ContactList').innerHTML = XASF2('DC',BID.toString(),CID.toString(),PID.toString() );
}




function LUD( VID, FID ) { 
    GetElementByID('ProfileContent').innerHTML=XASF2('LUD',VID.toString(),FID.toString(),'');
}
function DPF( PID ) { 
    GetElementByID('ImgList').innerHTML=XASF2('DPF',PID.toString(),'','');
}
function PSR( PID ) { 
    /* GetElementByID('UserList').innerHTML = XASF2('LSI','22060','',''); */
    GetElementByID('UserList').innerHTML = XASF2('PSR',PID.toString(),'','');
}


function PMBX( BID, PID ) { 
    GetElementByID('MailgridContent').innerHTML = XASF2('PMBX',BID.toString(),PID.toString(),'');
}
function DM( BID, MID, PID ) { 
    GetElementByID('MailgridContent').innerHTML = XASF2('DM',BID.toString(),MID.toString(),PID.toString() );
}





function OpenPopup() {
    ShowElement( 'PopupBackground' );
    ShowElement( 'PopupContent' );
}
function ClosePopup() {
    HideElement( 'PopupBackground' );
    HideElement( 'PopupContent' );
}
function ShowTOS() {
    GetElementByID( 'PopupText' ).innerHTML=XASF2('LDID','TermsOfService','','' );
    OpenPopup();
}
function ShowDPI() {
    GetElementByID( 'PopupText' ).innerHTML=XASF2('LDID','Privacy','','' );
    OpenPopup();
}

function FotoThumbClick( ImageURL ) {
    GetElementByID( 'ProfileCurrentFoto' ).src = ImageURL;
}

var LastNavTab = null;
function NavTabbing( linkobject ) {
    if( LastNavTab != null ) LastNavTab.className = 'inactive';
    if( linkobject == null ) return;    
    linkobject.className = 'active';
    linkobject.blur();
    LastNavTab = linkobject;
}
function NavTabbingByID( linkID ) {
    NavTabbing( GetElementByID( linkID ) );
}

function CutTextLength( inputObject, maxLength )
{
    if (inputObject.value.length > maxLength)
    {
        inputObject.value = inputObject.value.substring(0,maxLength);
    }
}


/*
 * JS sources: 
 * http://oak.ucc.nau.edu/djv7/js/charcounter.html
 * http://www.fullposter.com/snippets.php?snippet=262
 */
function typerCount(source, layerID, limit, countdown)
{
    if(typeof layerID=="string")
    {
        layerID=document.getElementById(layerID);
    }
    limit=Math.abs(limit)||0;
    
    if(!limit && countdown) countdown=0;
    
    if(typeof layerID=="object" && typeof source=="object")
    {
	    if(!layerID.childNodes.length){
	        layerID.appendChild(document.createTextNode(source.value.length));
	    }
		if(source.value.length+1>=limit){
		    source.value=source.value.substring(0, limit);
		}
		layerID.childNodes[0].nodeValue=(!countdown)?
		source.value.length:
		limit - source.value.length;
		
		layerID.childNodes[0].nodeValue += " / " + limit.toString();
		
    }
}