﻿/******** Trim Member Functions ************/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function PopupTimeOutRedirect()
{
    try
    {    
        if (self != self.parent && self.parent.frames.length > 0)
            self.parent.location = document.location;
    }
    catch (Exception) {}
}

function AddOnloadEvent(fnc)
{
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "load", fnc, false );
	else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", fnc );
	}
	else {
		if ( window.onload != null ) {
		    var oldOnload = window.onload;
		    window.onload = function ( e ) {
			        oldOnload( e );
			        window[fnc]();
		        };
		}
		else 
		    window.onload = fnc;
	}
}

function ScrollToElement(theElement)
{
  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
                  		      
  window.scrollTo(selectedPosX,selectedPosY);
}

/************************** Telerik ****************/
//This code is used to provide a reference to the radwindow "wrapper"   
function GetRadWindow()   
{   
    if (window.radWindow == null && window.frameElement == null)
        return null;
            
    var oWindow = null;   
    if (window.radWindow) oWindow = window.radWindow;   
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;   
        return oWindow;   
}

function ajax(url, vars, callbackFunction)
{
  var request = window.XMLHttpRequest ?
      new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded"); 
 
  request.onreadystatechange = function()
  {        
    if (request.readyState == 4 && request.status == 200)
    {
      if (request.responseText&&callbackFunction!=null)
      {
          callbackFunction(request.responseText);     
      }
    }
  };
 
 request.send(vars);
    
}

function addOnloadEvent2(fnc)
{
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "load", fnc, false );
	else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", fnc );
	}
	else {
		if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			window[fnc]();
		};
		}
		else 
		window.onload = fnc;
	}
}

function createCookie(name,value,days)
            {
	            if (days)
	            {
		            var date = new Date();
		            date.setTime(date.getTime()+(days*24*60*60*1000));
		            var expires = "; expires="+date.toGMTString();
	            }
	            else
	            {
	                var expires = "";
	            }
	            document.cookie = name+"="+value+expires+"; path=/";
            }

            function eraseCookie(name)
            {
	            createCookie(name,"",-1);
            }
            
            function setStylesheetHref()
            {
                var links = document.getElementsByTagName("link");
                for(i=0; i < links.length; i++)
                {
                    // add random token to refresh css
                    var randNum = Math.floor(Math.random( ) * 100 + 1);
                    links[i].href = links[i].href + "?ver=" + randNum;
                }
            }
