// JavaScript Document
/********************************************/
// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	/*******************************************************/
	
	
	
	/*codes to validate the phone no*/
	var minDigitsInIPhoneNumber = 10;
	
	function validatePhoneNo(field){
		if (field.value.length > minDigitsInIPhoneNumber) // if too long...trim it!
			field.value = field.value.substring(0, minDigitsInIPhoneNumber);
		
		if (checkPhoneNumber(field.value)==false){
			alert('Invalid phone number Enter correct phone number');
			field.value = "";
			field.focus();
		}
	}
	
	function validatePhoneNoLength(field){
		if (field.value.length == 0){}
		else if (field.value.length < minDigitsInIPhoneNumber){ // if too long...trim it!
			field.value = "";
			field.focus();
			alert('The phone number is not complete!');
		}
	}

		function validatePhoneNo(field){
			if (field.value.length > minDigitsInIPhoneNumber) // if too long...trim it!
				field.value = field.value.substring(0, minDigitsInIPhoneNumber);
			
			if (checkPhoneNumber(field.value)==false){
				alert('Invalid phone number Enter correct phone number');
				field.value = "";
				field.focus();
			}
		}
		
		function checkPhoneNumber(strPhone){
			return (isInteger(strPhone) && strPhone.length <= minDigitsInIPhoneNumber);
		}

		function isInteger(s)
		{   var i;
			for (i = 0; i < s.length; i++)
			{   
				// Check that current character is number.
				var c = s.charAt(i);
				if (((c < "0") || (c > "9"))) return false;
			}
			// All characters are numbers.
			return true;
		}
		
		/**************email validation*******************/
		function validateEmail(field){
			if (!(!(field.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)== null))) {  
				//alert('You must enter a valid email address');
				field.value = "";
				field.focus();
			}
		}
		

function checkForm()
{
    if(isEmpty(document.myFormSignUp.surname.value))
    {
        alert("Please enter your surname.");
        document.myFormSignUp.surname.focus();
    }
    else if(isEmpty(document.myFormSignUp.firstname.value))
    {
        alert("Enter your firstname.");
        document.myFormSignUp.firstname.focus();
    }
	else if(isEmpty(document.myFormSignUp.country.value))
    {
        alert("Select your country.");
        document.myFormSignUp.country.focus();
    }
    else if(isEmpty(document.myFormSignUp.phone.value))
    {
        alert("Enter your phone.");
        document.myFormSignUp.phone.focus();
    }
	else if(isEmpty(document.myFormSignUp.email.value))
    {
        alert("Enter your email.");
        document.myFormSignUp.email.focus();
    }
	else if(isEmpty(document.myFormSignUp.password.value))
    {
        alert("Enter your Password.");
        document.myFormSignUp.password.focus();
    }
	else if(isEmpty(document.myFormSignUp.confirm.value))
    {
        alert("The confirm field must not be blank.");
        document.myFormSignUp.confirm.focus();
    }
	else if(document.myFormSignUp.confirm.value != document.myFormSignUp.password.value)
    {
        alert("Ensure the password and the confirm field are the same.");
        document.myFormSignUp.confirm.focus();
    }
	else if(isEmpty(document.myFormSignUp.club.value))
    {
        alert("Select your club.");
        document.myFormSignUp.club.focus();
    }
	else
    {
        document.myFormSignUp.submit();
    }
}

function checkFormUpdate()
{
    if(isEmpty(document.myFormUpdate.surname.value))
    {
        alert("Please enter your surname.");
        document.myFormUpdate.surname.focus();
    }
    else if(isEmpty(document.myFormUpdate.firstname.value))
    {
        alert("Enter your firstname.");
        document.myFormUpdate.firstname.focus();
    }
    else if(isEmpty(document.myFormUpdate.phone.value))
    {
        alert("Enter your phone.");
        document.myFormUpdate.phone.focus();
    }
	else if(isEmpty(document.myFormUpdate.email.value))
    {
        alert("Enter your email.");
        document.myFormUpdate.email.focus();
    }
    else
    {
        document.myFormUpdate.submit();
    }
}

function checkSignInForm()
{
    if(isEmpty(document.myFormSignIn.email.value))
    {
        alert("Please enter your email.");
        document.myFormSignIn.email.focus();
    }
    else if(isEmpty(document.myFormSignIn.password.value))
    {
        alert("Enter your password.");
        document.myFormSignIn.password.focus();
    }
	else
    {
        document.myFormSignIn.submit();
    }
}

