//Script to show or hide the S2F - surrounding HTML
//and 
function S2FShow()
{
   var check=document.getElementById('pop_overlay').style.display;
   var selectCount;
   var loc;
   selectCount =  document.getElementsByTagName('select').length;
   //See if we are secure or not and change script accordingly
   if(location.protocol.toLowerCase() =='https:')
   {
	    //We are secure, so we do the callback directly
	    if(check=='none')
	    {
	       doS2FCallback('init');
	       document.getElementById('pop_overlay').style.display='';
	       document.getElementById('pop_overlay').style.height = document.getElementById('basisTabelle').clientHeight + 'px';
	       document.getElementById('pop_container').style.display='';
	       window.scrollTo(0,0);
	       //Start tracking the S2F
	       if( typeof(_tag) != 'undefined')
	       {
				   _tag.dcsMultiTrack('WT.ti','Send to Friend Start','DCS.dcsuri', '/SendToFriend/start');
				 }
	        //Hide Dropdown - lists (Z-order Bug in IE6)
	       var browser = navigator.appName;
	       var b_version = navigator.appVersion;
	       if(browser == 'Microsoft Internet Explorer' && b_version.indexOf('MSIE 6')> 0)
	       {
	          for (n=0; n < selectCount; n++)
	          document.getElementsByTagName('select')[n].style.display = 'none';
	       }
	    }
	    else
	    {
				//Hide the S2F
	       document.getElementById('pop_overlay').style.display='none';
	       document.getElementById('pop_container').style.display='none';
	       //Show hidden MVK dropdown - list (Z-order Bug in IE6
	       for (n=0; n < selectCount; n++)
	          document.getElementsByTagName('select')[n].style.display = '';
				//End tracking the S2F
				if( typeof(_tag) != 'undefined')
				{
					_tag.dcsMultiTrack('WT.ti','Send to Friend Sent','DCS.dcsuri', '/SendToFriend/Sent');
				}
	      
	      //restore page as it was before S2F was shown  
	      if(s2FBackJumps > 0)
	      {
					loc = location.href;
					loc = loc.replace('https','http');
					window.location = loc;
				}
				else
				{
					doS2FCallback('close');
				}

	    }
	 }
	else
	{
		//we are unsecure, use postback for switching to secure
		__doPostBack(s2FPostbackTarget,'GetSecure');
	}
}

function s2fcbResult(resultText) 
{
	//Insert the resultdata of the callback
	curS2FElemObj = document.getElementById(curS2FElem);
	if( curS2FElemObj != undefined) 
	{
		curS2FElemObj.parentNode.innerHTML = resultText;
  }
}

//Collect data and send it to the server
function doS2FCallback(func) 
{
  var s2fmessage;
  if(func == 'init') 
  {
	    s2fmessage = 'function=init'
	} 
	else 
	{
		if(func =='check')
		{
	    s2fmessage = 'senderName=' + encodeURIComponent(document.getElementById(S2FSenderNameClId).value);
	    s2fmessage += '&senderMail=' + encodeURIComponent(document.getElementById(S2FSenderMailClId).value);
      s2fmessage += '&recipientMail=' + encodeURIComponent(document.getElementById(S2FRecipientMailClId).value);
			s2fmessage += '&recipientName=' + encodeURIComponent(document.getElementById(S2FRecipientNameClId).value);
			s2fmessage += '&message=' + encodeURIComponent(document.getElementById(S2FMessageClId).value);
			s2fmessage += '&captchaText=' + encodeURIComponent(document.getElementById(S2FCaptchaClId).value) + '&function=check';
			//End tracking the S2F
			
		}
		else
		{
			s2fmessage = 'function=end';
		}
  }
	var s2fcontext = '';
	WebForm_DoCallback(s2FCallbackRefID,s2fmessage, s2fcbResult, s2fcontext, s2fError, false);
}

function s2fError(returnmessage, context)
{
	alert("Fehler. Bitte aktualisieren Sie die Seite.");
}

function addOnloadFunction(funcCall)
{
    if (window.addEventListener) 
    { // Non-IE browsers
        window.addEventListener('load', funcCall, false);        
    } 
    else if (window.attachEvent) 
    { // IE 6+
        window.attachEvent('on' + 'load', funcCall);
    } 
    else 
    { // Older browsers 
        var currentEventHandler = window['on' + 'load'];
        if (currentEventHandler == null) 
        {
	        window['on' + 'load'] = funcCall;
        } 
        else 
        {
        window['on' + 'load'] = function(e) { currentEventHandler(e); funcCall(e); }
        }
    }
}