

function createXMLHttpReqObj() {

var req = null;


			if(window.XMLHttpRequest) {
				try { //Fehler abfangen
					req = new XMLHttpRequest();
				} catch(e) {

					req = false;
				}


			} else {


                if(window.ActiveXObject) {
                     	 //Fehler abfangen
                        try {
                        req =  new ActiveXObject("Microsoft.XMLHTTP");
                        } catch(e) {

                            req = false;
                        }


                        if(typeof(req)!='object') {

                              req = new ActiveXObject("Msxml2.XMLHTTP");

                        }

                    }
                }



	return req;
}

    try {
 

     httpGetEvents = createXMLHttpReqObj();
     

     hasajax = true;
    } catch(exc) {
      
	hasajax = false;

    }

 



function handlehttpGetEventsTag() {

 
	if (httpGetEvents.readyState == 4) {
	
		response = httpGetEvents.responseXML.documentElement;
		
		tag = response.getElementsByTagName('tag')['0'].firstChild.nodeValue;
		result = response.getElementsByTagName('result')['0'].firstChild.nodeValue;
		
		 
        
		if (result == 1) {
			tagExists(tag);
			
		} else {
			tagAvail(tag); 
		}
	}
}


 

function actForm() {
	try { 
	document.getElementById("act").focus();
	} catch (err) {
	// be quiet // its ok to be null 
	}
}


function doIt(tag) {
	 
		if (httpGetEvents.readyState == 4 || httpGetEvents.readyState == 0) {
			 
			
			httpGetEvents.open("GET","/ajax/existsTag.php?tag="+tag, true);

			httpGetEvents.onreadystatechange = handlehttpGetEventsTag ;
			
		    	//httpGetEvents.setRequestHeader("Content-Length",0);
			
			httpGetEvents.setRequestHeader("Connection", "close"); 
		 
			httpGetEvents.send(''); 
		
		}
}



function tagExists (tag) {
	showEntry = document.getElementById("tag");
								
								cont = document.createElement('span')
								 //  cont.setAttribute('style','margin-bottom:5px;');
								 msg = document.createTextNode('Nickname schon vergeben');
								 //msg.appendChild(document.createElement('br'));
								 
								 cont.appendChild(msg); 
								  
								showEntry.appendChild(cont);

}

function tagAvail(tag) {
	
	showEntry = document.getElementById("tag");
	
	cont = document.createElement('span')
	cont.setAttribute('style','color:lightgreen');   
	 msg = document.createTextNode('Nickname frei');
	// msg.appendChild(document.createElement('br'));
	 
	 cont.appendChild(msg); 
	  
	showEntry.appendChild(cont);
}

function resetBox(o_box) {

	trash = document.getElementById("tag");
     
	//ashtray = document.getElementById("tag").removeChild(trash);


     if(trash != null) {
      
        if ( trash.hasChildNodes() ==true  )  {
        
  
        while ( trash.childNodes[0])
        {
            
            trash.removeChild( trash.childNodes[0] );
        }
    }

     }
}

function sha_resetChilds(tgid) {


	trash = document.getElementById(tgid);
 

     if(trash != null) {

                if ( trash.hasChildNodes() ==true)  {


                while ( trash.childNodes[0])
                {

                     trash.removeChild( trash.childNodes[0] );
                }
            }

     }
}


function watchBox(o_box) {
	showEntry = document.getElementById("tag");
	
	cont = document.createElement('span')
	  cont.setAttribute('style','color:white;margin-bottom:5px;');
	 msg = document.createTextNode('');
	 //msg.appendChild(document.createElement('br'));
	 
	 cont.appendChild(msg); 
	  
	showEntry.appendChild(cont);  
	
	doIt(o_box.value); 
}


function sha_hoverI (idname,hovImg,bgC,spC) {
 
    document.getElementById(idname).style.background = bgC;
    document.getElementById(idname).getElementsByTagName('a')[0].getElementsByTagName('img')[0].src = hovImg;
    document.getElementById(idname).getElementsByTagName('a')[0].getElementsByTagName('span')[0].style.color = spC;
}

var rld_status = false;

