/*
 ************************************************************ 
 *  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;
}



// ------------------------------ NIB (JavaScript)
// --------------------------------

function isNIB(sNIB){
var iX, iMult, sCheckDigit;
var sResult;

iMult = 0;

sCheckDigit = sNIB.substr(19, 2);

for (iX = 0; iX < 19; iX++)
{
iMult = ((iMult + parseInt(sNIB.substr(iX, 1))) * 10) % 97;
}

iMult = 98 - ((iMult * 10) % 97);

sResult = iMult.toString();

if (iMult < 10)
sResult = "0" + sResult;
if (!(sResult == sCheckDigit))
{
return false;
}
else
{
return true;
}
}

