//Dreamweaver Built-In Functions
/////////////////////////////////////////////////////////////////////////////////////////////
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_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_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];}
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Alpha Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateAlpha(stringToValidate, fieldName, theField) {
	var charOn = 0;
	if(stringToValidate.length > 2) {
		for(var i=0;i<stringToValidate.length;i++) {
			charOn = stringToValidate.substr(i,1);
			var re = new RegExp(/[A-Z]|[a-z]|\s/);
			if(!charOn.match(re)) {
				alert("You entered invalid characters in the "+fieldName+" field");
				theField.focus();
				return false;
			}
		}
		return true;
	} else {
		alert("Please fill out the "+fieldName+" field");
		theField.focus();
		return false;
	}		
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Num Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateNum(stringToValidate, reqLength, fieldName, theField) {
	var charOn = 0;
	if(reqLength != -1) {
		if(stringToValidate.length == reqLength) {
			for(var i=0;i<stringToValidate.length;i++) {
				charOn = stringToValidate.substr(i,1);
				if(charOn.search(/[0-9]/) == -1) {
					alert("There are invalid characters in your "+fieldName+" field");
					theField.focus();
					return false;
				}
			}
		} else {
			alert("Your "+fieldName+" field does not meet the requirements. Required length: "+reqLength+" numbers only.");
			theField.focus();
			return false;
		}
		return true;	
	} else {
		if(stringToValidate != '' && stringToValidate != null && stringToValidate != 0) {
			for(var i=0;i<stringToValidate.length;i++) {
				charOn = stringToValidate.substr(i,1);
				if(charOn.search(/[0-9]/) == -1) {
					alert("There are invalid characters in your "+fieldName+" field");
					theField.focus();
					return false;
				}
			}
		} else {
			return true;
		}
	}		
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate AplhaNum Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateAplhaNum(stringToValidate, fieldName, theField) {
	var charOn = '';
	if(stringToValidate.length > 2) {
		for(var i=0;i<stringToValidate.length;i++) {
			charOn = stringToValidate.substr(i,1);
			var re = new RegExp(/[a-z]|[A-Z]|[0-9]|\s|\./);
			if(!charOn.match(re)) {
				alert("Your "+fieldName+" field contains invaild characters. A-z a-z . and spaces only.");
				theField.focus();
				return false;
			}
		}
		return true;	
	} else {
		alert("Please fill out the "+fieldName+" field.");
		theField.focus();
		return false;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Password Only \w Special
//////////////////////////////////////////////////////////////////////////////////////////////
function validatePass(stringToValidate, fieldName, theField) {
	var charOn = 0;
	var specialChars = 0;
	
	if(stringToValidate.length >= 7 && stringToValidate.length <= 12) {
		for(var i=0;i<stringToValidate.length;i++) {
			charOn = stringToValidate.substr(i,1);
			/*var special_re = new RegExp(/\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-/);
			if(charOn.match(special_re)) {
				specialChars++;
			}*/
			var re = new RegExp(/[0-9]|[A-z]|[a-z]|\!|\$|\^|\*|\(|\)|\-|\{|\}/);
			if(!charOn.match(re)) {
				alert("Your "+fieldName+" contains invacharacters.");
				theField.value='';
				theField.focus();
				return false;
			}
		}
	} else {
		alert("Your "+fieldName+" field does not meet the correct length requirements.");
		theField.value='';
		theField.focus();
		return false;
	}
	
	/*if(specialChars < 1){
		alert("Your "+fieldName+" field did not contain at least one of the special characters.");
		theField.value='';
		theField.focus();
		return false;
	}	*/
	return true;	
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Email Only
//////////////////////////////////////////////////////////////////////////////////////////////
function isEmailAddr(email, formField, theField) { 	//email = 123123123@123123123.com
	if(email != "name@domain.com") {
		var theStr = String(email);
		var index = theStr.indexOf("@");
		index = index*1;
		if (index > 2) {
			var index_name = email.substr(0,index);
			var pindex = theStr.lastIndexOf(".");
			pindex = pindex*1;
			if ((pindex > 0) && (pindex > index+1) && (theStr.length > pindex+1)) {
				var pindex1 = theStr.substr(pindex+1,theStr.length);
				if(pindex1.length > 1) {
					var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
					for(var z=0;z<pindex1.length;z++) {
						if(charset.indexOf(pindex1.substr(z,1))>-1) {
							return true;
							break;
						}
						else {
							alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
							theField.focus();
							return false;
							break;
						}
					}
				}
				else {
					alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
					theField.focus();
					return false;
				}
			} else {
				alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
				theField.focus();
				return false;
			}
		} else {
			alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
			theField.focus();
			return false;
		}
	} else {
		alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
		theField.focus();
		return false;
	}
	alert("Please fill out the "+formField+" field with a vaild email address. ex: name@domain.com");
	theField.focus();
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Selects Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateSelect() {
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Checkbox Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateCheckbox(checkedObj, fieldName) {
	if(checkedObj.checked) {
		return true;
	} else {
		alert("Please check the "+fieldName+" box.");
		return false;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Checkbox Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validateMatchPasses(password1, password2) {
	var pas1 = String(password1);
	var pas2 = String(password2);
	if(pas1 == pas2) {
		return true;
	} else {
		return false;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate Checkbox Only
//////////////////////////////////////////////////////////////////////////////////////////////
function validatePhone(stringToValidate, fieldName, theField) {
	var charOn = 0;
	var specialChars = 0;
	
	if(stringToValidate.length >= 10) {
		for(var i=0;i<stringToValidate.length;i++) {
			charOn = stringToValidate.substr(i,1);
			var re = new RegExp(/[0-9]|\s|\-|\(|\)/);
			if(!charOn.match(re)) {
				alert("Your "+fieldName+" contains invacharacters.");
				theField.value='';
				theField.focus();
				return false;
			}
		}
	} else {
		alert("Your "+fieldName+" field does not meet the correct length requirements. EX: 000-000-0000.");
		theField.focus();
		return false;
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate changepassword.php form
//////////////////////////////////////////////////////////////////////////////////////////////
function validateChangePassword(theform) {
	if (theform.NewPass.value == theform.NewPassConf.value) {
		if (theform.NewPass.value.length >= 7 ) {
			md5me(theform.CurrentPass);md5me(theform.NewPass);md5me(theform.NewPassConf);
			theform.submit();
		} else {
			alert("Error. Your new password must be longer than 6 characters");
			theform.NewPass.value = "";
			theform.NewPassConf.value = "";
		}	
	} else {
		theform.NewPass.value = "";
		theform.NewPassConf.value = "";
		alert("Error. Your new passwords do not match each other.");
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Validate From
//////////////////////////////////////////////////////////////////////////////////////////////
function validateRequiredFormFields(theForm) {
	var formElements = theForm.elements;
	var elementID = '';
	var idValues = Array();
	
	for(var i=0;i<formElements.length;i++) {
		theElement = formElements[i];
		elementID = theElement.id;
		idValues = elementID.split(",");
		if(idValues[1] == 'req') {	
			switch(idValues[2]) {
				case 'Alpha':
					if(!validateAlpha(theElement.value, idValues[0], theElement)) {
						return false;
					}
					break
				case 'Num':
					if(!validateNum(theElement.value, idValues[3], idValues[0],theElement)) {
						return false;
					}
					break
				case 'AlphaNum':
					if(!validateAplhaNum(theElement.value, idValues[0], theElement)) {
						return false;
					}
					break
				case 'Pass':
					if(!validatePass(theElement.value, idValues[0], theElement)) {
						return false;
					}
					break
				case 'Email':
					if(!isEmailAddr(theElement.value, idValues[0], theElement)) {
						return false;
					}
					break
				case 'Select':
					if(validateSelect == "") {
						return false;
					}
					break;
				case 'Checkbox':
					if(!validateCheckbox(theElement, idValues[0])) {
						return false;
					}
					break
				case 'Phone':
					if(!validatePhone(theElement.value, idValues[0], theElement)) {
						return false;
					}
					break
				default:
					return false;
			}
		}
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Add Slashes From
//////////////////////////////////////////////////////////////////////////////////////////////
function JSaddslashes(str) {
	str=str.replace(/\'/g,"\\'");
	str=str.replace(/\"/g, '\\"');
	return str;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Strip Slashes From
//////////////////////////////////////////////////////////////////////////////////////////////
function JSstripslashes(str) {
	str=str.replace(/\\'/g,"'");
	str=str.replace(/\\"/g,'"');
	return str;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//AJAX (V1.0BK)
//////////////////////////////////////////////////////////////////////////////////////////////
var xmlHttp;
function getPage(page,urlvarsinfo, getpost, postinfo) { 
	page = String(page);
	urlvarsinfo = String(urlvarsinfo);
	getpost = String(getpost);
	postinfo = String(postinfo);
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	if((urlvarsinfo != '' && urlvarsinfo != null) && getpost == 'GET') {
		url=page+"?"+urlvarsinfo;
	} else {
		url=page;
	}
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open(getpost,url,true)
	if((urlvarsinfo == '' || urlvarsinfo == null) && getpost == 'POST') {
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
		xmlHttp.send(postinfo)
	} else {
		xmlHttp.send(null)
		return xmlHttp.responseText;
	}
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//document.getElementById("ContentContainer").innerHTML="";
		//document.getElementById("ContentContainer").innerHTML=xmlHttp.responseText;
		return;
	} 
}

function GetXmlHttpObject()	{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function createPostVars(theForm, urltopost, urlvars) {
	var stringofvars = '';
	var stringofvars1 = '';
	for(var i=0; i<theForm.elements.length; i++) {
		obj = theForm.elements[i];
		objValue = '';
		objName = obj.name;
		objValue = theForm.elements[i].value;
		objValue = JSaddslashes(objValue);
		stringofvars = stringofvars+objName+"="+objValue+"&";
/*
		if(obj.type == "radio" && obj.checked) {
			objValue = theForm.elements[i].value;
			objValue = JSaddslashes(objValue);
			stringofvars = stringofvars+objName+"="+objValue+"&";
		} 
		if(obj.type == "checkbox" && obj.checked) {
			objValue = theForm.elements[i].value;
			objValue = JSaddslashes(objValue);
			stringofvars = stringofvars+objName+"="+objValue+"&";
		} 
		if(obj.type != "checkbox" && obj.type != "radio"){
			objValue = theForm.elements[i].value;
			objValue = JSaddslashes(objValue);
			stringofvars = stringofvars+objName+"="+objValue+"&";
		}*/
	}
	stringofvars1 = stringofvars.substr(0, (stringofvars.length -1));
	/*theForm.action = "javascript:*/
	getPage(urltopost,urlvars,'POST','Post=true&'+stringofvars1);
	return;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//Cookie detection functions.
//retrieved from http://techpatterns.com/downloads/javascript_cookies.php
function Set_Cookie( name, value, expires, path, domain, secure ) {var today = new Date();today.setTime( today.getTime() );if ( expires ){expires = expires * 1000 * 60 * 60 * 24;}var expires_date = new Date( today.getTime() + (expires) );document.cookie = name + "=" +escape( value ) +( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) +( ( secure ) ? ";secure" : "" );}
function Get_Cookie( check_name ) {	var a_all_cookies = document.cookie.split( ';' );	var a_temp_cookie = '';	var cookie_name = '';	var cookie_value = '';	var b_cookie_found = false; 
for ( i = 0; i < a_all_cookies.length; i++ )	{		a_temp_cookie = a_all_cookies[i].split( '=' );		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');		if ( cookie_name == check_name )		{			b_cookie_found = true;			if ( a_temp_cookie.length > 1 )			{				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );			}			return cookie_value;			break;		}		a_temp_cookie = null;		cookie_name = '';	}	if ( !b_cookie_found )	{		return null;	}}	
function Delete_Cookie( name, path, domain ) {if ( Get_Cookie( name ) ) document.cookie = name + "=" +( ( path ) ? ";path=" + path : "") +( ( domain ) ? ";domain=" + domain : "" ) +";expires=Thu, 01-Jan-1970 00:00:01 GMT";}
function checkCookies() {
	Set_Cookie( 'test', 'none', '', '/', '', '' );
	if ( Get_Cookie( 'test' ) ) {
		// do nothing. because cookies are enabled
		Delete_Cookie('test', '/', '');
	} else {
		var cookiewarn = document.getElementById("cookies");
		if (cookiewarn) {
			cookiewarn.style.display = "block";
			cookiewarn.style.color = "#FF0000";
		}
	}
}
///////////////////////////////////////////////////////////////////////////
/// To confirm things
function confirmFormReset(theform) {
	if (confirm("Are you sure you would like to clear the form? This cannot be undone.")) {
		theform.reset();
	}
}