// JavaScript Document

function checkphone(s)
	{

		if(s == 0)
		{  
			document.getElementById('preferredtime').style.display='none';
		}
		else
		{
			document.getElementById('preferredtime').style.display='block';
		}
		return false;
		
	}
	
	
	function checke(url) {

  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
	
		if(http.responseText!="0")
		{
			alert("An existing member is using this email address, please try another. If you have forgotten your password please go to the login screen and request a reminder.");
			$('email').value = "";
			$('email').focus();
		}
    }
  }
  http.send(null);
  
}

	function checkex(s)
	{

		if(s == "I'd like to schedule some assessment training")
		{  
			document.getElementById('rm').style.display='block';
			document.getElementById('rn').style.display='block';
			document.getElementById('rtext').innerHTML = "I'd like training in the following assessment(s)";
			
		
			
			
		}
		else
		{
			document.getElementById('rm').style.display='none';
			document.getElementById('rn').style.display='none';
			
			
			
		}
			if(s == "I'd like advice about scoring and interpretation")
		{  
			document.getElementById('rtext').innerHTML = "I am using the following assessment(s)";
			
			
		}
			if(s == "I'd like advice on an assessment" || s == "I'd like a product demonstration" )
		{  
			document.getElementById('rtext').innerHTML = "I am interested in the following assessments";
		
			
		}
		else
		{
			document.getElementById('ta1').style.display='none';
			document.getElementById('ta2').style.display='none';
			document.getElementById('ta3').style.display='block';
		}
		return false;
		
	}

var http = false;
var http2 = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 

if(navigator.appName == "Microsoft Internet Explorer") {
  http2 = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http2 = new XMLHttpRequest();
} 

function replacehtml(id,url) {

  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(id).innerHTML = http.responseText;
	  if(http.responseText.search('alert') > 0)
	  {
		  alert("Sorry, promo code not recognised");
	  }
    }
  }
  http.send(null);
 
}


function replacehtml2(id,url) {

  http2.open("GET", url, true);
  http2.onreadystatechange=function() {
    if(http2.readyState == 4) {
      document.getElementById(id).innerHTML = http2.responseText;
    }
  }
  http2.send(null);
 
}

function callhtml(url) {

  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
    }
  }
  http.send(null);
  
}

var numb = "0123456789";
function res(t,v){
var w = "";
for (i=0; i < t.value.length; i++) {
x = t.value.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
t.value = w;
}

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;
   
   }
   
   var valf = "";
 function setval(s)
   {
	   
	   if(valf != s)
	   {
	   if(valf=="cc")
	   {
		   sprytextfield1u.reset();
		   sprytextfield1u.destroy();
		   sprytextfield2u.reset();
		   sprytextfield2u.destroy();
		   sprytextfield3u.reset();
		   sprytextfield3u.destroy();
		   sprytextfield4u.reset();
		   sprytextfield4u.destroy();
		   sprytextfield14u.reset();
		   sprytextfield14u.destroy();
		   sprytextfield7u.reset();
		   sprytextfield7u.destroy();
		      sprytextfield8u.reset();
		   sprytextfield8u.destroy();
		     sprytextfield9u.reset();
		   sprytextfield9u.destroy(); 
		    sprytextfield5u.reset();
		   sprytextfield5u.destroy(); 
		   sprytextfield6u.reset();
			sprytextfield6u.destroy();
		   sprytextfield10u.reset(); 
		   sprytextfield10u.destroy(); 
		  spryselect1u.reset();
		   spryselect1u.destroy();
		   spryselect2u.reset();
		  spryselect2u.destroy();
		   
		   
	   }
	    if(valf=="day")
	   {
		
		   sprytextfield11u.reset();
		  sprytextfield11u.destroy();
		   
		   
	   }
	   
	   valf = s;
	   
	   if(valf=="cc")
	   {
		   
		  sprytextfield1u = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["change"], hint:"Card Holder Name *"});
sprytextfield2u = new Spry.Widget.ValidationTextField("sprytextfield2", "integer", {hint:"Card Number * (between 13-16 characters)", validateOn:["change"], minChars:13, maxChars:16, useCharacterMasking:true});
	 sprytextfield3u = new Spry.Widget.ValidationTextField("sprytextfield3", "custom", {pattern:"00", hint:"MM", validateOn:["change"], useCharacterMasking:true});
	sprytextfield4u = new Spry.Widget.ValidationTextField("sprytextfield4", "custom", {pattern:"00", hint:"YY", validateOn:["change"], useCharacterMasking:true});
	 sprytextfield14u = new Spry.Widget.ValidationTextField("sprytextfield14", "integer", {hint:"", validateOn:["change"], useCharacterMasking:true, minChars:3, maxChars:4});
	 sprytextfield7u = new Spry.Widget.ValidationTextField("sprytextfield7", "none", {validateOn:["change"], hint:"Organisation *", maxChars:30});
	 sprytextfield8u = new Spry.Widget.ValidationTextField("sprytextfield8", "none", {hint:"Street Address *", maxChars:30, validateOn:["change"], isRequired:false});
	 sprytextfield9u = new Spry.Widget.ValidationTextField("sprytextfield9", "none", {hint:"Suburb * ", validateOn:["change"], maxChars:20});
	 sprytextfield5u = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {hint:"Department (if applicable)", maxChars:30, isRequired:false, validateOn:["change"]});
	 sprytextfield6u = new Spry.Widget.ValidationTextField("sprytextfield6", "none", {isRequired:false, validateOn:["change"], hint:"Address Line 4"});
	 spryselect1u = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["change"]});
	 spryselect2u = new Spry.Widget.ValidationSelect("spryselect2");
	 sprytextfield10u = new Spry.Widget.ValidationTextField("sprytextfield10", "integer", {validateOn:["change"], hint:"Postcode *"});
	   }
	   if(valf =="day")
	   {
		   sprytextfield11u = new Spry.Widget.ValidationTextField("sprytextfield11", "none", {hint:"30 Day Account Number", validateOn:["change"]});
		  // alert('day');
	   }
	   }
   }
   function paym(e){
		
		
		if(e == 'cc')
		{
		$('cc').tween('height', '400');
		$('dd').tween('height', '0');
		$('day').tween('height', '0');
		setval('cc');
		}
			
			if(e == 'dd')
		{
		$('cc').tween('height', '0');
		$('dd').tween('height', '190');
		$('day').tween('height', '0');
		setval('dd');
		}
		
			if(e == 'day')
		{
		$('cc').tween('height', '0');
		$('dd').tween('height', '0'); 
		$('day').tween('height', '160');
		setval('day');
		}
		
		return false;
		}

function ucart(num)
{
	window.cartitems = window.cartitems + num;
	
	if(window.cartitems > 0)
	{
			document.getElementById('cartlink').style.display = "inline";
			document.getElementById('cartlinka').innerHTML = "View shopping cart (" + window.cartitems + " items)";
	}
	else
	{
		document.getElementById('cartlink').style.display = "none";
	}
	
}
