﻿/*functions to control video player in article*/
function thisMovie(movieName) {
    /// <summary>Finds media player flash movie</summary>
    /// <param name="movieName" type="string">Id of player html element</param>
    /// <returns type="object"/>
    var player =  window[movieName];
    
    if (typeof(player)=="undefined") {
       player =  document[movieName];
    }
    
    if (typeof(player)=="undefined"){
       player =  document.getElementById(movieName);
    }
    return player;
}
function expandMedia(mediaid,size)
{
    a1=thisMovie("MediaPlayer"+mediaid);
	var small = document.getElementById('expandSmall'+mediaid);
	var big = document.getElementById('expandBig'+mediaid);
	if(size=="Big")
	{
		small.className='item_hide';
		big.className='expandBig';
		setTimeout('a1.jsPlay()',1000);
	}
	else
	{
		small.className='expandSmall mediathumb aligned';
		big.className='item_hide';
		a1.jsStop();
	}
	return false;
} 


/*function for article and forum pages to redirect to different page*/
function RedirectToForum(pageNumber,forumid,forumtypeid,revertSortingExpr)
{
	if(forumtypeid>2)
		{window.location ='/comments/' + pageNumber+'/' + forumtypeid+'/'+forumid+'.html'+revertSortingExpr+'#relatedInfoContainer';}
	else
		{window.location ='/discussion/' + pageNumber+'/'+forumid+'.html'+revertSortingExpr+'#relatedInfoContainer';}
	
}

/*helper function in_array - checks if given needle is already in haystack array*/
function in_array(needle, haystack) {
    for (var i = 0; i < haystack.length; i++) {
        if (haystack[i] == needle) {
            return true;
        }
    }
    return false;
}

/*opacity value ranges from 0 to 10.*/
function setThumbOpacity(objtoset,value) {
	objtoset.style.opacity = value/10;
	objtoset.style.filter = 'alpha(opacity=' + value*10 + ')';
}

/*function for adding new js file to be loaded on page onLoad event
this function should be used for adding new js files in aspx files instead of adding them directly*/
var files2include = new Array();
function includeJS(script_filename){
    if (!in_array(script_filename, files2include)) {
        files2include[files2include.length] = script_filename;
    }
}

/*function for adding new js command to be proceeded on page onLoad event
this function should be used for adding new js commands in aspx files instead of adding them directly*/
var onloadActions = new Array();
function addOnloadAction(action){
    onloadActions[onloadActions.length]=action;
}

/*set of functions for including other javascript files by contoller*/
var included_files = new Array();

function include_once(script_filename) {
    if (!in_array(script_filename, included_files)) {
        included_files[included_files.length] = script_filename;
        include_dom(script_filename);
    }
}

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

/*sets a cookie according to params on input*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*'expires' param means amount of days */
    if ( expires ) {
      expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

/*get a cookie of name given by input*/
function Get_Cookie( name ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) &&
    ( name != document.cookie.substring( 0, name.length ) ) )
    {
    return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}


/*function for fixing email addresses broken in order to avoid spaming spiders*/
function mixMail(){
  var mm = $(".mixmail");
  for(var i=0;i<mm.length;i++){
    var u=mm[i].firstChild.nodeValue.lastIndexOf('/');
    if(u>-1){
      mm[i].firstChild.nodeValue=mm[i].firstChild.nodeValue.substr(u+1);
    }
    mm[i].firstChild.nodeValue=mm[i].firstChild.nodeValue.replace('+','@');
    for(var ii=0;ii<mm[i].attributes.length;ii++){
      if(mm[i].attributes[ii].name=='href'){
        var u=mm[i].attributes[ii].nodeValue.lastIndexOf('/');
        if(u>-1){
          mm[i].attributes[ii].nodeValue=mm[i].attributes[ii].nodeValue.substr(u+1);
        }
        mm[i].attributes[ii].nodeValue='mailto:'+mm[i].attributes[ii].nodeValue.replace('+','@');
        break;
      }
    }
  }
}

/*function to adjust tabs behaviour - as anchors they keep the hand cursor feature, but we need to ged rid of the default action*/
function fixTabs(){
    $(".tab").click(function(event){
     event.preventDefault();
    });
/*
    $(".tab_oposite").click(function(event){
     event.preventDefault();
    });
*/
    $(".tab_acc").click(function(event){
     event.preventDefault();
    });
    
    $(".nohref").click(function(event){
     event.preventDefault();
    });
}

/*function for search form 'Send' button*/
function SearchButton(elementId, orderByName){
    location.href ='/search/?k=' + encodeURI(this.document.getElementById(elementId).value);
}