function checkManageMemberForm()
{
    if(!isNumeric(document.myManageMemberForm.add.value))
    {
        alert("Please enter correct additional value in the add field.");
		document.myManageMemberForm.add.value = "0";
        document.myManageMemberForm.add.focus();
    }
	else
    {
        document.myManageMemberForm.submit();
    }
}

function checkSingleSMSForm()
{
    if(isEmpty(document.mySingleSMSForm.origin.value))
    {
        alert("Please enter the sender id.");
        document.mySingleSMSForm.origin.focus();
    }
	else if(isEmpty(document.mySingleSMSForm.phone.value))
    {
        alert("Enter the recipient phone number.");
        document.mySingleSMSForm.phone.focus();
    }
	else if(isEmpty(document.mySingleSMSForm.message.value))
    {
        alert("Enter the SMS message.");
        document.mySingleSMSForm.message.focus();
    }
	else
    {
        document.mySingleSMSForm.submit();
    }
}

function checkContactForm()
{
	if(isEmpty(document.myContactUsForm.firstname.value))
    {
        alert("Enter your firstname.");
        document.myContactUsForm.firstname.focus();
    }
	else if(isEmpty(document.myContactUsForm.surname.value))
    {
        alert("Enter your surname.");
        document.myContactUsForm.surname.focus();
    }
	else if(isEmpty(document.myContactUsForm.email.value))
    {
        alert("Please enter email.");
        document.myContactUsForm.email.focus();
    }
	else if(isEmpty(document.myContactUsForm.message.value))
    {
        alert("Enter your message to us.");
        document.myContactUsForm.message.focus();
    }
	else
    {
        document.myContactUsForm.submit();
    }
}

function checkBulkSMSForm()
{
    if(isEmpty(document.myBulkSMSForm.origin.value))
    {
        alert("Please enter the sender id.");
        document.myBulkSMSForm.origin.focus();
    }
	else if(isEmpty(document.myBulkSMSForm.phone.value))
    {
        alert("Browse for the recipients.");
        document.myBulkSMSForm.phone.focus();
    }
	else if(isEmpty(document.myBulkSMSForm.message.value))
    {
        alert("Enter the SMS message.");
        document.myBulkSMSForm.message.focus();
	}
	else
    {
        document.myBulkSMSForm.submit();
    }
}

function checkBulkSMSFormb()
{
    if(isEmpty(document.myBulkSMSFormb.origin.value))
    {
        alert("Please enter the sender id.");
        document.myBulkSMSFormb.origin.focus();
    }
	else if(isEmpty(document.myBulkSMSFormb.message.value))
    {
        alert("Enter the SMS message.");
        document.myBulkSMSFormb.message.focus();
	}
	else
    {
        document.myBulkSMSFormb.submit();
    }
}


function checkPhoneBookForm()
{
    if(isEmpty(document.myPhoneBookForm.name.value))
    {
        alert("Please enter the list name.");
        document.myPhoneBookForm.name.focus();
    }
	else if(isEmpty(document.myPhoneBookForm.phone.value))
    {
        alert("Browse for the recipients.");
        document.myPhoneBookForm.phone.focus();
    }
	else
    {
        document.myPhoneBookForm.submit();
    }
}

function checkPostPasswordForm()
{
    if(isEmpty(document.myPostPasswordForm.email.value))
    {
        alert("Please enter your email.");
        document.myPostPasswordForm.email.focus();
    }
	else
    {
        document.myPostPasswordForm.submit();
    }
}

function checkBuyForm()
{
    if(isEmpty(document.myBuyForm.amount.value))
    {
        alert("Please enter valid amount.");
        document.myBuyForm.name.focus();
    }	
	
	else if(!isNumeric(document.myBuyForm.amount.value)){
		alert("Please enter valid amount (Between N50 and N20,000).");
		document.myBuyForm.amount.value = "";
        document.myBuyForm.amount.focus();
	}
	else if(document.myBuyForm.amount.value < 50 || document.myBuyForm.amount.value > 20000)
    {
        alert("Please enter valid amount (Between N50 and N20,000).");
		document.myBuyForm.amount.value = "";
        document.myBuyForm.amount.focus();
    }
	else
    {
        document.myBuyForm.submit();
    }
}

