
/*/////////////////////////////////////////////////////////////
//                                                           //
// Copyright (c) 2008, Peter Jones (AKA Azrael)              //
// All rights reserved.                                      //
//                                                           //
// For redistribution and use conditions, please see the     //
// file 'license.txt' supplied with the original download.   //
//                                                           //
// Author        : Peter Jones (AKA Azrael)                  //
// Website       : http://www.gamers-central.com + (.co.uk)  //
// Support       : http://www.babstats.com                   //
//                                                           //
// File Name     : Main Javascript functions                 //
// File Version  : 1.0.1                                     //
// File Date     : 2nd February 2008                         //
//                                                           //
/////////////////////////////////////////////////////////////*/

function resubmit(type) {	
	var myStr = window.location.href;
	var sChk = myStr.search("search");
	var fChk = myStr.search("filter");
	var nStr = myStr.replace("&bssearch=1", "");
	var nStr = nStr.replace("&bsfilter=1", "");

	if(sChk != -1 && type == 'search') {
		window.location = nStr;
	} else if(fChk != -1 && type == 'filter') {
		window.location = nStr;
	} else {
		if(type == "filter") {
			nStr = nStr + '&bsfilter=1';
		} else if(type == "search") {
			nStr = nStr + '&bssearch=1';
		}
		window.location = nStr;
	}
}

function SubmitForm() {
	var fObj = eval('window.document.FileList');
	fObj.submit();	
}

function bsAddUrl() {
	var uObj = eval('window.document.ProfileModifyForm.lUrl');
	var iObj = eval('window.document.ProfileModifyForm.lServerID');
	var fObj = eval('window.document.ProfileModifyForm');
	if(iObj.value.length < 1) {
		alert('Server ID field is empty!');
	} else if(IsUrl(uObj.value) === false) {
		alert('URL is invalid!');
	} else {
		var newOpt = new Option();
		newOpt.text = IsUrl(uObj.value) + ':' + iObj.value;
		newOpt.value = IsUrl(uObj.value) + ':' + iObj.value;
		fObj["ScriptUrls[]"].options.add(newOpt);
		for(j=0; j < fObj["ScriptUrls[]"].options.length; j++) {
			fObj["ScriptUrls[]"].options[j].selected = true;
		}
	}
	return false;
}

function IsUrl(UrlVal) {
	if(UrlVal == "http://" || UrlVal.length < 1) {
		IsValid = false;
	} else {
		var uStr = UrlVal.replace("http://", "");
		if(uStr.length < 1) {IsValid = false;}
		var sStr = uStr.split(".");
		var IsValid = "http://" + uStr;
		if(sStr.length == 2 && sStr[0] == "www") {IsValid = false;}
		if(sStr.length < 2) {IsValid = false;}
		if(IsValid.substr(-1) == "/") {IsValid = IsValid.substr(0, IsValid.length-1);}
	}
	return IsValid;
}

function bsSetProfile() {
	var fObj = eval('window.document.ProfileForm');
	if(null != fObj.nProfileID.length) {
		for(i = 0; i < fObj.nProfileID.length; i++) {
			if(fObj.nProfileID.item(i).checked) {
				fObj.PSEL.value = fObj.nProfileID.item(i).value;
			}
		}
	} else {fObj.PSEL.value = fObj.nProfileID.value;}
	fObj.submit();
}

function fSubmit(Form) {
	eval('window.document.' + Form + '.submit()');
}

function bsJointListSelect(List1, List2) {
	var fObj = eval('window.document.ProcessList');
	var lObj1 = eval('window.document.ProcessList.' + List1);
	var lObj2 = eval('window.document.ProcessList.' + List2);
	for(i = 0; i < lObj1.length; i++) {
		if(lObj1.options[i].selected == true) lObj2.options[i].selected = true
	}
}

function bsSetGameType(gType) {
    document.fGameType.selGameType.value = gType;
	document.fGameType.submit();
}

