

function checkContact() {
	if(document.getElementById("email").value =="") {
		window.alert("You must enter in an email address");
		return false;
	}

	if(document.getElementById("subject").value == "") {
		window.alert("You must select your type of question");
		return false;
	}


	
	return true;

}


// used in inbox and outbox, checks and unchecks all the checkboxes
// form name should be inbox
function check_all(status,boxName) {
	elem_form=document.forms["inbox"];
	len = elem_form.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (elem_form.elements[i].name==boxName) {
		elem_form.elements[i].checked=status;
		}
	}
}




// index.php, used for the radio buttons
function change_reply(obj) {
	
	if(obj == "1") {
		document.getElementById("from_field").style.display = "";
	}
	else if(obj == "0") {
	
		document.getElementById("from_field").style.display = "none";
	}
	
}

// index.php, used for the radio buttons
function display_email() {
	   
	radio_value = document.getElementById("reply").value
	alert(radio_value + "");
	if(radio_value == "email") { document.getElementById("from_field").style.display = ""; } 
	else { document.getElementById("from_field").style.display = "none"; }
	
}


// confirm delete of a inbox message
function cdelete_message() {

	return confirm("Are you sure you want to delete this message");

}


// delete a contact
function cdelete(obj) {

	if(confirm("Are you sure want to delete this contact")) {
		window.location.href = 'econtact.php?action=delete&cid=' + obj;
	}

}

//quick contacts, go to url

function selectURL() {
	
	url = document.getElementById("qcontacts").value;
	window.location.href = url;

}

//performed after a successful addition
function end_update(msg) {
	
	sURL = 
	window.alert("" + msg); 
	window.location.href = "contacts.php";
		
}


function check_msg_type(obj) {
	
	if(obj == 1) {
		window.location.href = "index.php";
	}
	else if(obj == 2) {
	
		window.location.href = "index.php?m=yes";
	}
	
}


function check_chars(msg) {

	var MAX_CHARS = 155;
	msg_length = msg.value.length ;
	//alert("LENGTH=" + msg_length);
	if(msg_length <= MAX_CHARS) { 
		document.getElementById("countchars").value = MAX_CHARS - msg_length;
		var overLimit;
		//Detect if IE, then use display appropriately, turns off the error message
		if(document.getElementById && (overLimit = document.getElementById('overLimit')) && overLimit.style)
			{ overLimit.style.display = 'none'; }
		else {
			document.getElementById('overLimit') = "none";
		}

	}

	
	else {
		if(document.getElementById && (overLimit = document.getElementById('overLimit')) && overLimit.style)
			{ overLimit.style.display = ''; }
		else {
			document.getElementById('overLimit') = "";
		}

		//alert("You've reached the maximum character limit, your message will be cut off you go above " + MAX_CHARS + " characters.");
	} 
}



function open_add() {

	window.open("http://www.textem.net/econtact.php?action=add", "addcontact", "height=550, width=340");

}

function open_edit(cid) { 

	window.open("http://www.textem.net/econtact.php?action=update&cid=" + cid, "addcontact", "height=550, width=340");
 
}

function open_add(number, mobile1, mobile2, mobile3) { 

	window.open("http://www.textem.net/econtact.php?action=add&number=" + number + "&mobile1=" + mobile1 + "&mobile2=" + mobile2 + "&mobile3=" + mobile3, "addcontact", "height=550, width=340");
 
}

function checkBlock() {

	if(document.getElementById("mobile1").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile1.focus();
		return false;
	}
	
	if(document.getElementById("mobile2").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile2.focus();
		return false;
	}	
	
	if(document.getElementById("mobile3").value.length < 4) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile3.focus();
		return false;
	}		

}

