//Global Functions 

function PopupWindow(strUrl, width, height, strScroll, windowName) {
	var PopupWin = window.open(strUrl,windowName,"scrollbars=" + strScroll + ",toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height)
	PopupWin.focus();
}

function GetQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}

// Nifty function to allow extra page onload events
// without interfering with/breaking any already called.
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;
  }
}// Or to pass arguments- addOnloadEvent(function(){ myFunctionName('myArgument') });

//Replaces getElementById method with $ for easy access
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}// Example usage: Use: $('a'); for one control; Use: $('a','b',obj,obj2,'c','d'); for multiple controls



function GetScrollPos() {
	if(typeof window.pageXOffset != 'undefined'){
		X = window.pageXOffset;
		Y = window.pageYOffset;
	}else{
		if((!window.document.compatMode)||
		  (window.document.compatMode == 'BackCompat')){
			X = window.document.body.scrollLeft;
			Y = window.document.body.scrollTop;
		}else{
			X =  window.document.documentElement.scrollLeft;
			Y =  window.document.documentElement.scrollTop;
		}
	}
		return(Y);
}


function GetFormArrayIndex(element) {
	var poz
	for (var i=0;i<element.form.elements.length;i++) {
		if (element===element.form.elements[i]) {
			poz = i
		}
	}
	return poz
}


function GetWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
return(myHeight);
}

function GetCookie( 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 SetCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	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() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function DeleteCookie( name, path, domain ) {
    //if (getCookie(name)) {
        SetCookie(name, "null", "Thu, 01-Jan-1970 00:00:01 GMT", path, "", "");
    //}
}

function GetCookieSubKey(cookieName,keyName){
	var cookie=unescape(GetCookie(cookieName));
	if(keyName && CookieHasSubKeys(cookieName)==true){
		var cookieData = GetCookieData(cookie);
		return cookieData[keyName];
	}else{
		return cookie;
	}
}

function GetCookieData(cookie){
	var ret=[];
	var subKeys=cookie.split("&");
	for (var i=0;i<subKeys.length;i++){
		//alert(subKeys[i]);
		var pos=subKeys[i].indexOf("=");
		if(pos!=0){
			//alert("cookieData["+subKeys[i].substring(0,pos)+']='+subKeys[i].substring(pos+1));
			ret[subKeys[i].substring(0,pos)]=subKeys[i].substring(pos+1);
		}
	}
	return ret;
}

function CookieHasSubKeys(cookieName){
    var ret=false;
    var cookie=unescape(GetCookie(cookieName));
    var subKeys=cookie.split("&");

    if(subKeys.length>=2){
    ret=true;}
    else{
    var subKeys=cookie.split("=");

    if(subKeys.length>=1){
    ret=true;}}
    return ret;
}


function SetCookieSubKey(cookieName,keyName,value,expires){
	var thisCookie=unescape(GetCookie(cookieName));
	if(thisCookie){
		if(keyName){
			//alert(keyName);
			var cookieData=GetCookieData(thisCookie);
			cookieData[keyName]=value;
			value="";
			for (var cookie in cookieData){
				value +=cookie+"="+cookieData[cookie]+"&";
			}
			if(value.charAt(value.length-1)=="&"){value=value.substring(0,value.length-1)}
		}
	}
	//alert(cookieName+"\n"+value);
	SetCookie( cookieName, value, expires, '', '', false )
}




function CreateNewFormElement(inputForm, elementName, elementValue, elementType){
    var input = document.createElement('input');
    input.setAttribute('type', elementType);
    input.setAttribute('name', elementName);
    input.setAttribute('id', elementName);
    input.value = elementValue;     
    inputForm.appendChild(input);
    return input;
}


function clearDummyText(sender, dummyValue) {
    if (sender.value == dummyValue) {
        sender.value = "";
    }
}

function setDummyText(sender, dummyValue) {
    if (sender.value == "") {
        sender.value = dummyValue;
        
    }
}


