function smartyesno(pg,ms) {
	if (confirm(ms)) {
		document.location = pg;
	}
}


function selecturl(s) 
{
  var gourl = s.options[s.selectedIndex].value;
  if ((gourl != null) && (gourl != "") )
  {
    window.top.location.href = gourl;
  }
}


function newWindow(newContent,w,h)
{
	win = 'right=0, top=20, ' + 'width=' + w + ', height=' + h + ', toolbar=no, scrollbars=yes, resizable=yes';
	winContent = window.open(newContent, 'nextWin', win);
	if (winContent.blur) winContent.focus();
}


function disableForm(theform)
{
	if (document.all || document.getElementById) 
	{
		for (i = 0; i < theform.length; i++)
		{
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}
		setTimeout('alert("Your form has already been submitted - please do not press the button again")', 2000);
		return true;
	}
	else
	{
		alert("Your form has already been submitted - please do not press the button again");
		return false;
  }
}

function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		countfield.value = maxlimit - field.value.length;
}

function toggleVisibility(block) {
	if ( (document.getElementById(block).style.display=="none") || (document.getElementById(block).style.display=="") ){
		document.getElementById(block).style.visibility="visible";
		document.getElementById(block).style.display="block";
	}
	else {
		document.getElementById(block).style.visibility="hidden";
		document.getElementById(block).style.display="none";
	}
}


function validatestreamform() {

	var frm = document.forms["payform"];										// Form
	var frmpaymentmethod = frm.elements["paymentmethod"];		// Type of credit card (required)
	var frmcardname = frm.elements["cardname"];							// Name on credit card (required)
	var frmcardnumber = frm.elements["cardnumber"];					// Number on credit card (required)
	var frmexpirydatem = frm.elements["expirydatem"];				// Expiry Date Month (required)
	var frmexpirydatey = frm.elements["expirydatey"];				// Expiry Date Year (required)
	var frmstartdatem = frm.elements["startdatem"];					// Start Date Month (required)
	var frmstartdatey = frm.elements["startdatey"];					// Start Date Year (required)
	var frmissuenumber = frm.elements["issuenumber"];				// Issue Number (required)
	var frmcvc = frm.elements["cvc"];												// card verification code (required)
	var frmholderspcod = frm.elements["holderspcod"];				// Cardholder's Postcode
	var frmsubmit = frm.elements["paynow"];									// Submit Button
	
	// Get the valueof the card type
	var varcardtype = frmpaymentmethod.options[frmpaymentmethod.selectedIndex].value;

	// Make sure that a card type has been chosen
	if ( varcardtype == 0 ) {
		alert("Please select the payment method");
		return false;
	}

	// Name on credit card
	if ( (frmcardname.value.length == 0) ) {
		alert("Please enter your name as it appears on your credit card");
		return false;
	}
	
	// Number on credit card
	if ( (frmcardnumber.value.length < 10) ) {
		alert("Please enter your card number correctly");
		return false; IsNumeric
	}
	if ( ! IsNumeric(frmcardnumber.value) ) {
		alert("Please enter your card number correctly");
		return false; 
	}
	
	// Credit card expiry date (required)
	if ( (frmexpirydatem.options[frmexpirydatem.selectedIndex].value == 0) || (frmexpirydatey.options[frmexpirydatey.selectedIndex].value == 0) ) {
		alert("Please enter the credit card expiry date correctly");
		return false;
	}
	
	// CVC checker
	if ( (frmcvc.value.length != 0) && (frmcvc.value.length != 3) ) {
		alert("If you are entering the card security code then this is three-digit value printed on the signature panel on the back following the credit card account number");
		return false;
	}
	if ( (! IsNumeric(frmcvc.value)) && (frmcvc.value.length == 3) ) {
		alert("If you are entering the card security code then this is three-digit value printed on the signature panel on the back following the credit card account number");
		return false;
	}

	//If this is switch or solo then we need either (issue number) OR (start date and issue number)
	if ( (varcardtype == 'SWITCH-SSL') || (varcardtype == 'SOLO_GB-SSL') ) {

		// If this doesn't have a start date then it requires an issue number
		if ( (frmstartdatem.options[frmstartdatem.selectedIndex].value == 0) || (frmstartdatey.options[frmstartdatey.selectedIndex].value == 0) ) {
		
			// Check issue number
			if (  ! IsNumeric(frmissuenumber.value) ) {
				alert("If you are paying by Maestro, Switch or Solo then you must enter the issue number. If no issue number exists on your card, the start date must be entered above and leave the issue number box empty");
				return false;
			}


		}


	}
	
	// If we have made it this far then disable the submit button and do an alert
	frmsubmit.value = 'Please wait...!';
	frmsubmit.disabled = true;

	return true;

}

// Hide and show startdate and issue number depending on whether they have been chosen or not
function hideshowswitchsolo() {

	var frm = document.forms["payform"];										// Form
	var frmpaymentmethod = frm.elements["paymentmethod"];		// Type of credit card (required)
	
	var aa = document.getElementById('aa');
	var ab = document.getElementById('ab');
	var ac = document.getElementById('ac');
	var ad = document.getElementById('ad');

	// Get the valueof the card type
	var varcardtype = frmpaymentmethod.options[frmpaymentmethod.selectedIndex].value;
	
	// Make sure that a card type has been chosen 0,VISA-SSL,ECMC-SSL,SWITCH-SSL,SOLO_GB-SSL
	if ( (varcardtype == 0) || (varcardtype == 'VISA-SSL') || (varcardtype == 'ECMC-SSL') ) {
		aa.style.visibility="hidden";
		ab.style.visibility="hidden";
		ac.style.visibility="hidden";
		ad.style.visibility="hidden";
		aa.style.display="none";
		ab.style.display="none";
		ac.style.display="none";
		ad.style.display="none";
	} else {
		aa.style.visibility="visible";
		ab.style.visibility="visible";
		ac.style.visibility="visible";
		ad.style.visibility="visible";
		aa.style.display="block";
		ab.style.display="block";
		ac.style.display="block";
		ad.style.display="block";
	}

return;

}

// Hide and show startdate and issue number depending on whether they have been chosen or not
var cvcmessage = 1;
function hideshowcvcmessage() {

	var ae = document.getElementById('ae');
	
	// Make sure that a card type has been chosen 0,VISA-SSL,ECMC-SSL,SWITCH-SSL,SOLO_GB-SSL
	if ( cvcmessage == 0 ) {
		ae.style.visibility="hidden";
		ae.style.display="none";
		cvcmessage = 1;
	} else {
		ae.style.visibility="visible";
		ae.style.display="block";
		cvcmessage = 0;
	}

return;

}

// Check to see if a variable is numeric
function IsNumeric(strString)	{

	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			blnResult = false;
	}

	return blnResult;
}