function PlyrWpns(pID) {
	myString = new String(window.location);
	if(myString.search("&pid") == -1) {
		document.TeamSelect.action = window.location + '&pid=' + pID + '#' + pID
		document.TeamSelect.submit()
	} else {
		splitString = myString.split("&pid");
		splitString2 = myString.split("&pid=");
		splitString3 = splitString2[1].split("#");
		if(splitString3[0] == pID) {
			vID=0;
		} else {
			vID=pID;
		} 
		document.TeamSelect.action = splitString[0] + '&pid=' + vID + '#' + pID
		document.TeamSelect.submit()
	}
}

function bsCheckAll(field, value) {
	var SelObj = document.getElementsByName(field);
	if(SelObj[0].type == 'checkbox') {
		for (i=0; i < SelObj.length; i++ ) {
			SelObj[i].checked = value;
		}
	} else {
		for (i=0; i < SelObj.length; i++ ) {
			SelObj[i].options[value].selected = true;
		}
	}
}

function bsPrompt(SelField, SelType, Form) {
	var SelObj = document.getElementsByName(SelField);
	var SelCnt = 0;

	for (i=0; i < SelObj.length; i++ ) {
		if(SelObj[i].checked == true) SelCnt++;
	}
	if(SelCnt == 0) {
		switch(SelType) {
			case 1:
				SelMsg = "You must check the boxes next to any players you wish to perform the selected actions on!\n\n" + 
		                 "Selected Players: " + SelCnt; break
			case 2:
				SelMsg = "You must check the boxes next to any games you wish to delete!\n\n" + 
		                 "Selected Games: " + SelCnt; break
			case 3:
				SelMsg = "You must check the boxes next to any maps you wish to perform the selected actions on!\n\n" + 
		                 "Selected Maps: " + SelCnt; break
			case 4:
				SelMsg = "You must check the boxes next to any players you wish to remove from the squad!\n\n" + 
		                 "Selected Players: " + SelCnt; break
			case 5:
				SelMsg = "You must check the boxes next to any servers you wish to perform the selected actions on!\n\n" + 
		                 "Selected Servers: " + SelCnt; break
			case 6:
				SelMsg = "You must check the boxes next to any weapons you wish to perform the selected actions on!\n\n" + 
		                 "Selected Weapons: " + SelCnt; break
			case 7:
				SelMsg = "You must check the boxes next to any awards you wish to perform the selected actions on!\n\n" + 
		                 "Selected Awards: " + SelCnt; break
			case 8:
				SelMsg = "You must check the boxes next to any ranks you wish to perform the selected actions on!\n\n" + 
		                 "Selected Ranks: " + SelCnt; break
			case 9:
				SelMsg = "You must check the boxes next to any users you wish to delete!\n\n" + 
		                 "Selected Users: " + SelCnt; break
			case 10:
				SelMsg = "You must check the boxes next to any opponents you wish to delete!\n\n" + 
		                 "Selected Opponents: " + SelCnt; break
			case 11:
				SelMsg = "You must check the boxes next to any tables you wish to fix!\n\n" + 
		                 "Selected Tables: " + SelCnt; break
		}
		alert(SelMsg)
		return false;
	} else {
		switch(SelType) {
			case 1:
				SelMsg = "Are you sure you wish to perform the selected actions?\n\n" + 
		                 "Selected Players: " + SelCnt; break
			case 2:
				SelMsg = "Are you sure you wish to delete the selected games?\n\n" + 
		                 "Selected Games: " + SelCnt; break
			case 3:
				SelMsg = "You must check the boxes next to any maps you wish to perform the selected actions on!\n\n" + 
		                 "Selected Maps: " + SelCnt; break
			case 4:
				SelMsg = "Are you sure you wish to remove the selected players from this squad?\n\n" + 
		                 "Selected Players: " + SelCnt; break
			case 5:
				SelMsg = "Are you sure you wish to perform the selected actions?\n\n" + 
		                 "Selected Servers: " + SelCnt; break
			case 6:
				SelMsg = "Are you sure you wish to perform the selected actions?\n\n" + 
		                 "Selected Weapons: " + SelCnt; break
			case 7:
				SelMsg = "Are you sure you wish to perform the selected actions?\n\n" + 
		                 "Selected Awards: " + SelCnt; break
			case 8:
				SelMsg = "Are you sure you wish to perform the selected actions?\n\n" + 
		                 "Selected Ranks: " + SelCnt; break
			case 9:
				SelMsg = "Are you sure you wish to delete the selected users?\n\n" + 
		                 "Selected Users: " + SelCnt; break
			case 10:
				SelMsg = "Are you sure you wish to delete the selected opponents?\n\n" + 
		                 "Selected Opponents: " + SelCnt; break
			case 11:
				SelMsg = "Are you sure you wish to fix the selected tables?\n\n" + 
		                 "Selected Tables: " + SelCnt; break
		}
		
		var retVal = confirm(SelMsg, "Hmm")
		if (retVal){
			return bsCheckForm(Form);

		} else {
			
			return false;
		}
	}
}

