function zcopyToClipboard()

{
    var content = document.getElementById('ctest');
    content.focus();
    content.select();
    CopiedTxt = document.selection.createRange();
    CopiedTxt.execCommand("Copy");
}

function ycopyToClipboard(field)
{
    var content = document.getElementById('ctest');
    content.focus();
    content.select();
//    range = content.createTextRange();
    range = content.selection.createRange();
    range.execCommand("Copy");
    window.status="Contents copied to clipboard";
    setTimeout("window.status=''",1800);
}



function copyToClipboard(meintext)
{
 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", meintext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig   om het in op te slaan
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
//   alert("Following info was copied to your clipboard:\n\n" + meintext);
   return false;
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}

function pageWidth() {
  return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
  return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function posLeft() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
function posTop() {
  return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
function posRight() {
  return posLeft()+pageWidth();
}
function posBottom() {
  return posTop()+pageHeight();
}

// Object Functions
// copyright Stephen Chapman, 4th Jan 2005
//  you may copy these functions but please keep the copyright notice as well
function objWidth(objectID) {
var obj = xDOM(objectID,0);
if(obj.offsetWidth) return  obj.offsetWidth;
if (obj.clip) return obj.clip.width;
return 0;
}
function objHeight(objectID) {
var obj = xDOM(objectID,0);
if(obj.offsetHeight) return  obj.offsetHeight;
if (obj.clip) return obj.clip.height;
return 0;
}
function objLeft(objectID) {
var obj = xDOM(objectID,0);
var objs = xDOM(objectID,1);
if(objs.left) return objs.left;
if (objs.pixelLeft) return objs.pixelLeft;
if (obj.offsetLeft) return obj.offsetLeft;
return 0;
}
function objTop(objectID) {
var obj = xDOM(objectID,0);
var objs = xDOM(objectID,1);
if(objs.top) return objs.top;
if (objs.pixelTop) return objs.pixelTop;
if (obj.offsetTop) return obj.offsetTop;
return 0;
}
function objRight(objectID) {
return objLeft(objectID)+objWidth(objectID);
}
function objBottom(objectID) {
return objTop(objectID)+objHeight(objectID);
}
function objLayer(objectID) {
var objs = xDOM(objectID,1);
if(objs.zIndex) return objs.zIndex;
return 0;
}
function objVisible(objectID) {
var objs = xDOM(objectID,1);
if(objs.visibility == 'hide' || objs.visibility == 'hidden') return 'hidden';
return 'visible';
}

// Buy Now Button Script
// copyright Stephen Chapman, 1st march 2008
// you may copy this script provided that you retain the copyright notice

var aDOM = 0, ieDOM = 0, nsDOM = 0; 
var stdDOM = document.getElementById; 
if (stdDOM) 
   aDOM = 1; 
else 
  {
    ieDOM = document.all; 
    if (ieDOM) 
       aDOM = 1; 
    else 
      {
        var nsDOM = ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) ==4)); 
        if (nsDOM) 
           aDOM = 1;
      }
  } 
function xDOM(objectId, wS) 
{
if (stdDOM) 
  return wS ? document.getElementById(objectId).style : document.getElementById(objectId); 
if (ieDOM) 
  return wS ? document.all[objectId].style: document.all[objectId]; 
if (nsDOM) 
  return document.layers[objectId];
} 
//function objWidth(objectID) {var obj = xDOM(objectID,0); if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;} function objHeight(objectID) {var obj = xDOM(objectID,0); if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;} function objLeft(objectID) {var obj = xDOM(objectID,0);var objs = xDOM(objectID,1);  if(objs.left) return objs.left; if (objs.pixelLeft) return objs.pixelLeft; if (obj.offsetLeft) return obj.offsetLeft; return 0;} function objTop(objectID) {var obj = xDOM(objectID,0);var objs = xDOM(objectID,1);  if(objs.top) return objs.top; if (objs.pixelTop) return objs.pixelTop; if (obj.offsetTop) return obj.offsetTop; return 0;} function objRight(objectID) {return objLeft(objectID)+objWidth(objectID);} function objBottom(objectID) {return objTop(objectID)+objHeight(objectID);} function objLayer(objectID) {var objs = xDOM(objectID,1); if(objs.zIndex) return objs.zIndex; return 0;} function objVisible(objectID) {var objs = xDOM(objectID,1); if(objs.visibility == 'hide' || objs.visibility == 'hidden') return 'hidden'; return 'visible';} function setObjVis(objectID,vis) {var objs = xDOM(objectID,1); objs.visibility = vis;} function toggleObjVis(objectID) {var objs = xDOM(objectID,1); var vis = objs.visibility; objs.visibility = (vis == "visible" || vis == "show") ? 'hidden' : 'visible';} function moveObjTo(objectID,x,y) {var objs = xDOM(objectID,1); objs.left = x; objs.top = y;} function moveObjBy(objectID,x,y) {var// obj = xDOM(objectID,0);var objs = xDOM(objectID,1); if (obj.offsetLeft != null) {var l = obj.offsetLeft; var t = obj.offsetTop; objs.left = l+x; objs.top = t+y;} else if (objs.pixelLeft != null) {objs.pixelLeft += x; objs.pixelTop += y;} else obj.moveBy(x,y);} function moveObjLayer(objectID,z) {var objs = xDOM(objectID,1); objs.zIndex = z;} function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;} function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;} function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();} var xxx = 0; var yyy = 0; var endPos = 0; function start() {var w = objWidth('buynow'); var h = objHeight('buynow'); xxx = 20; yyy = -h-20; endPos = (pageHeight()-objHeight('buynow'))/2; moveit(); setObjVis('buynow','visible'); setTimeout('mover()',5000);} function moveit() {var x = (posLeft()+xxx) + 'px'; var y = (posTop()+yyy) + 'px'; moveObjTo('buynow',x,y);} function mover() {if (yyy < endPos) {yyy +=2; moveit(); setTimeout('mover()',5);}} window.onload = start; window.onscroll = moveit;