// renewd counter function with color //
function sha_cntr(pt,fn) {

    rld_status = true;

    tg = document.getElementById(pt);

     
    df = fn.maxLength-(fn.value.length);
    if(df<0) df=0;
    

    tg.style.visibility = 'visible';
    tg.innerHTML = '<span class="green">'+df+'</span> / '+fn.maxLength+' Zeichen';

}
//old cntr not deprecated!
function cntr(pt,fn) {

    rld_status = true;

    tg = document.getElementById(pt);


    df = fn.maxLength-(fn.value.length);
    if(df<0) df=0;


    tg.style.visibility = 'visible';
    tg.innerHTML = df+'/'+fn.maxLength+' Zeichen';

}

function hd(tgs) {
    tg = document.getElementById(tgs);
    tg.style.visibility = 'hidden';
}

function maySubmit() {
	return true; 
}



function sha_renderBadMsgO(txt) {

    oT =  document.createTextNode(txt);

    oW = document.createElement('span');
    oW.setAttribute('class','err');

    oW.appendChild(oT);
    return sha_stdWrapr(oW);
}

function sha_stdWrapr(ic) {
    sha_resetChilds('s_tmp');

    oW = document.getElementById('s_tmp');

    if(oW=='undefined'||oW==null) {
        oW = document.createElement('div');
          oW.setAttribute('id','s_tmp');
    } else {
        oW = document.getElementById('s_tmp'); 
    }

    
  
    oW.appendChild(ic);
    return oW;
}

function sha_mobHover(context,direction,textAlignment) {
    /*try {
        if(document.getElementById('mhmsg')!=undefined) {
        document.getElementById('content').removeChild(document.getElementById('mhmsg'));
        }
    } catch (ex) {
        //quiet//
    }*/
 sha_resetChilds('mhmsg');

 oD = sha_getMessageDiv();

var msgtxt;
 
    if(direction=='i') {
        //inject the message

        switch(context) {

            case 'a':
                msgtxt = 'Zu Bekannten hinzufügen';
            break;
            

            case 'ui':
                msgtxt = 'User ignorieren';
            break;

            case 'r':
                msgtxt = 'User melden';
            break;

           case 'd':
           msgtxt = 'Aus Bekanntenliste entfernen';
           break;

           case 'bup':
           msgtxt = 'Businessprofil ansehen';
           break;

           case 'pp':
           msgtxt = 'Partyprofil ansehen';
           break;

           case 'bp':
           msgtxt = '';
           break;

           case 'Twitter':
                msgtxt = 'Zeigt Dir Deine Twitter-Timeline an.';
           break;

           case 'Bekannte':
               msgtxt = 'Zeigt Dir was bei Deinen Bekannten los ist.';

           break;

           case 'Umgebung':
            msgtxt = 'Zeigt Dir was in Deiner Umgebung passiert.';
           break;

           case 'Favourite Locations':
               msgtxt = 'Zeigt Dir wer in Deinen Favourite Locations ist.';
           break;

        }



            if(textAlignment=='r') {
            oD.setAttribute('style', 'width:100%;text-align:right;');
            } else {
                oD.setAttribute('style', 'width:100%;text-align:left;');
            }
            
            oD.setAttribute('class','txt sm');


            oW = document.createElement('span');
            inr = document.createTextNode(msgtxt);

            oI = oW.appendChild(inr);


            oD.appendChild(oI);

 
        } else {


             spr = document.createTextNode(' ');
             oD.appendChild(spr)

        }




            sha_setStatus(oD);

    

        
}
 
function sha_getMessageDiv() {
    return document.getElementById('mhmsg');
}

function sha_setStatus(stat) {
    document.getElementById('content').insertBefore(stat,document.getElementById('content').firstChild);
}
   
function sha_renderGoodMsgO(txt) {
     oT =  document.createTextNode(txt);

    oW = document.createElement('span');
    oW.setAttribute('class','green');

    oW.appendChild(oT);



    return sha_stdWrapr(oW);
}

var sha_lnkRes;
var sha_cbCcntr = 1;