// Returns false if the string doesn't contain any special characters
function checkSpecial(str) {
	if(/[%&()\*:;\?+=\'\"]/.test(str)) {
		return true;
	}
	else {
		return false;
	}
}


// Returns false if the username doesn't contain of the disallowed characters
function checkUname(str) {
	if(/[%&(): \*;?+=\'\"]/.test(str)) {
		return true;
	}
	else {
		return false;
	}
}


// Returns true if the string contains all numbers

function checkNumber(str) {
	if(/\w/.test(str)) {
		return true;
	}
	else {
		return false;
	}

}

// Returns false if the string in the param isn't a number
function checkNumber(str) {

	if(/[^0-9]/.test(str)) {
		return true;
	}
	else {
		return false;
	}

}

/* USED IN THE INDEX.PHP */
function validate(checkTerms) {

	mobile1 = document.getElementById("mobile1").value;
	mobile2 = document.getElementById("mobile2").value;
	mobile3 = document.getElementById("mobile3").value;

	if(checkNumber(mobile1) || checkNumber(mobile2) || checkNumber(mobile3)) {
		window.alert("Only numbers allowed within the mobile number");
		document.mainForm.mobile1.focus();
		return false;
	}

	if(checkSpecial(document.getElementById("from").value)) {
		window.alert("No special characters or spaces are allowed in the form field");
		document.mainForm.from.focus();
		return false;
	}

	if(document.getElementById("mobile1").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile1.focus();
		return false;
	}
	
	if(document.getElementById("mobile2").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile2.focus();
		return false;
	}	
	
	if(document.getElementById("mobile3").value.length < 4) {
		window.alert("You're missing digits within the mobile number");
		document.mainForm.mobile3.focus();
		return false;
	}	
	
	if(document.getElementById("msg").value.length == 0) {
		window.alert("You can't send a text message without a message!");
		document.mainForm.msg.focus();
		return false;	
	}

	//make sure the person selected an option within the carrier field

	if(document.getElementById("carrier").value.length ==0) {
		window.alert("You need to select a Mobile Carrier");
		document.mainForm.carrier.focus();
		return false;			
	}

if(checkTerms != "1") { 
	if(!document.mainForm.terms.checked) {
		window.alert("You must check off the Terms and Conditions checkbox");
		return false;
	}
}  

	return true;
}


function checkEdit() {


	if(document.getElementById("label").value == "") {
		window.alert("You didn't enter in a Name");	
		document.econtact.label.focus();
		return false;		
	}	

	//check to see if the user entered in any special characters
	var specialCharacters = "";
	var mobile1 = document.getElementById("mobile1").value;
	var mobile2 = document.getElementById("mobile2").value;
	var mobile3 = document.getElementById("mobile3").value;
	var label = document.getElementById("label").value;
	if(checkSpecial(label)) {
		alert("Do not use any special characters or spaces");
		return false;
	}	//endif

	if(checkNumber(mobile1) || checkNumber(mobile2) || checkNumber(mobile3)) {
		alert("The mobile number should only contain numbers");
		return false;
	}
	

	if(document.getElementById("mobile1").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.econtact.mobile1.focus();
		return false;
	}
	
	if(document.getElementById("mobile2").value.length < 3) {
		window.alert("You're missing digits within the mobile number");
		document.econtact.mobile2.focus();
		return false;
	}	
	
	if(document.getElementById("mobile3").value.length < 4) {
		window.alert("You're missing digits within the mobile number");
		document.econtact.mobile3.focus();
		return false;
	}	
	
	if(document.getElementById("carrier").value == "") {
		window.alert("You must select a service provider");
		document.getElementById("carrier").focus();
		return false;
	
	}


	return true;

}

/* function checks the field on the registration page */
function checkLoginX() {
	
	if(document.getElementById("uname").value == "") {
		window.alert("You didn't enter in a username");	
		document.login.uname.focus();
		return false;		
	}
		
	if(document.getElementById("pwd").value == "") {
		window.alert("You didn't enter in a password");	
		document.login.pwd.focus();
		return false;		
	}	
	
	return true;
	
}

function checkTerms() {

	

}

/* function checks the field on the registration page */
function checkRegistration() {

	if(checkUname(document.getElementById("uname").value)) {
		window.alert("No special characters or spaces are allowed for your username");		
		document.register.uname.focus();
		return false;
	}	

	
	if(document.getElementById("uname").value == "") {
		window.alert("You didn't enter in a username");	
		document.register.uname.focus();
		return false;		
	}
	
	if(document.getElementById("email").value == "") {
		window.alert("You didn't enter in an email address");	
		document.register.email.focus();
		return false;		
	}	
	
	if(document.getElementById("pwd").value == "") {
		window.alert("You didn't enter in a password");	
		document.register.pwd.focus();
		return false;		
	}	

	if(document.getElementById("cpwd").value == "") {
		window.alert("You didn't confirm your password");	
		document.register.cpwd.focus();
		return false;		
	}

	var pwd = document.getElementById("pwd").value;
	//match any illegal characters
	var match = /[^a-zA-Z0-9]/.test(pwd);
	if(match == true) {
		window.alert("Your password cannot contain any special characters");
		document.getElementById("pwd").value = "";
		document.getElementById("cpwd").value = "";
		return false;
	}
	if(!document.register.terms.checked) {
		window.alert("You must check off the Terms and Conditions checkbox");
		return false;
	}



	//check to make sure the passwords match
	if (document.getElementById("pwd").value != document.getElementById("cpwd").value) {
		window.alert("Your passwords don't match, please make sure they match before submitting");
		document.getElementById("pwd").value = "";
		document.getElementById("cpwd").value = "";
		return false;
	}


	return true;
}