function NoFunc() {
  	alert('This function is not active yet!');
}

function bsCheckForm(Form) {
	var fValid = true;
	var eField;
	for (i=0; i < Form.length; i++ ) {
		if(Form[i].type == "text") {
			if(Form[i].value == "") {
				fValid = false;
				eField = Form[i].name + ' field is empty!';
				break;
			} else {
				if(bsValidateStr(Form[i].value) == false) {
					fValid = false;
					eField = Form[i].name + ' MUST be alphanumeric!';
					break;
				}
			}
		}
	}
	
	if(fValid == false) alert(eField);
	
	return fValid;
}

function bsValidateStr(Str) {
	var ValidChr = /[^a-z\d .|/]/i;
	return !(ValidChr.test(Str));
}

function bsAddStats() {
	var fObj = window.document.AwardEditForm;
	var sObj = window.document.AwardEditForm.aStatList;
	var sLen = sObj.options.length;

	for (i=0; i < sLen; i++ ) {
		if(sObj.options[i].selected == true) {
			sVal = prompt('Please enter a value for ' + sObj.options[i].value + 
						  '\n\n Any value left blank, set to 0 or not numeric will be discarded!');
			if(sVal > 0) {
				if(fObj.eStats.value == "") {
					fObj.eStats.value = sObj.options[i].value;
				} else {
					fObj.eStats.value = fObj.eStats.value + "|" + sObj.options[i].value;
				}
				if(fObj.eValues.value == "") {
					fObj.eValues.value = sVal;
				} else {
					fObj.eValues.value = fObj.eValues.value + "|" + sVal;
				}
			}
		}
	}
	
	return false;
}

function bsAddAwards(type) {
	if(type === '1') {
		var fObj = window.document.AwardEditForm;
		var sObj = window.document.AwardEditForm.eAwardList;
	} else if(type === '2') {
		var fObj = window.document.RankEditForm;
		var sObj = window.document.RankEditForm.eAwardList;
	} else {
		var fObj = window.document.RankEditForm;
		for(j=0; j < fObj["eAwards[]"].options.length; j++) {
			fObj["eAwards[]"].options[j].selected = true;
		}
	}

	var sLen = sObj.options.length;

	for (i=0; i < sLen; i++ ) {
		if(sObj.options[i].selected == true) {
			var awFound = false;
			for(j=0; j < fObj["eAwards[]"].options.length; j++) {
				if(fObj["eAwards[]"].options[j].value == sObj.options[i].value) {
					awFound = true;
					break;
				}
			}
			if(awFound === false) {
				var newOpt = new Option();
				newOpt.text = sObj.options[i].value;
				newOpt.value = sObj.options[i].value;
				fObj["eAwards[]"].options.add(newOpt);
			}
			for(j=0; j < fObj["eAwards[]"].options.length; j++) {
				fObj["eAwards[]"].options[j].selected = true;
			}
		}
	}
	
	return false;
}

function bsListSelectAll(FNAME, SELNAME) {
	var fObj = eval('window.document.' + FNAME);
	for(j=0; j < fObj[SELNAME].options.length; j++) {
		fObj[SELNAME].options[j].selected = true;
	}
}