function sha_handleMessage() {
 
    if (httpGetEvents.readyState == 4 && sha_cbCcntr==1) {

		response = httpGetEvents.responseXML.documentElement;

		status = response.getElementsByTagName('bool')['0'].firstChild.nodeValue;
 

		if (status == 'false') {

          

            stat = sha_renderBadMsgO(response.getElementsByTagName('txt')['0'].firstChild.nodeValue);

		} else {


             txt = 'Abgeschickt';
            if(response.getElementsByTagName('txt')['0'].firstChild.nodeValue!=undefined) {
                txt = response.getElementsByTagName('txt')['0'].firstChild.nodeValue;
            }

             stat = sha_renderGoodMsgO(txt);
		}

        if(bool_doJump!=undefined) {
            if(bool_doJump==true) document.location.href = '#content';
        }

        
            sha_setStatus(stat);
     sha_cbCcntr=2;
	}

}

var shaCbContext;


function sha_lnk(params,act,retFalse,oLnk) {
sha_cbCcntr=1;

if(sha_device_brand=='rim') {

     return true;
}

    shaCbContext = 'msgs';

    sha_io(params,'',act,retFalse);
    oLnk.href='#s_tmp';

    if(document.getElementById('visQuestion')!=undefined) {
        document.getElementById('visQuestion').setAttribute('style','visibility:hidden;height:0px;');

       
    }



    if(document.getElementById('qprf')!=undefined) {
        //document.location.href = document.location.href; //request full rebuild
    }

      if(document.getElementById('gprofile')==undefined&&document.getElementById('qprf')!=undefined) {
        document.location.href = document.location.href + '#s_tmp'; //request full rebuild
    }


    //alert(oLnk.href);

    //insertAfter(,status,document.getElementBy)
   // document.getElementById('content').insertBefore(status,document.getElementById('content').firstChild);
    return false;
}

var nextCb = false;
shaNextCb = undefined;

function sha_cbContext() {

shaLocal = shaCbContext;
 


if(shaNextCb!=undefined) {
                shaCbContext = shaNextCb;
            }

    if(shaLocal=='msgs'&&sha_cbCcntr==1) {
        
        sha_handleMessage(); 

    }


    if(shaLocal=='jgps'&&sha_cbCcntr==1) {

            

           sha_handleJgps();

    }

   

    if(shaLocal=='reqAlias'&&sha_cbCcntr==1) {

            

          renewAlias();

    }

    if(shaLocal=='renAlias'&&sha_cbCcntr==1) {

   
            
           sha_handleRenewAlias();

    }



}

function getAliasBox() {
    return document.getElementById('inTag');
}

function sha_handleRenewAlias()  {

     if(httpGetEvents.readyState == 4 && sha_cbCcntr==1) {


 
                    response = httpGetEvents.responseXML.documentElement;

                   

                    status = response.getElementsByTagName('bool')['0'].firstChild.nodeValue;

                      alias = response.getElementsByTagName('alias')['0'].firstChild.nodeValue;
 



                    if (status == 'false') {

                       // alert('returned false'+response.getElementsByTagName('txt')['0'].firstChild.nodeValue);

                    } else {


                        getAliasBox().value = alias; 


                    }


                       sha_cbCcntr=2;
                       nextCb=false;
                }
}



function sha_handleJgps() {


     if(httpGetEvents.readyState == 4 && sha_cbCcntr==1) {
 

        if(sha_device_brand=='rim') {
            document.location.href = '/index.php?dogps=rim';
        } else {


                    response = httpGetEvents.responseXML.documentElement;


                    status = response.getElementsByTagName('bool')['0'].firstChild.nodeValue;

                      lt = response.getElementsByTagName('lt')['0'].firstChild.nodeValue;

                      lo = response.getElementsByTagName('lo')['0'].firstChild.nodeValue;




                    if (status == 'false') {

                       // alert('returned false'+response.getElementsByTagName('txt')['0'].firstChild.nodeValue);


                        txt = response.getElementsByTagName('txt')['0'].firstChild.nodeValue;

                        content = document.createElement('div');
                        content.appendChild(document.createTextNode("Es ist leider ein Fehler aufgetreten: "+txt));


                    } else {




                        var txt = response.getElementsByTagName('txt')['0'].firstChild.nodeValue;


                        ct = document.createElement('div');

                        inr = document.createTextNode("Deine Position ist im Bereich "+txt); //+txt);
                        ct.appendChild(inr);

                        var br = document.createElement('br');

                        ct.appendChild(br);
                         ct.appendChild(br);


                         img = document.createElement('img');
                         img.setAttribute('src', '/css/ic/aw.gif')

                         lnk = document.createElement('a');
                         lnk.setAttribute('href','/index.php?dogps=on');





                         lnk.appendChild(document.createTextNode('Jetzt übernehmen  '));
                         lnk.appendChild(img);

                        ct.appendChild(lnk);



                    }

                     nd = document.getElementById('wo_bin_ich');

                        nd.appendChild(ct);

                       sha_cbCcntr=2;
                }

                
     }


}