/**
 * Returns the absolute X and Y positions of an object.
 * @param {HTMLObject} obj HTML Object.
 * @return {Object} Returns an accessor with .x and .y values.
 */
function getXY(obj)
{
  var curleft = 0;
  var curtop = obj.offsetHeight + 5;
  var border;
  if (obj.offsetParent)
  {
    do
    {
      // XXX: If the element is position: relative we have to add borderWidth
      if (getStyle(obj, 'position') == 'relative')
      {
        if (border = _pub.getStyle(obj, 'border-top-width')) curtop += parseInt(border);
        if (border = _pub.getStyle(obj, 'border-left-width')) curleft += parseInt(border);
      }
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    }
    while (obj = obj.offsetParent)
  }
  else if (obj.x)
  {
    curleft += obj.x;
    curtop += obj.y;
  }
  return [curleft,curtop];
}
/**
 * Returns the specified computed style on an object.
 * @param {HTMLObject} obj HTML Object
 * @param {String} styleProp Property name.
 * @return {Mixed} Computed style on object.
 */
function getStyle(obj, styleProp)
{
  if (obj.currentStyle)
    return obj.currentStyle[styleProp];
  else if (window.getComputedStyle)
    return document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);
}

function getX(oElement)
{
  var iReturnValue = 0;
  while (oElement != null) 
  {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function getY(oElement)
{
  var iReturnValue = 0;
  while (oElement != null) 
  {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function moveUpList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == 0 ) {
               alert("The first entry in the list cannot be moved up.");
            } else {
               // Get the text/value of the one directly above the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected-1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected-1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected-1].text = moveText2;
               listField[selected-1].value = moveValue2;
               listField.selectedIndex = selected-1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

function moveDownList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == listField.length-1 ) {
               alert("The last entry in the list cannot be moved down.");
            } else {
               // Get the text/value of the one directly below the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected+1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected+1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected+1].text = moveText2;
               listField[selected+1].value = moveValue2;
               listField.selectedIndex = selected+1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

function removeFromList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be removed!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be removed!");
      } else {  // Build arrays with the text and values to remain
         var replaceTextArray = new Array(listField.length-1);
         var replaceValueArray = new Array(listField.length-1);
         for (var i = 0; i < listField.length; i++) {
            // Put everything except the selected one into the array
            if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }
            if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }
            if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }
            if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }
         }
         listField.length = replaceTextArray.length;  // Shorten the input list
         for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
            listField.options[i].value = replaceValueArray[i];
            listField.options[i].text = replaceTextArray[i];
         }
      } // Ends the check to make sure something was selected
   } // Ends the check for there being none in the list
}

function onlyNumbers(evt)
{
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

  return true;
}

function checkDate(input)
{
  if (input == "") return true;
  if (input == "0000-00-00") return true;
  var validformat=/(\d{4})-(\d{2})-(\d{2})/ //Basic check for format validity
//  if(!input.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)) alert('bad');
  if(!input.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)) return true;
  var monthfield=input.split("-")[1]
  var dayfield=input.split("-")[2]
  var yearfield=input.split("-")[0]
  var dayobj = new Date(yearfield, monthfield-1, dayfield)
  if ((dayobj.getMonth()+1==monthfield)&&(dayobj.getDate()==dayfield)&&(dayobj.getFullYear()==yearfield)) return true;
  return false;
}
