
/*
----  CAPTCHA  ----
*/

var sHiddenInputNamePrefix = 'h_captcha_';
var sHiddenInputNameSeparator = '!';
var sImageCaptchaAsp = '/cms/publish/content/captcha.asp';

function DrawCaptcha(sImgName, sCodeName)
{

  var oImgCaptcha = document.getElementById(sImgName);
	var oParent = oImgCaptcha.parentNode;

	// firefox & IE
	var sUniqueID = oImgCaptcha.getAttribute('qid');
  var d = new Date();
	
	if (sUniqueID == null)
	{	 
		if (oImgCaptcha.sourceIndex) 
		{ // IE
	    sUniqueID = oImgCaptcha.sourceIndex.toString() + '_' + d.getMilliseconds();
		}	
		else
		{ // Firefox
	    sUniqueID = d.getMilliseconds() + '_' + sImgName.substr(sImgName.length - 3);
		}
	}


  var oCodeCaptcha = document.getElementById(sCodeName);
	if (oCodeCaptcha)
	{ oCodeCaptcha.name = sHiddenInputNamePrefix + sImgName + 
							sHiddenInputNameSeparator + sUniqueID +
							sHiddenInputNameSeparator + sCodeName;
	}
	
	var oExistsHiddenButton = document.getElementById(sHiddenInputNamePrefix + sImgName);
  if (oExistsHiddenButton)
	{
	} 
	else
	{ 
	  var newHiddenInput = document.createElement("INPUT");
 	  newHiddenInput.value = sUniqueID; 
  	newHiddenInput.name = sHiddenInputNamePrefix + sImgName;
  	newHiddenInput.id = sHiddenInputNamePrefix + sImgName;
	newHiddenInput.type = 'hidden';
	oParent.insertBefore(newHiddenInput, oParent.lastChild);
		
  	oImgCaptcha.src = sImageCaptchaAsp + '?cid=' + sUniqueID + '&PreventCachingCode=' + d.valueOf().toString();
  }				
	
	
}

function SetUniqueIDShortTime(sImgName)
{
  var oImgCaptcha = document.getElementById(sImgName);

  var d = new Date();
	var sUniqueID;
  if (oImgCaptcha.sourceIndex) 
  {  // IE
     sUniqueID = oImgCaptcha.sourceIndex.toString() + '_631';
  }	
  else
  {  // Firefox
     sUniqueID = '631_' + sImgName.substr(sImgName.length - 3);
  }
	oImgCaptcha.setAttribute('qid', sUniqueID);
}

function RenewCaptcha(sImgName)
{
  var oImgCaptcha = document.getElementById(sImgName);
	var sUniqueID = oImgCaptcha.getAttribute('qid');
	// 'http://' + document.location.host + 
	var d = new Date();
	oImgCaptcha.src = sImageCaptchaAsp + '?cid=' + sUniqueID + '&special=renew&PreventCachingCode=' + d.valueOf().toString(); 
}

function RedrawCaptcha(sImgName)
{
  var oImgCaptcha = document.getElementById(sImgName);
	var sUniqueID = oImgCaptcha.getAttribute('qid');
	// 'http://' + document.location.host + 
	var d = new Date();
	oImgCaptcha.src = sImageCaptchaAsp + '?cid=' + sUniqueID + '&PreventCachingCode=' + d.valueOf().toString(); 
}

function FormVerzender(sImgName, sCodeName)
{
 
  var oImgCaptcha = document.getElementById(sImgName);
	var oCodeCaptcha = document.getElementById(sCodeName);
	if (oImgCaptcha)
	{
	  oImgCaptcha.name = sHiddenInputNamePrefix + oImgCaptcha.id;
		oImgCaptcha.id = oImgCaptcha.name; 
	  setQueryStringValuesInForm(oImgCaptcha.id);	
		oImgCaptcha.id = sImgName;
	}
	if (oCodeCaptcha)
	{
	  oCodeCaptcha.name = escape(oImgCaptcha.name + sHiddenInputNameSeparator + oImgCaptcha.value + sHiddenInputNameSeparator + oCodeCaptcha.id);
		oCodeCaptcha.id = oCodeCaptcha.name; 
  	setQueryStringValuesInForm(oCodeCaptcha.id);
		oCodeCaptcha.id = sCodeName;
		// zonder escape	
	  oCodeCaptcha.name = oImgCaptcha.name + sHiddenInputNameSeparator + oImgCaptcha.value + sHiddenInputNameSeparator + oCodeCaptcha.id;
	}
}