function sha_io(params,cb,act,retFalse) {

     

    if (httpGetEvents.readyState == 4 || httpGetEvents.readyState == 0) {


            prot = window.location.protocol;

            if(prot=='') {
                prot = 'http:';
            }


            if(act!=false||act!=undefined) {


                param = "action="+act+"&"+params;
            } else {
               param = params;
            }


		   	httpGetEvents.open("GET",prot+"//"+window.location.hostname+"/ajax/listener.php?"+param, true);

            //if(cb!=false) {
            //    alert(cb);
                	httpGetEvents.onreadystatechange = sha_cbContext;
            //}

                     //   httpGetEvents.setRequestHeader("Content-Length",param.length);


			httpGetEvents.setRequestHeader("Connection", "close");

			httpGetEvents.send(param);

		}
 
}

function sha_pushValues(params,cb) {

		sha_io(params,cb,'push',false);
}

function sha_form_savrCB() {
    if (httpGetEvents.readyState == 4) {
        return true;
    }  else {
        return false; 
    }
}

function sha_form_savr(oForm) {

var params = '';

  for (i=0; i<oForm.getElementsByTagName("input").length; i++) {
        if (oForm.getElementsByTagName("input")[i].type == "text"&&oForm.getElementsByTagName("input")[i].name!='re') {
           params += oForm.getElementsByTagName("input")[i].name + "=" +
                   oForm.getElementsByTagName("input")[i].value + "&";
        }
        if (oForm.getElementsByTagName("input")[i].type == "checkbox") {
           if (oForm.getElementsByTagName("input")[i].checked) {
              params += oForm.getElementsByTagName("input")[i].name + "=" +
                   oForm.getElementsByTagName("input")[i].value + "&";
           } else {
              params += oForm.getElementsByTagName("input")[i].name + "=&";
           }
        }
        if (oForm.getElementsByTagName("input")[i].type == "radio") {
           if (oForm.getElementsByTagName("input")[i].checked) {
              params += oForm.getElementsByTagName("input")[i].name + "=" +
                   oForm.getElementsByTagName("input")[i].value + "&";
           }
     }

  }

  if(params!='') sha_pushValues('sac=sv_reg_form&'+ params,sha_form_savrCB);
  

}


 function switchVis(elementId,collapseTarget) {



            oElement = document.getElementById(elementId);
            oElementImg = document.getElementById(elementId+"_i");
            clName = oElement.className;

            if(clName=="hvis") {
                oElementImg.src= '/css/img/arrow_down.gif';
                oElementImg.width = 6;
                oElementImg.height = 3;
                oElement.className = "vvis";
                

            } else {
                oElementImg.src= '/css/img/arrow_right.gif';
                oElementImg.width = 3;
                oElementImg.height = 6;
                oElement.className = "hvis";
                //window.location.hash =  '#'+collapseTarget;
            }

           return false; 
 }
function initHide(elementId) {
      document.getElementById(elementId).className="hvis";
 }

 function sha_rzEl(targetElementId,pxNeeded) {


    avlWidth = screen.availWidth;


    iWidth = window.innerWidth;

   

    if(iWidth!=undefined) {
        avWidth = iWidth;
    } else {
        if(avlWidth!=undefined) {
            avWidth = avlWidth;
        } else {
            avWidth = undefined;
        }
    }

   

    if(avWidth!=undefined) {

        margins = 20;

        if(avWidth>600) {
            rWidth = 600-margins;
        } else {
            rWidth = avWidth-margins;
        }

        tgWidth = rWidth-pxNeeded;


    } else {
        tgWidth = 100;
    }

    
   
    document.getElementById(targetElementId).setAttribute('style', 'width:'+(tgWidth)+'px;max-width:'+tgWidth+';');


 }
