/*----------------------------------------------------------------------------------------------------------------------
		Copyright 2007 (c) Profusion, LLC. All Rights Reserved.
		This is a commercial software product, please visit http://www.profusioworks.com/ for more information.
		See http://www.profusioworks.com/license.php for Commercial License Agreement
		All Copyright statements must always remain in place in all files at all times
****** ******* ******** PLEASE NOTE: THIS IS NOT FREE SOFTWARE, IT MUST BE LICENSED FOR ALL USE  ******** ******* ******
----------------------------------------------------------------------------------------------------------------------*/
function stringLen(type){
	if(type == "password")
		x=6;
	else if(type == "phone" || type == "cell" || type == "fax")
		x=10;
	else if(type == "zip")
		x=5;
	else
		x=2;
		
	return x;
}

function changeColor(id, f1, div){
	var mail = new Array('@', '.');
	if(f1 == "email"){
		var z=0;
		var temp = document.getElementById(id)[f1].value;
		for(i=0; i<=temp.length; i++){
			t = temp.substr(i, 1);
			if(t == mail[0] || t == mail[1])
				z++;
		}
		if(z == 2)
			document.getElementById(div).style.color="#CCCCCC";
	}else{
		x = stringLen(f1);
		if(document.getElementById(id)[f1].value.length >= x)
			document.getElementById(div).style.color="#CCCCCC";
		else
			document.getElementById(div).style.color="#FF0000";
	}
}

var msg='';
function valText(id, f1, txt){
	x = stringLen(f1);
	if(document.getElementById(id)[f1].value.length < x)
		msg = "The "+ txt +" field has not been completed correctly.\r\n\r\n";
	else
		msg = '';
	return msg;
}

function valPull(id, f1, txt){
	if(document.getElementById(id)[f1].value == '')
		msg = "There has nor been a "+ txt +" selected for this job.\r\n\r\n";
	else
		msg = '';
	return msg;
}

function valEmail(id, f1, txt){
	var z=0;
	var mail = new Array('@', '.');
	var temp = document.getElementById(id)[f1].value;
	for(i=0; i<=temp.length; i++){
		t = temp.substr(i, 1);
		if(t == mail[0] || t == mail[1])
			z++;
	}
	if(z == 2 || z == 3)
		msg = '';
	else
		msg = "The "+ txt +" field is not a valid email.\r\n\r\n";
	return msg;
}

function valPass(id, f1, txt){
	x=6;
	if(document.getElementById(id)[f1].value.length < x)
		msg = "The "+ txt +" does not meet the minimum number of characters.\r\n\r\n";
	else
		msg = '';
	return msg;
}

function validatePassword(str, isNew){
	var patt1 = new RegExp('[A-Z]');
	var patt2 = new RegExp('[0-9]');
	
	if(patt1.exec(str) == null || patt2.exec(str) == null || str.length < 6){
		return false;
	}else{
		if(str == isNew){
			alert('Your new password must be different from your current.');
			return false;
		}
		return true;
	}
}

function alertEr(error){
	alert(error);
}
