// GlobalScript.js - Contains global Javascript functions
//
// --------------------------------------------------------------
// Date         Developer       Ref     Comments
// 10-Mar-2003  Cameron Gibbs   SR001   Created.
//
//
// --------------------------------------------------------------

// Opens the ViewTaxInvoice.aspx with the specified participant identifier
function OpenInvoice(ParticipantIdentifier)
{
    window.open("ViewTaxInvoice.aspx?Participant=" + ParticipantIdentifier, "","toolbar=yes,location=no,scrollbars=yes,resizable=yes")
}


// Opens a new window with the specified url
function OpenWindow(Source)
{
    
	window.open(Source, "","toolbar=no,menubar=no,scrollbars=yes,height=600,width=610,resizable=yes,location=no,status=no")
}


var message="";

function clickIE()
 
{if (document.all)
{(message);return false;}}
 
function clickNS(e) {
if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.  onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu  =clickIE;}
 
document.oncontextmenu=new Function("return false")

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header

// =======================================
// set the following variables
// =======================================

// Set speed (milliseconds)
var speed = 2000

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

//Pic[0] = '1.jpg'
//Pic[1] = '2.jpg'
//Pic[2] = '3.jpg'
//Pic[3] = '4.jpg'
//Pic[4] = '5.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
   document.images.SlideShow.src = preLoad[j].src
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', speed)
}

//validates credit card number against type
function isValidCreditCard(type,ccnum) {
	var card = ""
	if (type == "1") {
		// Visa: length 16, prefix 4, dashes optional.
		var re = /^4\d{3}\d{4}\d{4}\d{4}$/;
		card = "Visa";
	} else if (type == "2") {
		// Mastercard: length 16, prefix 51-55, dashes optional.
		var re = /^5[1-5]\d{2}\d{4}\d{4}\d{4}$/;
		card = "Mastercard";
	} else if (type == "3") {
		// BankCard: length 16, prefix 5610.
		var re = /^5610\d{12}$/;
		card = "BankCard";
	} else if (type == "4") {
		// American Express: length 15, prefix 34 or 37.
		var re = /^3[4,7]\d{13}$/;
		card = "American Express";
	} else if (type == "5") {
		// Diners: length 14, prefix 30, 36, or 38.
		var re = /^3[0,6,8]\d{12}$/;
		card = "Diners Club";
	}
	if (!re.test(ccnum)){
		alert(ccnum + ' is not a valid ' + card + ' number');
		return false;
	}
	// Checksum ("Mod 10")
	// Add even digits in even length strings or odd digits in odd length strings.
	var checksum = 0;
	for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
		checksum += parseInt(ccnum.charAt(i-1));
	}
	// Analyze odd digits in even length strings or even digits in odd length strings.
	for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
		var digit = parseInt(ccnum.charAt(i-1)) * 2;
		if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
	}
	if ((checksum % 10) == 0) return true; 
	else {
		alert(ccnum + ' is not a valid ' + card + ' number');
		return false;
	}
}