<!--

//CycleLogic Functions

function openWindow(url, name)
{
	popupWin = window.open(url,name,'width=300,height=170,left=100,top=100');
}

function clearform()
{
	document.sms.reset();
}

function send()
{
	//var min_val	= document.sms.min.value;
	//var msg_val	= document.sms.msg.value;
	var min_val = document.sms.minTemp.value;
	var msg_val = document.sms.msgTemp.value;
	if (min_val.length < 10) {
	  	alert ("El numero de tu celular debe ser de 10 digitos. Por favor intenta de nuevo.");
		return false;
	}
	else {
		if (msg_val.length < 1) {
		    alert ("Por favor escribe un mensaje.");
			return false;
		}else {
			if (checkFields() == true) {
					document.sms.msg.value = document.sms.msgTemp.value;
					document.sms.min.value = document.sms.minTemp.value
					document.sms.totalCounter.value = document.sms.totalCounterTemp.value;
					document.sms.msgTemp.value = "";
					document.sms.minTemp.value = "";
					document.sms.totalCounterTemp.value = "";
					openWindow("","ie1","");
			} else {
					return false;
			}
		}
	}
}

function countChars(form) {
		var intLimit = 160;
		//var varValue = document.sms.msg.value;
		var varValue = document.sms.msgTemp.value;
		/* flag to set the counter increment ascendent (true) or descendent (false) */
		var flagIncCounter = true;
		document.sms.totalChars.value = varValue.length;
		document.sms.msg_total.value = varValue;
		if (document.sms.totalChars.value > intLimit) {
			alert ("Disculpa, la cantidad de caracteres por mensaje es solo de " + intLimit + ".");
			document.sms.msgTemp.value = varValue.substring(0, intLimit);
			if (flagIncCounter == true){
				document.sms.totalCounterTemp.value = intLimit;
			}else{
				document.sms.totalCounterTemp.value = "0";
			}
		}else{
			if (flagIncCounter == true){
				document.sms.totalCounterTemp.value = varValue.length;
			}else{
				document.sms.totalCounterTemp.value = intLimit - varValue.length;
			}
		}
}

function checkFields() {

	//Create and Initialize temp variables
	var blnValid = 1;								//Flag used to determine whether or not to proceed with the submit

	var strGeneralMsg1 = "";						//General Msg header for null fields
	//var strGeneralMsg2 = "";						//General Msg header for illegal characters
	var strGeneralMsg3 = "";						//General Msg header for spaces in string
	var strGeneralMsg4 = "";						//General Msg header numeric reguirements and illegal characters

	var strCheckFields1 = "";
	//var strCheckFields2 = "";
	var strCheckFields3 = "";
	var strCheckFields4 = "";

	var strFinalMsg = "";
	var strACTemp = "";

		//------------------------------------------------------------------------------------
		// Phone Number field validation
		//------------------------------------------------------------------------------------

		//Can't be null
		if (document.sms.minTemp.value == "") {
			strCheckFields1 = 'Número' + '\n';
			blnValid = 0;
		}
		else {
			//Must not contain spaces
			if (CheckForValidChar(document.sms.minTemp.value, "space") == true) {
				strCheckFields3 = 'Numero' + '\n';
				blnValid = 0;

			}
			else {
				//Must be a number
				if (CheckForValidChar(document.sms.minTemp.value, "num") == false) {
					strCheckFields4 = 'Numero' + '\n';
					blnValid = 0;

				}
			}
		}
		if (blnValid == 0)
			{
				//Not valid - Message to User needed
				//Setup message sections

				if (strCheckFields1 != "") {
					strGeneralMsg1 = "Para continuar, debes completar los siguientes campos.";					//null fields
					strFinalMsg = strGeneralMsg1 + "\n\n" + strCheckFields1 + "\n\n";
				}

				//if (strCheckFields2 != "") {
				//	strGeneralMsg2 = "Los siguientes campos contienen caracteres invalidos:";					//invalid characters
				//	strFinalMsg = strFinalMsg + strGeneralMsg2 + "\n\n" + strCheckFields2 + "\n\n";
				//}

				if (strCheckFields3 != "") {
					strGeneralMsg3 = "Los siguientes campos no deben tener espacios:";					//spaces in string
					strFinalMsg = strFinalMsg + strGeneralMsg3 + "\n\n" + strCheckFields3 + "\n\n";
				}

				if (strCheckFields4 != "") {
					strGeneralMsg4 = "Los siguientes campos deben ser numericos:";					//must be numeric and not invalid characters
					strFinalMsg = strFinalMsg + strGeneralMsg4 + "\n\n" + strCheckFields4 + "\n\n";
				}

				alert(strFinalMsg);
				return false;

			}
			else {
				return true;
			}
}


function checkFields() {

	//Create and Initialize temp variables
	var blnValid = 1;								//Flag used to determine whether or not to proceed with the submit

	var strGeneralMsg1 = "";						//General Msg header for null fields
	//var strGeneralMsg2 = "";						//General Msg header for illegal characters
	var strGeneralMsg3 = "";						//General Msg header for spaces in string
	var strGeneralMsg4 = "";						//General Msg header numeric reguirements and illegal characters

	var strCheckFields1 = "";
	//var strCheckFields2 = "";
	var strCheckFields3 = "";
	var strCheckFields4 = "";

	var strFinalMsg = "";
	var strACTemp = "";

		//------------------------------------------------------------------------------------
		// Phone Number field validation
		//------------------------------------------------------------------------------------

		//Can't be null
		if (document.sms.minTemp.value == "") {
			strCheckFields1 = 'Numero' + '\n';
			blnValid = 0;
		}
		else {
			//Must not contain spaces
			if (CheckForValidChar(document.sms.minTemp.value, "space") == true) {
				strCheckFields3 = 'Numero' + '\n';
				blnValid = 0;

			}
			else {
				//Must be a number
				if (CheckForValidChar(document.sms.minTemp.value, "num") == false) {
					strCheckFields4 = 'Numero' + '\n';
					blnValid = 0;

				}
			}
		}
		if (blnValid == 0)
			{
				//Not valid - Message to User needed
				//Setup message sections

				if (strCheckFields1 != "") {
					strGeneralMsg1 = "Para continuar, debes completar los siguientes campos.";					//null fields
					strFinalMsg = strGeneralMsg1 + "\n\n" + strCheckFields1 + "\n\n";
				}

				//if (strCheckFields2 != "") {
				//	strGeneralMsg2 = "Los siguientes campos contienen caracteres invalidos:";					//invalid characters
				//	strFinalMsg = strFinalMsg + strGeneralMsg2 + "\n\n" + strCheckFields2 + "\n\n";
				//}

				if (strCheckFields3 != "") {
					strGeneralMsg3 = "Los siguientes campos no deben tener espacios:";					//spaces in string
					strFinalMsg = strFinalMsg + strGeneralMsg3 + "\n\n" + strCheckFields3 + "\n\n";
				}

				if (strCheckFields4 != "") {
					strGeneralMsg4 = "Los siguientes campos deben ser numericos:";					//must be numeric and not invalid characters
					strFinalMsg = strFinalMsg + strGeneralMsg4 + "\n\n" + strCheckFields4 + "\n\n";
				}

				alert(strFinalMsg);
				return false;

			}
			else {
				return true;
			}
}