function checkReportForm()
{
	var opt;
    if(document.getElementById('div_abon_period_day').style.visibility == 'visible')
    {
        //alert("Single is visible.");
		opt = 'single';
    }
	else if(document.getElementById('div_abon_period_month').style.visibility == 'visible')
    {
        //alert("Month is visible.");
		opt = 'month';
    }
	else if(document.getElementById('div_abon_period_year').style.visibility == 'visible')
    {
        //alert("Year is visible.");
		opt = 'year';
    }
	else if(document.getElementById('div_abon_period_period').style.visibility == 'visible')
    {
        //alert("Period is visible.");
		opt = 'period';
    }
	else {
		//alert("All is visible.");
		opt = 'all';
	}
	document.frm.action = "../vg/report.php?option=" + opt +"&action=show";
    document.frm.submit();
}

function checkScheduleSMSForm()
{
	//alert("Today is after 14th January 2010");
	var smsDay = document.frm.abon_period_selDayDay.value;
	var smsMonth = document.frm.abon_period_selPeriodMonth.value;
	var smsYear = document.frm.abon_period_selPeriodYear.value;
	var smsHour = document.frm.abon_period_selDayMonth.value;//this is actuall the time to send the SMS
	
	smsMonth = smsMonth;
	var myDate=new Date();
	myDate.setFullYear(smsYear,smsMonth-1,smsDay);
	
	var today = new Date();
	var currentHour = today.getHours();

	if (myDate<today)
	  {
	  alert("SMS Schedule Date Must not be less than today");
	  }
	else if(smsHour <= currentHour)
	  {
	  alert("The time to broadcast SMS must be greater than the current time");
	  }
	  
   else if(isEmpty(document.myScheduleSMSForm.origin.value))
    {
        alert("Please enter the sender id.");
        document.myScheduleSMSForm.origin.focus();
    }
	else if(isEmpty(document.myScheduleSMSForm.phone.value))
    {
        alert("Browse for the recipients.");
        document.myScheduleSMSForm.phone.focus();
    }
	else if(isEmpty(document.myScheduleSMSForm.message.value))
    {
        alert("Enter the SMS message.");
        document.myScheduleSMSForm.message.focus();
	}
	else
    {
		document.myScheduleSMSForm.day.value = 	smsDay;
		document.myScheduleSMSForm.month.value = 	smsMonth;
		document.myScheduleSMSForm.year.value = 	smsYear;
		document.myScheduleSMSForm.hour.value = 	smsHour;
        document.myScheduleSMSForm.submit();
    }
}

function clearForm()
{
    document.mySingleSMSForm.origin.value = "";
    document.mySingleSMSForm.mcountry.value = "+";
	document.mySingleSMSForm.phone.value = "";
	document.mySingleSMSForm.message.value = "";
}

function clearFormBulk()
{
	document.myBulkSMSForm.origin.value = "";
	document.myBulkSMSForm.message.value = "";
}

function clearFormBulkb()
{
	document.myBulkSMSFormb.origin.value = "";
	document.myBulkSMSFormb.message.value = "";
}

function fnOpenHelp()
{
  w = window.open ("../help/","IS2009Help","location=no,status=no,toolbar=no,scrollbars=yes,menubar=no, width=500, height= 500")
  if (w != null)
    w.focus();
}

function isNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function isEmpty(field)
{
	field =trimEnter(field);
	return ((field == null) || (field.length == 0) || myTrim(field)=="");
}

function trimEnter(input)
{
	var tmp = "";

	for (var begin=0;begin <input.length;begin++)
	{
		var chrCode = input.charCodeAt(begin);
		if((chrCode!=13)&&(chrCode!=10))
		tmp+=input.charAt(begin);

	}
	return tmp;
}

function myTrim(str)
{
	var end = false;
	var ch;

	while(!end)
	{
		if (str.length == 0) break;
		ch = str.charAt(0);

		if (ch == ' ')
		{
			str = str.substring(1,str.length);
		}
		else
		{
			end = true;
		}
	}

	end = false;

	while(!end)
	{
		if (str.length == 0)
		{
			break;
		}

		ch = str.charAt(str.length-1);

		if (ch == ' ')
		{
			str = str.substring(0,str.length-1);
		}
		else
		{
			end = true;
		}
	}

	return str;
}
