/*---
 
 Basis functions
 author   : David Safar
 revision : 1.00 01.08.2006
  
 (c)2006 Copyright Trisoft Technologies. All rights reserved.
 
---*/

var check = false;
var what = null;

// trimming
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.trimStart = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.trimEnd = function() {
	return this.replace(/\s+$/,"");
}

// padding
String.prototype.padLeft = function(padString, length) {
	var str = this;
    while (str.length < length)
        str = padString + str;
    return str;
}
String.prototype.padRight = function(padString, length) {
	var str = this;
    while (str.length < length)
        str = str + padString;
    return str;
}

function print_r(theObj,indent){
    var output='';
    if (indent == undefined) { indent = ' '; } else { indent += ' '; }
    if(theObj.constructor == Array || theObj.constructor == Object) {
    for(var p in theObj){
      if(theObj[p].constructor == Array|| theObj[p].constructor == Object){
        var type = (theObj[p].constructor == Array) ? 'Array' : 'Object';
        output += indent+"["+p+"]("+type+")=>\n";
        output += print_r(theObj[p],indent);
      } else { output += indent+"["+p+"]:"+theObj[p]+"\n"; }
      }
    }
    return output;
}

function checkEnter(e){ 
    var characterCode;
    if(e && e.which){ //NN4
        e = e;
        characterCode = e.which;
    } else{
        e = event;
        characterCode = e.keyCode;
    }
    if(characterCode == 13){
        return false;
    }else{
        return true;
    }
}

// Functions
function toggle(node) {
   if (node.nextSibling.style.display == 'none') {
		node.nextSibling.style.display = 'block';
		node.className = "minus";
	} else 	{
		node.nextSibling.style.display = 'none';
		node.className = "plus";
	}
}

function clean(obj,val) {
    if ( obj.value == val ) {
        obj.value='';
    }
    
}

function detect() {
	if (document.getElementById) {
		layerRef="document.getElementByID";
		styleSwitch=".style";
		visibleVar="visible";
		what="dom1";	
	} else if(document.all) {
    layerRef="document.all";
    styleSwitch=".style";
    visibleVar="visible";
    screenSize = document.body.clientWidth + 18;
    what ="ie4";
	} else if (document.layers) {
		layerRef="document.layers";
		styleSwitch="";
		visibleVar="show";
		screenSize = window.innerWidth;
		what ="ns4";
	} else {
		what="none";
		newbrowser = false;
	}
	check = true;
}  

//---( the layer visibility on
function show(layerName,displayType) {
    displayType = displayType || "block";
    if (document.getElementById) {	
	    document.getElementById(layerName).style.display=displayType;
	    document.getElementById(layerName).style.visibility="visible";  
    } else if (document.all || document.layers ) {
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="' + displayType + '"');
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');  		
    }
} 

//---( the layer visibility off
function hide(layerName) {
    if (document.getElementById) {	
	    document.getElementById(layerName).style.display="none";
	    document.getElementById(layerName).style.visibility="hidden";  
    } else if (document.all || document.layers ) {
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"');
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');  		
    }
}

function SelectAllCheckboxes(spanChk){
    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
    var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
    xState=theBox.checked;

    elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
    if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
    {
    //elm[i].click();
    if(elm[i].checked!=xState)
        elm[i].click();
    //elm[i].checked=xState;
    }
    //theBox.checked="";
}

function setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  } else {

    var current_date = new Date;
    var cookie_year = current_date.getFullYear ( ) + 1;
    var cookie_month = current_date.getMonth ( );
    var cookie_day = current_date.getDate ( );

    var expires = new Date ( cookie_year, cookie_month, cookie_day );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}
