// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// SAMSON IT Custom Javascript functions for CodeCharge Studio
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

 var OMO_COLOR = '#A29277';
// var OMO_COLOR_BE = '#EFEEF2';

/**
 * Swaps two forms, setting one invisible and the other
 * visible using the css property display
 */
function swapForms(form1, form2)
{
  if( form1.style && !form1.style.display )
  {
    // display porperty has never been set yet
    form1.style.display = "block";
  }

  if(form1.style.display == "block")
  {
    form1.style.display = "none";
    form2.style.display = "block";
  }
  else
  {
    form2.style.display = "none";
    form1.style.display = "block";
  }
}

/**
 * load HtmlArea
 */
function loadHtmlarea() {
_editor_url = "../../customcode/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
}

/**
 * Opens plain window with url.
 */
	function openUrlInWindow(url,windowName,width,height,parameters)	{	//
		var standardParameters = "status=0,menubar=0,resizable=1,location=0,directories=0,scrollbars=1,toolbar=0";
		if (parameters == "") { parameters = standardParameters; }
		regularWindow = window.open(url,windowName,"height=" + height + ",width=" + width + "," + parameters);
		regularWindow.focus();
		return false;
	}

function setRowstyle (oRow, bSetting) {
	// highlites the row (and its cells) using style
	if (isIE) {
		var i, imax, cChilds, oChild;
	
		cChilds = oRow.children;
		imax = cChilds.length;

		oRow.style.backgroundColor = (bSetting ? OMO_COLOR : "")
		
		for (i=0;i<imax;i++) {
			oChild = cChilds[i];
			oChild.style.backgroundColor = (bSetting ? OMO_COLOR : "")
		}
	}
}

function setCellstyle (oCell, bSetting) {
	// highlites the row (and its cells) using style
	if (isIE) {
		oCell.style.backgroundColor = (bSetting ? OMO_COLOR : "");
	}
}

function setSingleRowStyle( oRow, bSetting )
{
  var i;

  oRow.style.backgroundColor = (bSetting ? OMO_COLOR : "")
  

  for( i=0; i<oRow.cells.length; i++ )
  {
    oRow.cells[i].style.backgroundColor = (bSetting ? OMO_COLOR : "");
  }
}

function setCompoundRowstyle (oCompoundRow, bSetting) {
  var rowIndex, tableSection;

  // first do the row itself
  setSingleRowStyle( oCompoundRow, bSetting );
  
  // see if it is a compound row, i.e. if the first cell spans more than one row
  rowIndex = oCompoundRow.rowIndex;
  tableSection = oCompoundRow.parentNode;

  if( (oCompoundRow.cells[0].rowSpan > 1) &&
      (tableSection.rows.length > rowIndex) )
  {
    setSingleRowStyle( tableSection.rows[rowIndex+1], bSetting );
  }
}


function clickRow(oRow) {
  // clicks the first link in the row
  var oLink;
  
  oLink = oRow.getElementsByTagName("a");
  document.location = oLink[0].href;
}

function Mod(a, b) { return a-Math.floor(a/b)*b }
function Div(a, b) { return Math.floor(a/b) }

function normalizeTime(oTextbox) {
	sVal = oTextbox.value;
	aVal = sVal.split(/\W/);

	iHour = null;
	iMinute = 0;
	
	if (sVal.length == 4) { // eg. 2130 -> 21:30
		iHour = Div(sVal, 100);
		iMinute = Mod(sVal, 100);
	} else {
		switch (aVal.length) {
			case 1:
				iHour = aVal[0];
				break;
			case 2:
				iHour = aVal[0];
				iMinute = aVal[1];
				break;
		}
	}

	if (sVal.length > 0 && iHour != null)	{
		if (iHour > 23) iHour = 0;
		if (iMinute > 59) iMinute = 0;
	
		sHour = zeros(iHour);
		sMinute = zeros(iMinute);
		
		oTextbox.value = sHour+":"+sMinute;
	}

}
/*
 * Convert all comma's to dots, round to two decimals
 */
function normalizeFloat(oTextbox, iDecimals) {
	// if there are no comma's do nothing, proceed to rounding the number
	// if there are any comma's, remove all points (10.000,00 > 10000,00)
	// replace all comma's with points (10000,00 > 10000.00)
	// round the number to iDecimals.
}

