// javascripts.js
// Author: Alexander Aberer
// Date: 27.7.2000
// Last modified: 8.6.2001 (Andreas Ritter)
// Last modified: 2.7.2003 (Alexander Aberer)
// Last modified: 19.2.2004 (Stephan Schw&auml;rzler) - Opera
// Last modified: 10.12.2004 (Norbert Kujbus) - Google callback function
// Last modified: 15.01.2005 (Norbert Kujbus) - Remove Google callback function
// Last modified: 14.04.2005 (Csaba Mezo) - Introduce CountIt function
// Last modified: 11.10.2007 (Roland Fischl) - Added getOptimalTabBoxSize function

// !!!Wichtig!!! Die folgende Variable muß gesetzt werden wenn über open_window()
// Seiten auf externen/fremden Webservern geöffnet werden sollen.
if (document.domain.indexOf("gastro.rosenheim24.de") > -1) document.domain = "gastro.rosenheim24.de";
var blank_page = "about:blank"; 

function SwitchWebservice(switchform,formelement) {
	var fe, dummy;
	if(typeof formelement != "undefined") {
		fe = formelement;
	} else {
		fe = switchform.elements[0];
	}
	if (fe.selectedIndex != 0) {
		var pulldownindex = fe.selectedIndex;
		var url = fe.options[pulldownindex].value;
		locarray = url.split("|");
		if ( locarray.length > 1 ) {
			windata = locarray[0].split(",");
			dummy = open_window(locarray[1],windata[0],windata[1],windata[2],0,0,"scrollbars=" + windata[3] + ",location=no,toolbar=no,status=no,menubar=no,resizable=yes,dependent=yes");
		} else {
			dummy = open_window(url,"",700,480,10,10,"location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,dependent=no");
		}
	}
}

function realmedia(path,name,content) {
	var datestr = new Date();
	url = 'http://apps.vol.at/tools/realaudio/embed.asp?cont=' + content + '&title=' + escape(name) + '&file=' + escape(path) + "&" + escape(datestr.toLocaleString());
	if (content=='video') {
		var rc_video=window.open(url,'rc_video','width=230,height=310,resizable=yes');
		rc_video.focus();
	} else {
		var rc_audio=window.open(url,'rc_audio','width=400,height=40');
		rc_audio.focus();
	}
}

function open_window(targetX,name,width,height,posx,posy,windowoptions,init_target) {
	var it, wo, px, py, host,target;
 
	it = targetX;
	wo = "location=no,toolbar=no,status=no,statusbar=no,scrollbars=no,resizable=no,dependent=yes";
	px = py = 0;
	target = targetX;
	
	if(typeof new_window != "undefined") {
		if(new_window.closed != true) {
			new_window.close();
		}
	}

	if (typeof posx != "undefined") px = posx;
	if (typeof posy != "undefined") py = posy;
	if ((typeof windowoptions != "undefined") && (windowoptions != "")) wo = windowoptions;
	
	
	if (typeof init_target != "undefined") {
		it = init_target;
	} else {
		if (targetX.indexOf("http://") != -1) {
			host = "http://" + window.location.hostname;
			if (navigator.appName != "Opera") {
				if (targetX.indexOf(host) == -1) it = blank_page;
			}
		}
	}
	new_window = window.open(it,name,"width=" + width + ",height=" + height + "," + wo);
	//new_window.moveTo(px,py);
	new_window.location.replace(targetX);
	new_window.focus();
	return false;
}

function setUrlForPrint() {
	sUrl = document.location.href;
	if ((document.all) || (document.layers)){
		sUrl = sUrl.replace(/\?/, "\\/");
		sUrl = sUrl.replace(/\&/, "//");
	}
	document.printform.url.value = sUrl;
}

//Script to invoke OEWA measurement on page events (click)
function CountIt(what)
{
	var OEWA1="http://austria.oewabox.at/cgi-bin/ivw/CP/"+what;
	var OEWA2="http://a-vol.oewabox.at/cgi-bin/ivw/CP/"+what;
	var counter1 = new Image;
	var counter2 = new Image;
	counter1.src = OEWA1+"?r="+escape(document.referrer);
	counter2.src = OEWA2+"?r="+escape(document.referrer);
}

// Function for URL (GET) Parameter
function getURLParam(name) {
	var q = document.location.search;
	var i = q.indexOf(name + '=');
	if (i == -1) {
		return false;
	}
	var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);
	i = r.indexOf('&');
	if (i != -1) {
		r = r.substr(0, i);
	}
	return r.replace(/\+/g, ' ');
}

// resizes a window depending on its content and a given width to the optimal size
function resizeWindowToOptimalSize(oW,divId) {
    if( !document.getElementById ) return false;
    var oH = document.getElementById(divId); if( !oH ) { return false; }
    var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
    window.resizeTo( oW, oH );
    var myW = 0, myH = 0, d = document.documentElement, b = document.body;
    if( window.innerWidth ) { myW = window.innerWidth; myH = window.innerHeight; }
    else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
    else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
    if( window.opera && !document.childNodes ) { myW += 16; }
    window.resizeTo( oW + ( oW - myW ), oH + ( oH - myH ) );
}

function open_window_astitle(target,name,width,height) { 
	void(open_window(target,name,width,height));
}

//get height of given divId
function getOptimalTabBoxSize(divId) {
    if( !document.getElementById ) return false;
    var oH = document.getElementById(divId); if( !oH ) { return false; }
    var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
    return oH;
}

//mouseover function for social bookmarks
function toggleIcons(iconName,textField,active) {
    var Img = document.getElementById(iconName);
    var Text = document.getElementById(textField);
              
    if (iconName != "" && active == true) {
      switch (iconName) {
        //icons
        case 'txt_smaller':
          displayText = "Text verkleinern";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_txt_smaller2.png";
          break;
        case 'txt_bigger':
          displayText = "Text vergr&ouml;&szlig;ern";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_txt_bigger2.png";
          break;
        case 'send_a_friend':
          displayText = "Artikel versenden";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_send_a_friend2.png";
          break;
        case 'print':
          displayText = "Artikel drucken";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_print2.png";
          break;  
        case 'toggleforum':
          displayText = "Artikel kommentieren";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_forum2.png";
          break;
        case 'sendmail':
          displayText = "An Redaktion melden";
          ImgSrc = "/SysRes/R1024VOLSkin/Icon/icon_sendmail2.png";
          break;
              
        //social bookmarks
        case 'wong':
          displayText = "Mr. Wong";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/wong_b.png";
          break;
        case 'Yigg':
          displayText = "Yigg";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/yigg_b.png";
          break;
        case 'Digg':
          displayText = "Digg";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/digg_b.png";
          break;
        case 'Delicious':
          displayText = "del.icio.us";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/delicious_b.png";
          break;
        case 'StumbleUpon':
          displayText = "Stumble Upon";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/stumbleupon_b.png";
          break;
        case 'Technorati':
          displayText = "Technorati";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/technorati_b.png";
          break;
        case 'Facebook':
          displayText = "Facebook";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/facebook_b.png";
          break;
        case 'Twitter':
          displayText = "Twitter";
          ImgSrc = "/SysRes/R1024VOLSkin/Img/SocialBookmarks/twitter_b.png";
          break;  
          
        default: displayText = ""; break;
      }
      
      lastImgSrc = Img.src;
      Text.innerHTML = displayText;
      Img.src = ImgSrc;
    }
    else
    {
      Text.innerHTML = "";
      Img.src = lastImgSrc;
    }
}

function ClientSnapper(strTargetContainerId) {
    //properties & defaults
    this.nodeTargetContainer  = null;

    //set properties
    if(document.getElementById(strTargetContainerId))
        this.nodeTargetContainer = document.getElementById(strTargetContainerId);

}
    //public method to fetch a page fragment and insert it into the target container
    ClientSnapper.prototype.GetPageFragment = function(strUrl) {
        var Snapper = this;
        if (this.nodeTargetContainer != null) {
            var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
            request.open("GET", strUrl, true);
            request.onreadystatechange = function(){
                if (request.readyState == 4) {
                    if (request.responseText){
                        Snapper._InjectContent(request.responseText);
                    }
                }
            };
            request.send(null);
        }
    }
    
    //public method to read a value from cookie
    ClientSnapper.prototype.GetCookieValue = function(strCookieName, strSubKey, strDefaultValue) {
                        
        myCookie = this._GetCookie(strCookieName);
        if (myCookie == null)
            return strDefaultValue;
            
        var arrCookieVals = myCookie.split(/\&/);
        
        if (strSubKey != null && strSubKey != '') {
            for (var i = 0; i < arrCookieVals.length; i++) {
		        var Val = arrCookieVals[i].split(/\=/);   			
		        if (Val[0] == strSubKey) return Val[1];
	        }
	    }
	    else {
	        return myCookie;  
	    }
    }
    
    //private method for reading cookie 
	ClientSnapper.prototype._GetCookie = function (name){
	   var i=0;  //Suchposition im Cookie
	   var suche = name+"=";
	   var cook = null;
	   while (i<document.cookie.length){
	      if (document.cookie.substring(i, i+suche.length)==suche){
	         var ende = document.cookie.indexOf(";", i+suche.length);
	         ende = (ende>-1) ? ende : document.cookie.length;
	         cook = unescape(document.cookie.substring(i+suche.length, ende));
	      }
	      i++;
	   }
	  
    return cook;
	};
    
    
    //private method to move the fetched content to the target container
    ClientSnapper.prototype._InjectContent = function(strContent) {
        this.nodeTargetContainer.innerHTML =  strContent;
    }
    
    