function bsClearCriteria(type) {
	if(type === '1') {
		var fObj = window.document.AwardEditForm;
		fObj.eStats.value = ""
		fObj.eValues.value = ""
	} else {
		var fObj = window.document.RankEditForm;
	}
	
	fObj["eAwards[]"].length = 0;
	
	return false;
}

function bsEditAward(type) {
	var fObj = window.document.AwardEditForm;
	var eField = true;

	if(bsValidateStr(fObj.aName.value) == false) {
		alert('Name field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /');
		eField = false;
	}
	
	if(fObj.aName.value == "") {
		alert('Name field is empty!');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aDesc.value) == false) {
		alert('Description field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aCat.value) == false) {
		alert('Category field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aType.value) == false) {
		alert('Type field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aGame.value) == false) {
		alert('Game field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /');
		eField = false;
	}
	
	if(fObj.aStats.value == "") {
		alert('You must have atleast 1 Stat criteria set for an award!');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aStats.value) == false) {
		alert('Stats field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /, |');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aValues.value) == false) {
		alert('Values field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /, |');
		eField = false;
	}
	
	if(bsValidateStr(fObj.aAwards.value) == false) {
		alert('Awards field can only contain the following characters: \n\n a-z, A-Z, 0-9, space, ., /, |');
		eField = false;
	}
	
	if(eField == true) {alert('Award ' + type + ' Successfully');}
	
	return eField;
}

function bsConfirmDelete(SelField, SelType, Form) {
	var SelObj = document.getElementsByName(SelField);
	var SelCnt = 0;

	for (i=0; i < SelObj.length; i++ ) {
		if(SelObj[i].checked == true) SelCnt++;
	}
	
	if(SelCnt == 0) {
		SelMsg = "You must check the boxes next to any " + SelType + " you wish to delete!\n\n" + 
		         "Selected " + SelType + ": " + SelCnt;
			
		alert(SelMsg)
		return false;
	} else {
		SelMsg = "Are you sure you wish to delete the selected " + SelType + "?\n\n" + 
		         "Selected " + SelType + ": " + SelCnt;
		
		var retVal = confirm(SelMsg)
		if (retVal){
			return bsCheckForm(Form);

		} else {
			
			return false;
		}
	}
}

function bsSetLink(Link, CMS) {
	var qStr = document.location.search.substring(1);
	var nStr = 'section=' + Link.replace("admin", "admin_");
	if(CMS) {
		var sStr = new Array();
		var sStr = qStr.split("&");
		if(sStr.length > 2) {
			for(i = 2; i < sStr.length; i++) {
				sStr[1] = sStr[1] + "&" + sStr[i]
			}
		}
		var nUrl = document.location.href.replace(sStr[1], nStr);
	} else {
		var nUrl = document.location.href.replace(qStr, nStr);
	}

	if(document.AdminMenu.MenuSel.value == Link) {Link = "None";}
	document.AdminMenu.MenuSel.value = Link;
	document.AdminMenu.submit();
	document.location = nUrl;
}

function bsConfirmDel(dMsg) {
	var retVal = confirm(dMsg)
	if (retVal){
		return true;
	} else {
		return false;
	}
}

