//Popup script
function fnPopWindow(theUrl,width,height,mod,naam)
{
	toolbar = 'no';
	resizable = 'no';
	personalbar = 'no';
	locationbar = 'no';
	status = 'no';
	scrollbars='no';
	
	IE = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)) ? true : false;

	if (IE && mod=='yes')
	{
		window.showModalDialog(theUrl,window,"dialogWidth: "+width+"px; dialogHeight: "+height+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; scroll: "+scrollbars+"; resizable: "+resizable+"; status: "+status+";");
	}
	
	else
	{
		var winleft = (screen.width - width) / 2;
		var winUp = (screen.height - height) / 2;
		winUp = winUp -40;
		var winProp = 'width='+width+',height='+height+',left='+winleft+',top='+winUp+',scrollbars='+scrollbars+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar+',personalbar='+personalbar+',location='+locationbar+',status='+status+''
		if (naam=='')
		{
			naam= date.getSeconds ;
		}
		Win = window.open(theUrl, naam, winProp)
	}
}

//Display the card-print question depending on if it is a e-voucher or a normal card
function swithCardPrintTable()
{
	var objTable = document.getElementById('cardprint');
	var objSerial1 = document.getElementById('serialno1');
	var objCardTypeCard= document.getElementById('cardtype_card');
	
	
	if (objTable && objSerial1 && objCardTypeCard)
	{
		//Check on serial lenght
		var strText = objSerial1.value;
		strText = trim(strText)
		
		
		if (objCardTypeCard.checked && strText.length == 8)
		{
			objTable.style.display = 'block';
		}
		else
		{
			objTable.style.display = 'none';
		}
	}
	return false;
}

//Function to check if a string is nummeric
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
//Function to trim a string   
function trim(string){

while(string.substr(0,1)==" ")

string = string.substring(1,string.length) ;

while(string.substr(string.length-1,1)==" ")

string = string.substring(0,string.length-2) ;

return string;

}

//Check for valid input on form
function fnCheckSubmit()
{
	var strMsg = '';
	var blnError = false;
	var objForm = document.getElementById('mailform');
	if (!objForm)
	{
		blnError = true;
	}
	
	//Set screen properties
	var objswidth = document.getElementById('swidth');
	var objsheight = document.getElementById('sheight');
	var objcolors = document.getElementById('scolors');
	if (objswidth && objsheight && objcolors)
	{
		objswidth.value = screen.width;
		objsheight.value = screen.height;
		objcolors.value = screen.colorDepth;
	}
	else
	{
		blnError = true;
	}
	
	//Check on email
	var objEmail = document.getElementById('email');
	if (objEmail)
	{
		var strEmailValue = trim(objEmail.value);
		
		if (strEmailValue == '')
		{
			strMsg += '    - (1) You have not entered a email address.\r\n';
		}
		else
		{
			var x = strEmailValue;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(x))
			{
				strMsg += '    - (1) You have not entered a valid email address.\r\n';
			}
				
		}
	}
	else
	{
		blnError = true;
	}
	
	//Check on website
	var objWhichSite = document.getElementById('whichsite');
	if (objWhichSite)
	{
		var strWhichSiteValue = trim(objWhichSite.value);
		if (strWhichSiteValue == '')
		{
			strMsg += '    - (4) You have not entered a website.\r\n';
		}
	}
	else
	{
		blnError = true;
	}	
	
	//Check on cardtype
	var objCardType_card = document.getElementById('cardtype_card');
	var objcardtype_evoucher = document.getElementById('cardtype_evoucher');
	if (objCardType_card && objcardtype_evoucher)
	{
		if (!objCardType_card.checked && !objcardtype_evoucher.checked)
		{
			strMsg += '    - (5) You have not indicated if you have a Wallie card or a Wallie voucher.\r\n';
		}
	}
	else
	{
		blnError = true;
	}
	
	//Check on serialno
	var objSerial = document.getElementById('serialno1');
	if (objSerial)
	{
		//get the string
		var strText = objSerial.value;
		
		//Trim the spaces
		strText = trim(strText);
		
		//Check if the string is numeric
		if (!IsNumeric(strText))
		{
			strMsg += '    - (6) Only numbers can occur in the serial number\r\n';	
		}
		
		//Check on lenght
		var intLenght = strText.length;
		if (intLenght != 8 && intLenght != 16)
		{
			strMsg += '    - (6) The serial number is either 8 or 16 digits.\r\n';	
		}
	
	}
	else
	{
		blnError = true;
	}
	
	//Check on 2nd serialno
	var objSerial2 = document.getElementById('serialno2');
	if (objSerial2)
	{
		//get the string
		var strText2 = objSerial2.value;
		
		//Trim the spaces
		strText2 = trim(strText2);
		
		//First check if something is filled in
		if (strText2 != '')
		{
			
			//Check if the string is numeric
			if (!IsNumeric(strText2))
			{
				strMsg += '    - (7) If you enter a second serial number, it can only consist of numbers.\r\n';	
			}
			
			//Check on lenght
			var intLenght2 = strText2.length;
			if (intLenght2 != 8 && intLenght2 != 16)
			{
				strMsg += '    - (7) If you enter a second serial number, it must be either 8 or 16 digis.\r\n';	
			}
		}
	
	}
	else
	{
		blnError = true;
	}
	
	//Check on cardprint
	var objcardprint_wallie = document.getElementById('cardprint_wallie');
	var objcardprint_habbo = document.getElementById('cardprint_habbo');
	if (objCardType_card && objcardprint_wallie && objcardprint_habbo)
	{	
		
		var objSerial1 = document.getElementById('serialno1');
		var strText = objSerial1.value;
		strText = trim(strText)		

		if (objCardType_card.checked && strText.length == 8)
		{
			//Check on value
			var objvalue_05 = document.getElementById('value_05');
			var objvalue_10 = document.getElementById('value_10');
			var objvalue_20 = document.getElementById('value_20');
			var objvalue_50 = document.getElementById('value_50');
			if (objvalue_05 && objvalue_05 && objvalue_05 && objvalue_05)
			{
				if (!objvalue_05.checked && !objvalue_10.checked && !objvalue_20.checked && !objvalue_50.checked)
				{
					strMsg += '    - (8) You have not entered the value of the card .\r\n';	
				}
			}
			else
			{
				blnError = true;
			}

			//check on print
			if (!objcardprint_wallie.checked && !objcardprint_habbo.checked)
			{
				strMsg += '    - (9) You have not selected if you have a Wallie or Habbo card.\r\n';	
			}
		}
	}
	else
	{
		blnError = true;
	}
	
	//Display message
	if (!blnError)
	{
	
		if (strMsg != '')
		{
			strMsg = 'Your question could not be sent because:\r\n\r\n' + strMsg;
			alert(strMsg);
		}	
		else
		{
			objForm.submit();
		}
	}
	else
	{
		alert('An error has occured');
	}
	
}

function fnThankYou()
{
	var objForm = document.getElementById('mailform');
	var objthanksmessage = document.getElementById('thanksmessage');
	var objReset = document.getElementById('resetten');
	
	if (objForm && objthanksmessage && objReset)
	{
		objthanksmessage.style.display = 'block';
		objForm.style.display = 'none';
		objReset.click();		
	}
}