/*
 ************************************************************ 
 *  JavaScript Collection, SOS-Childrensvillage.
 * Revision 0.0; Edwertz.M 2003-04-14, Initial Creation
 ************************************************************
 */

function closeWindow(){
 window.close();
 //alternatively: self.close();
}


function printDocument(){
 bV = parseInt(navigator.appVersion);
 if (bV >= 4) window.print();
}


/************************************************************ 
 * Popup Window Functions:
 * First the specific functions are listed thereafter the standard functions
 *(With increasingly complexity type of the pop-up windows)
 ************************************************************ 
 */ 

function openPopup(popurl, title, params){
 window.open(popurl,title,params);
}

//SOS-Specific functions
function openPopupPrinterFriendly(popurl){
 var width=600;
 var height=600;
 openPopupMedium(popurl,width,height);
}


//General Functions
function openPopupDialog(popurl, width, height){
 var params = 'width=' + width + ',height=' + height;
 window.open(popurl,'',params);
}

function openPopupSimple(popurl, width, height){
 var params = 'width=' + width + ',height=' + height;
 params = params + ',scrollbars,menubar,resizable';
 window.open(popurl,'',params);
}

function openPopupMedium(popurl, width, height){
 var params = 'width=' + width + ',height=' + height;
 params = params + ',toolbar,scrollbars,menubar,resizable';
 window.open(popurl,'',params);
}

function openPopupNormal(popurl, width, height){
 var params = 'width=' + width + ',height=' + height;
 params = params + ',toolbar,location,directories,status,scrollbars,menubar,resizable';
 window.open(popurl,'',params);
}



//Function to view as a template how other openPopup functions can be done
function openPopupDemoTemplate(popurl, width, height){
 var params = 'width=' + width + ',height=' + height;
 params = params + ',toolbar'; // The standard toolbar 
 //params = params + ',location'; //The URL Adress field
 //params = params + ',directories'; //The favorite links
 //params = params + ',status';
 params = params + ',scrollbars';
 params = params + ',menubar';
 params = params + ',resizable';
 
 window.open(popurl,'',params);
}




/************************************************************ 
 * URL-parameter and Linking Functions:
 * Used to re-transfer (copy) URL-parameters of the present location into a new link
 ************************************************************ 
 */ 

//Copying Broad Vision Parameters
function paramLinkBV(site) {
 var param=new Array('BV_EngineID','BV_SessionID');//URL-parameters to transfere
 iLink(site, param);
}

//Copying Broad Vision Parameters + PartnerIDs
function paramLinkBVAndPartner(site) {
 var param=new Array('BV_EngineID','BV_SessionID','jwppid','jwpbid');//URL-parameters to transfere
 iLink(site, param);
}


function paramLink(site, param) {
 /* Javascript Function "iLink" to use for internal links.
  * J.Scudder 2002, M.Edwertz 2003-Feb
  * Takes an URL as argument, and adds one or more URL-parameters and their values to a target URL, and jumps to the target URL.
  */
 var separator='&';
 
 //If no '&' is found, check for '%26'. '%26' in URL corresponds to the amphersand '&'
 if (location.search.indexOf('&') == -1)
 	separator='%26';
 var keys =location.search.substring(1, location.search.length).split(separator);
 var paramValue= new Array(param.length);
 
 for (var i = 0; i < param.length; i++)
 	paramValue[i]='';
 
 for (var x = 0; x < keys.length; x++)
 {
   for (var i = 0; i < param.length; i++)
   { 	if(keys[x].substring(0, param[i].length) == param[i]) 
     		paramValue[i] = keys[x].substring(param[i].length + 1, keys[x].length);
   }
 }

 var l = site;
 for (var i = 0; i < param.length; i++)
 {	if (paramValue[i] != '')
 		l += '&'+param[i]+'='+paramValue[i];
 }	
 location = l;
}

function checkRadioByValue(formName, radioName, value) {
	var radioField = document.forms[formName].elements[radioName];
	for (i=0;i<radioField.length;i++) {
		if (radioField[i].value==value) {
			radioField[i].checked=true;
		}
	}
}

function setHiddenCheckboxField(a, name) {
	frm = a.form;
	if (a.checked==true) {
		frm.elements[name].value = "on";
	} else {
		frm.elements[name].value = "";
	}
}
function textlimit(Obj,maxcount)
{
    function c_len(){
        if(this.value.length > this.maxcount && this.maxcount != 0)
            return false;
    }

   function check(){
        if (this.value.length  > this.maxcount && this.maxcount != 0)
            this.value = this.value.substr(0,this.maxcount);
    }

    Obj.maxcount  = maxcount;                                                                              
    Obj.onkeypress= c_len;
    Obj.onkeyup   = check;
    Obj.onfocus   = check;
    Obj.onblur    = check;
    Obj.onmouseup = check;


/*************** OTHER USED / NEEDED FUNCTIONS ***************************/
function getObj( ref ) { if( document.getElementById( ref ) != null )//W3C/
return document.getElementById(ref); else if(document.all[ref]!=null)//IE5/
return document.all[ ref ]; else if( document.layers[ ref ] != null )//NN4/
return document.layers[ref]; else alert('Object "'+ref+'" not Found')//ERR/
}/************************************************************************/
}

