
//************************************************************************************************
//					Get a radio box value
//************************************************************************************************
function getradioboxval(formname,elementname) {
	theone = '';
	for (i=0;i <= document.forms[formname].elements[elementname].length-1;i++) {
		if (document.forms[formname].elements[elementname][i].checked == true) {
			theone=i
		}
	}
	if (theone !== '') {
		value = document.forms[formname].elements[elementname][theone].value;
	} else {
		value = false;
	}
	return value;
};


//************************************************************************************************
//						Submit a form using given action
//************************************************************************************************
function actionsubmit(formname,to,cmd) {
	document.forms[formname].action = to;
	document.forms[formname].dothis.value = cmd;
	document.forms[formname].submit();
};


//************************************************************************************************
//								Confirmation box
//************************************************************************************************
function checkok(text,formname,dothis,dosubmit) {
	if(confirm(text)) {
		document.forms[formname].dothis.value = dothis;
		if (dosubmit == true) {
			document.forms[formname].submit();
		};
		return true;
	} else {
		return false;
	}
}


//************************************************************************************************
//								Show a given section of a KB article
//************************************************************************************************
function sectionshow(formname,section) {
	if (document.forms[formname].elements['sec'+section+'_show'].checked != 1) {
		document.forms[formname].elements['sec'+section+'_title'].disabled = true;
		document.forms[formname].elements['sec'+section+'_text'].disabled = true;
	} else {
		document.forms[formname].elements['sec'+section+'_title'].disabled = false;
		document.forms[formname].elements['sec'+section+'_text'].disabled = false;
	}	
}


//************************************************************************************************
//************************************************************************************************
//								Swap one picture with another
//************************************************************************************************
function picswap(elementid,pic1,pic2) {
	thepic = document.getElementById(elementid);
	if (thepic.src.indexOf(pic1) == -1) {
		thepic.src = pic1;
	} else {
		thepic.src = pic2;
	}
};
//									Form verification object
//************************************************************************************************

verify = {
	//Properties
	fail : false,               //has verification failed ?
	failedon : '',              //What did it fail on - returns string of all that failed.
	checks : new Array,          //All the checks to be performed
	
	//Methods
	//Main check function
	docheck : function(type, val1, val2, themsg) {
		newkey = new String;
		checkfail = false;
		switch (type) {
			case 'notblank':
				if (val1 == '') {
					checkfail = true;
					this.fail = true;
					if (themsg != '') { this.failedon += themsg + "\n"; };
				};				
			break;
			
			case 'notmatch':
				if (val1 == val2) {
					checkfail = true;
					this.fail = true;					
					if (themsg !='') { this.failedon += themsg + "\n"; };
				};
			break;
			
			case 'match':
				if (val1 != val2) {
					checkfail = true;
					this.fail = true;					
					if (themsg != '') { this.failedon += themsg + "\n"; };
				};
			break;

			case 'email':
				if (((val1 == '') || (val1.indexOf("@") == -1) || (val1.indexOf(".") == -1))) {
					checkfail = true;
					this.fail = true;					
					if (themsg != '') { this.failedon += themsg + "\n"; };
				};
			break;
			
			case 'luhn':
				strippedval = new String;
				
				//Strip away all invalid chars
				validchars = Array('0','1','2','3','4','5','6','7','8','9');
				val1upper = val1.toUpperCase();
				for (i=0;i<=val1upper.length-1;i++) { 			//Begin loop through the key we're checking
					for(j=0;j<=validchars.length-1;j++) {		//Begin loop through the validchars array
						if (val1upper.charAt(i) == validchars[j]) {
							strippedval += val1upper.charAt(i);		//If char matches in validcars array, add to newkey string
							break;								//Break out of for loop for validchars
						};
					};
				};
				var oddoeven = strippedval.length & 1;
				var sum = 0;
	
				if (strippedval.length != 16) {
					checkfail = true;
					this.fail = true;					
					if (themsg != '') { this.failedon += themsg + "\n"; };
					break;
				}
	
				for (var count = 0; count < strippedval.length; count++) {
					var digit = parseInt(strippedval.charAt(count));
					if (!((count & 1) ^ oddoeven)) {
						digit *= 2;
						if (digit > 9)
							digit -= 9;
						}
						sum += digit;
					}
				if (sum % 10 != 0) {
					checkfail = true;
					this.fail = true;					
					if (themsg != '') { this.failedon += themsg + "\n"; };
				};
			break;
			
			case 'licensekey':
			
				strippedval = new String;
				//Strip away all invalid chars
				validchars = Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
				val1upper = val1.toUpperCase();
				for (i=0;i<=val1upper.length-1;i++) { 			//Begin loop through the key we're checking
					for(j=0;j<=validchars.length-1;j++) {		//Begin loop through the validchars array
						if (val1upper.charAt(i) == validchars[j]) {
							strippedval += val1upper.charAt(i);		//If char matches in validcars array, add to newkey string
							break;								//Break out of for loop for validchars
						};
					};
				};
				
				//Check length.
				if (strippedval.length != 20) {
					this.fail = true;
					checkfail = true;
					if (themsg != '') { this.failedon += themsg + "\n"; };					
				};
			break;
		};
			
		return checkfail;
	}, // end docheck 
	
	//Check everything in the checks array in one go (for one shot checking)
	checkall : function() {
		for(i=0; i <= this.checks.length - 1;i++) {			//Step through the checks array
			this.docheck(this.checks[i][0],this.checks[i][1],this.checks[i][2],this.checks[i][3]);
		};
	},
	
	//Add a new check 
	addcheck : function(type, val1, val2, themsg) {
		this.checks[this.checks.length] = Array(type, val1, val2, themsg);		//Add check to checks array
		return true;
		
	}, //end addcheck
	
	//Reset
	resetall : function() {
		this.checks = new Array();
		this.fail = false;
		this.failedon = '';
	}
}; //end verify object

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}