function bsValidFields(form, ignore) {
	var tmpA = new Array();
	var tmpB = new Array();
	var eacb = 127;
	var eace = 254;
	var ignoreField = false;
	var proceed = true;
	var fObj = eval('window.document.' + form);
	var eCnt = 0;

	for (x=0; x < fObj.length; x++ ) {
		if(fObj[x].type != "submit") {
			tmpA[eCnt] = fObj[x].name;
			eCnt++;
		}
	}
	//alert(tmpA.length);
	//return false;
	//tmpA = str.split(',');
	tmpB = ignore.split(',');
	for(i = 0; i < tmpA.length; i++) {
		//tVal = eval('window.document.' + form + '.' + tmpA[i] + '.name')
		//alert(tVal.length);
		//return false;
		sVal = eval('window.document.' + form + '.' + tmpA[i] + '.value')
		tVal = eval('window.document.' + form + '.' + tmpA[i] + '.type')
		if(tVal == "select-one") { 
			sVal = fObj[tmpA[i]].options.length; 
		}
		if(null != sVal) {
			sNam = eval('window.document.' + form + '.' + tmpA[i] + '.name');
			sType = tmpA[i].substring(0,1);
			sVal = sVal.replace("http://", "");
			if(sNam != arguments[2]) {
				if(sVal.length == 0) {
					ignoreField = false;
					for(k = 0; k < tmpB.length; k++) {
						if(tmpB[k] == tmpA[i]) {ignoreField = true;}
					}
					
					if(ignoreField === false) {
						alert(tmpA[i].substring(1) + " is empty!");
						return false;
					}
				} else {
					if(bsRegex(sVal, sType) == false) {
						switch(sType) {
							case "a": eMsg = " field MUST be Alphabetic (only a-z and A-Z allowed)"; break;
							case "n": eMsg = " field MUST be Numeric (only 0-9, - and . allowed)"; break;
							case "l": eMsg = " field MUST be Alphanumeric (only a-z, A-Z, 0-9 and spaces allowed)"; break;
							case "e": 
							  eMsg = " field can only contain the following: \n\n (a-z) (A-Z) (0-9) (" + bsAllowedSymbols + ") (Extended Characters " + eacb.toString(16) + " - " +  eace.toString(16) + ")"; break;
						}
						alert(tmpA[i].substring(1) + eMsg);
						return false;
					}
				}
			} 
		}
	}
	return proceed;
}

function bsRegex(str, type) {
	var res = true;
	cArr = new 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", 
					 "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");
	nArr = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
	xArr = new Array("€", "«", "Ö", "¬", "×", "‚", "­", "Ø", "ƒ", "®", "Ù", "„", "¯", "Ú", "…", "°", "Û", "†", "±", "Ü", 
					 "‡", "²", "Ý", "ˆ", "³", "Þ", "‰", "´", "ß", "Š", "µ", "à", "‹", "¶", "á", "Œ", "·", "â", "¸", "ã", "Ž", 
					 "¹", "ä", "º", "å", "»", "æ", "‘", "¼", "ç", "’", "½", "è", "“", "¾", "é", "”", "¿", "ê", "•", "À", "ë", 
					 "–", "Á", "ì", "—", "Â", "í", "˜", "Ã", "î", "™", "Ä", "ï", "š", "Å", "ð", "›", "Æ", "ñ", "œ", "Ç", "ò", 
					 "È", "ó", "ž", "É", "ô", "Ë", "ö", "¡", "Ì", "÷", "¢", "Í", "ø", "£", "Î", "ù", "¤", "Ï", "ú", "¥", "Ð", 
					 "û", "¦", "Ñ", "ü", "§", "Ò", "ý", "¨", "Ó", "þ", "©", "Ô", "ÿ", "ª", "Õ", ".");
	sArr = bsAllowedSymbols.split('');
	str = str.replace(/(\s)/g, "");
	//alert(str);
	switch(type) {
		case "a": vRegex = /[^a-z ]/i; break
		case "n": vRegex = /[^\d .-]/; break
		case "l": vRegex = /[^a-z\d ]/i; break
		case "e": vRegex = /[^a-z\d ]/i; break
	}
	
	str.replace(/</g,"<")
	str.replace(/>/g,">")

	if(type == "a" || type == "n" || type == "l") {
		return !(vRegex.test(str));
	} else {
		for(j = 0; j < str.length; j++) {
			if(!cArr.inArray(str.substr(j, 1))) {
				if(!nArr.inArray(str.substr(j, 1))) {
					if(!sArr.inArray(str.substr(j, 1))) {
						if(!xArr.inArray(str.substr(j, 1))) {
							res = false;
						}
					}
				}
			}
		}
		return res;
	}
}


Array.prototype.inArray = function (value) {
    var i;
    for (i=0; i < this.length; i++) {
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

<!--jfuncs.js 1.0.1-->