function normalizeDate(oTextbox) {
	sVal = oTextbox.value;
	aVal = sVal.split(/\W/);
	
	iYear = 0;
	
	switch (aVal.length) {
		case 1:
			iDate = aVal[0];
			
			d = new Date();
			iMonth = d.getMonth();
			iYear = d.getFullYear();
			break;
		case 2:
			iDate = aVal[0];
			iMonth = aVal[1]-1;

			d = new Date();
			iYear = d.getFullYear();
			break;
		case 3:
			iDate = aVal[0];
			iMonth = aVal[1]-1;
			iYear = aVal[2];
			
			if (iYear.length < 3) {
				if (iYear < 70) {
					iYear = 2000 + Number (iYear);
				} else {
					iYear = 1900 + Number (iYear);
				}
			}
			
			break;
	}
	
	if (iYear != 0 && sVal.length > 0)	{
		oDate = new Date(iYear, iMonth, iDate);
		sDay = zeros(oDate.getDate());
		sMonth = zeros(oDate.getMonth()+1);
		
		if (!isNaN(oDate.getFullYear())) {
			oTextbox.value = sDay+"-"+sMonth+"-"+oDate.getFullYear();
		}
	}
}

function normalizeDateMMYYYY(oTextbox) {
	sVal = oTextbox.value;
	aVal = sVal.split(/\W/);
	
	iYear = 0;
	iDate = 1;
	
	switch (aVal.length) {
		case 1:
			iMonth = aVal[0]-1;
			
			d = new Date();
			iYear = d.getFullYear();
			break;
		case 2:
			iMonth = aVal[0]-1;
			iYear = aVal[1];
			
			if (iYear.length < 3) {
				if (iYear < 70) {
					iYear = 2000 + Number (iYear);
				} else {
					iYear = 1900 + Number (iYear);
				}
			}
			
			break;
	}
	
	if (iYear != 0 && sVal.length > 0)	{
		oDate = new Date(iYear, iMonth, iDate);
		sDay = zeros(oDate.getDate());
		sMonth = zeros(oDate.getMonth()+1);
		
		if (!isNaN(oDate.getFullYear())) {
			oTextbox.value = sMonth+"-"+oDate.getFullYear();
		}
	}
}

function normalizeDateYYYY(oTextbox) {
	sVal = oTextbox.value;
	aVal = sVal.split(/\W/);
	
	iYear = 0;
	
	switch (aVal.length) {
		case 1:
			iYear = aVal[0];
			iMonth = 1;
			iDate = 1;
			
			if (iYear.length < 3) {
				if (iYear < 70) {
					iYear = 2000 + Number (iYear);
				} else {
					iYear = 1900 + Number (iYear);
				}
			}
			break;
	}
	
	if (iYear != 0 && sVal.length > 0)	{
		oDate = new Date(iYear, iMonth, iDate);
		sDay = zeros(oDate.getDate());
		sMonth = zeros(oDate.getMonth()+1);
		
		if (!isNaN(oDate.getFullYear())) {
			oTextbox.value = oDate.getFullYear();
		}
	}
}

function zeros(sDay) {
	sDay = sDay.toString();
	if (sDay.length == 1) {
		sDay = "0"+sDay;
	}
	return sDay;
}

// Met dit script kan je een 'variabele fotolijst' window openen, welke met een click op de foto weer wordt gesloten.
//  Laad Scriptje: 
//  <SCRIPT LANGUAGE="JavaScript" SRC="fotolijst.js"></SCRIPT>
// 
// In Linkje (de x & y zijn de afmetingen van de foto in pixels)
//  <A HREF="JavaScript:openFoto('gpics/ski952.jpg', x, y)
// 
// Fotolijst.html  moet er zo uitzien:
//    <HTML>
//    <HEAD><TITLE>B'vo Fotolijst</TITLE></HEAD>
//    <BODY bgcolor="#000000">
//    
//    <script language="JavaScript">
//    
//    document.write( "<a href='JavaScript:self.close();'><img src="+location.search.substring(1, location.search.length )+" border=0></a>");
//    
//    </script>
//    
//    </body>
//    </HTML>
function openFoto( location, width, height )
{
	var win = window.open( 'fotolijst.html?'+location, '_blank', 'resizable=no,scrollbars=no,status=0,width='+(width+23)+',height='+(height+23) );
}


function selectAll(formObj, fieldName, isInverse)
// Selecteer alle opties in een multi-select (of inverteer de selectie).
// invoer van form en afzonderlijk de naam van de (multi)checkbox omdat (ccs) '[]' in de naam opneemt en 
// javascript hier niet mee uit de voeten kan...
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox' && fldObj.name == fieldName)
      { 
         if(isInverse)
            fldObj.checked = (fldObj.checked) ? false : true;
         else fldObj.checked = true; 
       }
   }
}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }


/*
 * Get a GET variable from the URL
 */   
 function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }

