﻿/*
*
* upondo.net JS
*
*/

/* 
 *
 * 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 ToggleVisibility(name) {
	var element = GetElementByID(name);
	if (element != null) {
   		if (element.style.visibility == 'hidden') {
   			element.style.visibility = 'visible';
   			return;
   		}
   		else if (element.style.visibility == 'visible') {
   			element.style.visibility = 'hidden';
   			return;
   		}
	}
}

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.
 *
 */
    
var req; // the httpReq object itself...

function XASF2( Param0, Param1, Param2, Param3, Param4, Param5 )
{
	var parameters = "Param1=" + Param1.toString();
    if (Param2 != undefined) if (Param2.length > 0) parameters += "&Param2=" + Param2.toString();
    if (Param3 != undefined) if (Param3.length > 0) parameters += "&Param3=" + Param3.toString();
    if (Param4 != undefined) if (Param4.length > 0) parameters += "&Param4=" + Param4.toString();
    if (Param5 != undefined) if (Param5.length > 0) parameters += "&Param5=" + Param5.toString();
    parameters += "&rnd=Math.random()";


    var fullurl = "/XRSF.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 ) {
	XASF2('DSC', CID.toString() );
	GetElementByID('ContactList').innerHTML = XASF2('RCG', BID.toString(), PID.toString());
}

function LUD( VID, FID ) { 
    GetElementByID('ProfileContent').innerHTML=XASF2('LUD',VID.toString(),FID.toString() );
}
function DPF(PID) {
	XASF2('DSPF', PID.toString());
	GetElementByID('ImgList').innerHTML = XASF2('RPFL', PID.toString());
	GetElementByID('FirstPic').src = XASF2('GFPU', PID.toString());
}
function SFAP(PID) {
	XASF2('SFAP', PID.toString());
	GetElementByID('ImgList').innerHTML = XASF2('RPFL', PID.toString());
	GetElementByID('FirstPic').src = XASF2('GFPU', PID.toString());
}

function PMBX( BID, PID ) { 
    GetElementByID('MailgridContent').innerHTML = XASF2('PMBX',BID.toString(),PID.toString() );
}
function DM(BID, MID, PID) {
	XASF2('DSM', BID.toString(), MID.toString() );
    GetElementByID('MailgridContent').innerHTML = XASF2('RMG',BID.toString(),PID.toString() );
}


function PQA( QID, VID ) {
    var questionBoxID = "Q" + QID.toString();
    var requestForm = document.getElementById(questionBoxID).getElementsByTagName('input');

    var PostOptionFields = ""; // byte-array containing true/false for each option
    for (i = 0; i < requestForm.length; i++) { // collecting the correct values for the option field: checked==yes, unchecked==no
        if (requestForm[i].checked == true) PostOptionFields += "1";
        else PostOptionFields += "0";
    }

    var textFields = document.getElementById(questionBoxID).getElementsByTagName('textarea');
    var userComment = "0";
    if (textFields.length >= 1) {
        if (textFields[0].value.length > 0) userComment = textFields[0].value; 
    }
    document.getElementById(questionBoxID).innerHTML = XASF2('PQA', QID.toString(), VID.toString(), PostOptionFields, userComment );
}


function RLCFS() {
	XASF2('RLCFS', '');
}



function ClosePopup(ContentName, BackgroundName) {
	HideElement(BackgroundName);
    HideElement(ContentName);
    
}
function ShowPopup(ContentName, BackgroundName) {
    ShowElement(ContentName);
    ShowElement(BackgroundName);
}


function FotoThumbClick( ImageURL ) {
    GetElementByID('FotoboxCurrentFoto').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 ) );
}

/*
 * 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) {
	/*var outPanel = document.getElementById(layerID);
	limit=Math.abs(limit)||0;
	    	
    //layerID.appendChild(source.value.length);
	// layerID.appendChild(document.createTextNode(source.value.length));
	outPanel.innerHTML = source.value.length.toString(); //  + " / " + limit.toString();	
	outPanel.innerHTML += " / " + limit.toString();		   */

}



/*
	Does all client-side stuff for selecting a gift:
	- loads the current html-link-object and switches CSS classes
	- resets CSS of prior selected html-link-object (this is saved in LastGiftSelection)
	- updates the text with gift-name/price/coins-left
	- saves selected gift in hidden-input value "GiftPopupSelction", hardcoded in aspx page...
*/
var LastGiftSelection = null;
function SelectGift( GiftID ) {

	var giftHtmlSelectionLink = GetElementByID(GiftID); // saves the javascript object of the html-selection-link itself
	if (giftHtmlSelectionLink != null) {
		giftHtmlSelectionLink.className = "gift-border-20-hit";
		if (LastGiftSelection != null) LastGiftSelection.className = 'gift-border-20';
		LastGiftSelection = giftHtmlSelectionLink;
		GetElementByID('GiftPopupSelection').value = GiftID.toString(); // updating number for transfer to have saved which gift is send
	}
}




function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
	if (!document.forms[FormName])	return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if (!objCheckBoxes) 	return;
	var countCheckBoxes = objCheckBoxes.length;
	if (!countCheckBoxes) objCheckBoxes.checked = CheckValue;
	else
	
		for (var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}




function OpenAuthWindow() {
	var Provider = XASF2('DMP', GetElementByID('TextBox1').value );
	if (Provider == 'GoogleMail') window.open("/oauth.aspx?provider=GoogleMail", "GoogleMail", "location=1,status=1,scrollbars=1,width=800,height=500");
	else if (Provider == 'Yahoo') window.open("/oauth.aspx?provider=Yahoo", "Yahoo", "location=1,status=1,scrollbars=1,width=800,height=500");
	else if (Provider == 'Hotmail') window.open("/oauth.aspx?provider=Hotmail", "Hotmail", "location=1,status=1,scrollbars=1,width=900,height=600");
	else if (Provider == 'MSN') window.open("/oauth.aspx?provider=MSN", "MSN", "location=1,status=1,scrollbars=1,width=800,height=500");
}