function rateComment(topicId, option)
{
    if (topicId != '' && option != '')
        window.location.href = '/engine.aspx?page=forum-rate-message&messageid=' + topicId + '&rate=' + option;
}

function blendoutComment(msgId)
{
  // blend out forum post
  var msgLnkObj = document.getElementById("messageLink_" + msgId);
  var msgShwLnkObj = document.getElementById("messageShowLink_" + msgId);
  var msgBdyObj = document.getElementById("messageBody_" + msgId);

  msgLnkObj.className = "InactiveHeadline";
  msgShwLnkObj.style.display = 'block';
  msgBdyObj.style.display = 'none';
}

function blendinComment(msgId)
{
  // blend in forum post
  var msgLnkObj = document.getElementById("messageLink_" + msgId);
  var msgShwLnkObj = document.getElementById("messageShowLink_" + msgId);
  var msgBdyObj = document.getElementById("messageBody_" + msgId);

  msgBdyObj.style.display = '';
  msgLnkObj.className = 'ActiveHeadline';
  msgShwLnkObj.style.display = 'none';
}

function blendoutForumComments(selVal) {
  //blend out comments              
    $(".R1024VOL_ArticleForumMessage").find("form[name='NumberOfVotes']").each( function(i) {
      var CommentId = $(this).find("input[name='CommentId']").val();
      if (selVal > 0){
        if ($(this).find("input[name='num_p']").val()< Math.abs(selVal)){
          blendoutComment(CommentId);
        } else {
          blendinComment(CommentId);
        }
      } else if (selVal == 0){
        blendinComment(CommentId);
      }else if (selVal < 0) {
        if ($(this).find("input[name='num_n']").val()>= Math.abs(selVal)){
          blendoutComment(CommentId);
        }else {
          blendinComment(CommentId);
        }
       }
    });
}

function toggle(id)
{
    var messageLinkId = "messageLink_" + id;
    var messageShowLinkId = "messageShowLink_" + id;
    var messageBodyId = "messageBody_" + id;
    
    var msgLnkObj = document.getElementById(messageLinkId);
    var msgShwLnkObj = document.getElementById(messageShowLinkId);
    var toggleMsgBdy = document.getElementById(messageBodyId);
    
    
    if(toggleMsgBdy.style.display == 'none')
    {
        toggleMsgBdy.style.display = '';
        msgLnkObj.className = 'ActiveHeadline';
        msgShwLnkObj.style.display = 'none';
        ivwCount('ivw_open');
    }
    else
    {
        toggleMsgBdy.style.display = 'none';
        msgLnkObj.className = 'InactiveHeadline';
        msgShwLnkObj.style.display = 'block';
    }
}

function get_cookie_value(Name) 
{
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
      offset = document.cookie.indexOf(search)
      // if cookie exists
      if (offset != -1) { 
        offset += search.length
        // set index of beginning of value
        end = document.cookie.indexOf(";", offset);
        // set index of end of cookie value
        if (end == -1) end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
       }
    }
    return returnvalue;
}

//save cookie value 'forumRating'
function set_cookie_value(selVal) {
  var a = new Date();
  a = new Date(a.getTime() +1000*60*60*24*365); //save for one year (365 days)
  document.cookie='forumRating=' + selVal +'; path=/; expires='+a.toGMTString()+';';
  
  blendoutForumComments(selVal) ;
}  

function ivwCount(id)
{
    var ivw_px = new Image();
    ivw_px.src = id + "?r=" + escape(document.referrer) + "&d=" + (new Date()).getTime();
    
    var pageTracker = _gat._getTracker("UA-3628762-1");
	  pageTracker._initData();
	  pageTracker._trackPageview(id);

}

