function refreshCaptcha() {
	var img = document.images["captchaimg"];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}

function isValidPayment() {
	var amount;
	with(window.document.frmBuyCredits) {
		amount = txtAmount;
	}
	if(trim(amount.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter credits to calculate payment amount for further transaction';
		amount.focus();
		return false;
	} else if (trim(amount.value) <= 0) {
		document.getElementById('notification').innerHTML = 'Amount being processed is invalid';
		amount.focus();
		return false;
	} else {
		//document.frmBuyCredits.action = "processPayment.php";
		document.frmBuyCredits.action = "makePayment.php";
		return true;
	}
}
function isValidCreditTransfer() {
		var amount,username;
		with(window.document.frmtransferCredit) {
			amount = txtcreditTransfer;
			username=txtUsername;	
		}
		if(trim(amount.value) == '') {
			document.getElementById('notification').innerHTML = 'Please enter credits to transfer';
			amount.focus();
			return false;
		} else if (trim(amount.value) <= 0) {
			document.getElementById('notification').innerHTML = 'Amount being processed is invalid';
			amount.focus();
			return false;
		} else if (trim(username.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your username';
		username.focus();
		return false;
		} else if (!isValid(username.value)) {
			document.getElementById('notification').innerHTML = 'Please enter valid username';
			username.focus();
			return false;
		
		} else {
			
			document.frmtransferCredit.action = "transferCredit.php";
			return true;
		}
}
function isValidCredits() {
	var credits;
    with(window.document.frmBuyCredits) {
		credits = txtCredits;
	}
	if(trim(credits.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter credits you want to purchase';
		credits.focus();
		return false;
	} else if (!(isNaN(credits.value))) {
		document.getElementById('notification').innerHTML = 'Credits entered should be number only';
		credits.focus();
		return false;
	} else {
		document.frmBuyCredits.action = "buyCredits.php";
		return true;
	}
}

function UpdateScheduledJob(jobid){
	window.location ='updateScheduledJob.php?iJobId=' + jobid;
}

function StopScheduledJob(jobid){
	//window.location ='includes/stopScheduledJob.php?action=stop&iJobId=' + jobid;
	window.location ='manageScheduledJobs.php?action=stop&iJobId=' + jobid;
}

function StartScheduledJob(jobid){
	//window.location ='includes/startScheduledJob.php?action=start&iJobId=' + jobid;
	window.location ='manageScheduledJobs.php?action=start&iJobId=' + jobid;
}

function UpdateRecurringScheduledJob(JobId){
	window.location ='updateRecurringScheduledJob.php?iJobId=' + JobId;
}

function StopRecurringScheduledJob(RecurringJobId){
	//window.location ='includes/StopRecurringScheduledJob.php?action=stop&iJobId=' + RecurringJobId;
	window.location ='manageRecurringScheduledJob.php?action=stop&iJobId=' + RecurringJobId;
}

function StartRecurringScheduledJob(RecurringJobId){
	//window.location ='includes/StartRecurringScheduledJob.php?action=start&iJobId=' + RecurringJobId;
	window.location ='manageRecurringScheduledJob.php?action=start&iJobId=' + RecurringJobId;
}

function UpdateRecurringScheduledJobFile(RecurringJobId){
	//window.location ='includes/updateRecurringScheduledJobFile.php?iJobId=' + RecurringJobId;
	window.location ='updateRecurringScheduledJobFile.php?iJobId=' + RecurringJobId;
}

function calculate_time_zone() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	var i;
	// check just to avoid error messages
	if (document.getElementById('timezone')) {
		for (i = 0; i < document.getElementById('timezone').options.length; i++) {
			if (document.getElementById('timezone').options[i].value == convert(std_time_offset)) {
				document.getElementById('timezone').selectedIndex = i;
				break;
			}
		}
	}
}

function convert(value) {
	var hours = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var mins = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var secs = parseInt(value);
	var display_hours = hours;
	// handle GMT case (00:00)
	if (hours == 0) {
		display_hours = "00";
	} else if (hours > 0) {
		// add a plus sign and perhaps an extra 0
		display_hours = (hours < 10) ? "+0"+hours : "+"+hours;
	} else {
		// add an extra 0 if needed
		display_hours = (hours > -10) ? "-0"+Math.abs(hours) : hours;
	}

	mins = (mins < 10) ? "0"+mins : mins;
	return display_hours+":"+mins;
}

function isValidImport()
{
	var  cgroup,cmessage;
	with (window.document.frmContact) {
		cgroup = cmbGroup;
		contactlist = fileContact;
	}
	if (cgroup.selectedIndex == "") {
		document.getElementById('notification').innerHTML = 'Please select group!';
		return false;
	} else if (trim(contactlist.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload valid file!';
		contactlist.focus();
		return false;
	} else if (isValidFile(contactlist.value)) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload excel, text or csv file only!';
		contactlist.focus();
		return false;
	} else {
		//document.frmContact.action="includes/importContact.php";
		document.frmContact.action="import_contacts.php";
		return true;
	}
}

function isValidImportList()
{
	var  contactlist;
	with (window.document.frmLists) {
		contactlist = fileNumbers;
	}
	if (isValidFile(contactlist.value)) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload excel, text or csv file only!';
		contactlist.focus();
		return false;
	} else {
		//document.frmLists.action="includes/importListNumbers.php";
		document.frmLists.action="import_numbers.php";
		return true;
	}
}

function processSummary()
{
	document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="userSummary.php";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	window.scrollTo(0,0);
}

function processLog()
{
	document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="userLog.php";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	window.scrollTo(0,0);
}

function isValidSignupForm()
{
	var cname, email, company, mobile, username, password, confirmpassword, code;
	with(window.document.frmSignup) {
		cname = txtName;
		email = txtEmail;
		company = txtCompany;
		mobile = txtMobile;
		username = txtUsername;
		password = txtPassword;
		confirmpassword = txtConfirmPassword;
		code = captcha_code;
	}
	if(trim(cname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your contact name';
		cname.focus();
		return false;
	} else if (trim(email.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your email address';
		email.focus();
		return false;
	} else if(!isValidEmail(email.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid email address';
		return false;
	} else if (trim(company.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your company name';
		company.focus();
		return false;
	} else if (trim(mobile.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter mobile number';
		mobile.focus();
		return false;
	} else if(!isValidMobile(mobile.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid mobile no. <br/>Characters +, - and spaces are not allowed!';
		mobile.focus();
		return false;
	} else if (trim(username.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your username';
		username.focus();
		return false;
	} else if (!isValid(username.value)) {
		document.getElementById('notification').innerHTML = 'Please enter valid username';
		username.focus();
		return false;
	} else if ( trim(password.value) == '' ) {
		document.getElementById('notification').innerHTML = 'Please enter Password';
		password.focus();
		return false;
	} else if (!isValid(password.value)) {
		document.getElementById('notification').innerHTML = 'Please enter valid Password';
		password.focus();
		return false;
	} else if((password.value).indexOf(username.value)>=0) {
		document.getElementById('notification').innerHTML = 'Please do not use username in password field';
		password.focus();
		return false;
	} else if (trim(password.value) != trim(confirmpassword.value)) {
		document.getElementById('notification').innerHTML = 'Passwords entered do not match';
		confirmpassword.focus();
		return false;
	} else if (trim(code.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter verification code';
		code.focus();
		return false;
	} else {
		document.frmSignup.action = "signup.php";
		return true;
	}
}

function isValidContactForm()
{
	var cname, email, mobile, subject, message, code;
	with(window.document.frmContactUs) {
		cname = txtName;
		email = txtEmail;
		mobile = txtMobile;
		subject = txtSubject;
		message = txtMessage;
		code = captcha_code;
	}
	if(trim(cname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your name';
		cname.focus();
		return false;
	} else if (trim(email.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter your email address';
		email.focus();
		return false;
	} else if(!isValidEmail(email.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid email address';
		return false;
	} else if (trim(mobile.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter mobile number';
		mobile.focus();
		return false;
	} else if(!isValidMobile(mobile.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid mobile no. <br/>Characters +, - and spaces are not allowed!';
		return false;
	} else if (trim(subject.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter subject';
		subject.focus();
		return false;
	} else if (trim(message.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter message';
		message.focus();
		return false;
	} else if (trim(code.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter verification code';
		code.focus();
		return false;
	} else {
		document.frmContactUs.action = "contact.php";
		return true;
	}
}

function isValidProfile()
{
	var uname,company,email,mobile,password,confirmpassword;
	with(window.document.frmProfile) {
		uname = txtName;
		company = txtCompany;
		email = txtEmail;
		mobile = txtMobile;
		password = txtPassword;
		confirmpassword = txtConfirmPassword;
	}
	if(trim(uname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter Name!';
		uname.focus();
		return false;
	} else if(!isValid(uname.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in name';
		return false;
	} else if (trim(company.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter company name!';
		company.focus();
		return false;
	} else if(!isValid(company.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in company!';
		return false;
	} else if (trim(email.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter email id!';
		email.focus();
		return false;
	} else if(!isValidEmail(email.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid email id!';
		return false;
	} else if (trim(mobile.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter mobile number!';
		mobile.focus();
		return false;
	} else if(!isValidMobile(mobile.value)){
		document.getElementById('notification').innerHTML = 'Please enter valid mobile no. <br/>Characters +, - and spaces are not allowed!';
		return false;
	} else if(trim(password.value) !='' && !isValid(password.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in password';
		return false;
	} else if(trim(password.value) !='' && trim(password.value) != trim(confirmpassword.value)){
		document.getElementById('notification').innerHTML = 'Both passwords do not match !';
		return false;
	} else {
		document.frmProfile.action = "profile.php";
		return true;
	}

}

function isValidLogin()
{
	var username,password;
	with(window.document.frmLogin) {
		username = txtUsername;
		password = txtPassword;
	}
	if(trim(username.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter username!';
		username.focus();
		return false;
	} else if(!isValid(username.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in username';
		return false;
	} else if (trim(password.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter password!';
		password.focus();
		return false;
	} else if(!isValid(password.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in password';
		return false;
	} else {
		//document.frmLogin.action = "login.php";
		return true;
	}
}

function isValidUsername()
{
	var username;
	with(window.document.frmForgotPassword) {
		username = txtUsername;
	}
	if(trim(username.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter username!';
		username.focus();
		return false;
	} else if(!isValid(username.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in username';
		return false;
	} else {
		document.frmForgotPassword.action = "forgotpassword.php";
		return true;
	}
}

function isValidSingleSms ()
{
	var mobileno, senderid, message;
	with (window.document.frmSendSms) {
		mobileno = txtMobile;
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(mobileno.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter mobile number with country code!';
		mobileno.focus();
		return false;
	} else if (!isValidMobile(mobileno.value)) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid mobile number with country code !';
		mobileno.focus();
		return false;
	} else if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id !';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message !';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT, DATE and TIME to schedule message(s)!';
		return false;
	} else if(document.frmSendSms.chkSchedule.checked && document.frmSendSms.chkRecurSchedule.checked) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select one time scheduling or recurring scheduling!';
		return false;
	} else if((document.frmSendSms.chkRecurSchedule.checked) && (document.frmSendSms.r_timezone.selectedIndex == "-1")){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT for recurring schedule message(s)!';
		return false;
	} else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked)&&((minute_options.selectedIndex == "-1")||(hour_options.selectedIndex == "-1")||(day_options.selectedIndex == "-1") ||(month_options.selectedIndex == "-1"))){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and day for adavance setting !';
		return false;
	}else {
		//document.frmSendSms.action = "includes/sendSingleSms.php";
		document.frmSendSms.action = "single_sms.php";
		return true;
	}
}

function isValidBulkSms ()
{
	var filetoupload, senderid, message;
	with (window.document.frmSendSms) {
		filetoupload = fileToUpload;
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(filetoupload.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload valid file!';
		filetoupload.focus();
		return false;
	} else if (isValidFile(filetoupload.value)) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload excel, text or csv file only!';
		filetoupload.focus();
		return false;
	} else if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT, DATE and TIME to schedule message(s)!';
		return false;
	} else if(document.frmSendSms.chkSchedule.checked && document.frmSendSms.chkRecurSchedule.checked) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select one time scheduling or recurring scheduling!';
		return false;
	}else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked) && ((minute_options.selectedIndex == "-1")||(hour_options.selectedIndex == "-1") || (day_options.selectedIndex == "-1") || (month_options.selectedIndex == "-1"))){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and day for adavance setting !';
		return false;
	}else{
		//document.frmSendSms.action = "includes/sendBulkSms.php";
		document.frmSendSms.action = "blast_sms.php";
		return true;
	}
}

function isValidPersonalizedSms ()
{
	var filetoupload, senderid, message;
	with (window.document.frmSendSms) {
		filetoupload = fileToUpload;
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(filetoupload.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload valid file!';
		filetoupload.focus();
		return false;
	} else if (isValidFile(filetoupload.value)) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please upload excel, text or csv file only!';
		filetoupload.focus();
		return false;
	} else if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT, DATE and TIME to schedule message(s)!';
		return false;
	} else if(document.frmSendSms.chkSchedule.checked && document.frmSendSms.chkRecurSchedule.checked) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select one time scheduling or recurring scheduling!';
		return false;
	}else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked) && ((minute_options.selectedIndex == "-1") || (hour_options.selectedIndex == "-1") || (day_options.selectedIndex == "-1") || (month_options.selectedIndex == "-1"))){

		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and day for adavance setting !';
		return false;
	}else{
		//document.frmSendSms.action = "includes/sendPersonalizedSms.php";
		document.frmSendSms.action = "personalized_sms.php";
		return true;
	}
}

function insertAtCursor(myField, myValue) {

	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function isValidListSms ()
{
	var senderid, message;
	with (window.document.frmSendSms) {
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT, DATE and TIME to schedule message(s)!';
		return false;
	} else if(document.frmSendSms.chkSchedule.checked && document.frmSendSms.chkRecurSchedule.checked) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select one time scheduling or recurring scheduling!';
		return false;
	}else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked) && ((minute_options.selectedIndex == "-1") || (hour_options.selectedIndex == "-1") || (day_options.selectedIndex == "-1") || (month_options.selectedIndex == "-1"))){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and day for adavance setting !';
		return false;
	}else {
		//document.frmSendSms.action = "includes/sendListSms.php";
		document.frmSendSms.action = "list_sms.php";
		return true;
	}
}

function isValidGroupSms ()
{
	var mobilenos, senderid, message;
	with (window.document.frmSendSms) {
		mobilenos = txtMobileNumbers;
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(mobilenos.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select contact numbers!';
		mobilenos.focus();
		return false;
	} else if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enters some text message!';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select GMT, DATE and TIME to schedule message(s)!';
		return false;
	}else if(document.frmSendSms.chkSchedule.checked && document.frmSendSms.chkRecurSchedule.checked) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select one time scheduling or recurring scheduling!';
		return false;
	}else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked) && ((minute_options.selectedIndex == "-1") || (hour_options.selectedIndex == "-1") || (day_options.selectedIndex == "-1") || (month_options.selectedIndex == "-1"))){

		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and day for adavance setting !';
		return false;
	} else {
		//document.frmSendSms.action = "includes/sendGroupSms.php";
		document.frmSendSms.action = "group_sms.php";
		return true;
	}
}

function isValidScheduledSms()
{
	var senderid, message;
	with (window.document.frmSendSms) {
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message';
		message.focus();
		return false;
	} else if (document.frmSendSms.chkSchedule.checked && trim(document.frmSendSms.dc.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select datetime to schedule message!';
		return false;
	} else {
		//document.frmSendSms.action = "includes/updateScheduledBulkSms.php";
		document.frmSendSms.action = "updateScheduledJob.php";
		return true;
	}
}

function isValidRecurringScheduledSms()
{
	var senderid, message;
	with (window.document.frmSendSms) {
		senderid = txtSender;
		message = txtMessage;
	}
	if (trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSendSms.txtSender.select();
		senderid.focus();
		return false;
	} else if (trim(message.value)=='') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter some text message';
		message.focus();
		return false;
	} else if((document.frmSendSms.chkRecurSchedule.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule !';
		return false;
	}else if((document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_comm_setting.checked==false) &&(document.frmSendSms.chkRecurSchedule.checked && document.frmSendSms.chk_adva_setting.checked==false)){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select recurring schedule type(common or advance setting)!';
		return false;
	}else if((document.getElementById("chk_adva_setting").checked)&&((minute_options.selectedIndex == "-1")||(hour_options.selectedIndex == "-1")||(day_options.selectedIndex == "-1") ||(month_options.selectedIndex == "-1"))){
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please select Minute, Hour and Days for adavance setting !';
		return false;
	}else{
		//document.frmSendSms.action = "includes/updateRecurringScheduledSms.php";
		document.frmSendSms.action = "updateRecurringScheduledJob.php";
		return true;
	}
}

function isValidGroup ()
{
	var gname;
	with (window.document.frmGroup) {
		gname = txtGroupName;
	}
	if(trim(gname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter group name!';
		gname.focus();
		return false;
	} else if(!isValid(gname.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in username!';
		gname.focus();
		return false;
	} else if(document.frmGroup.hidMode.value == 'm') {
		//document.frmGroup.action="includes/updateUsersGroup.php";
		document.frmGroup.action ='manage_group.php?action=edit';
		return true;
	}else {
		//document.frmGroup.action="includes/addUsersGroup.php";
		document.frmGroup.action ='manage_group.php?action=add';
		return true;
	}
}

function isValidList ()
{
	var lname;
	with (window.document.frmList) {
		lname = txtListName;
	}
	if(trim(lname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter List name!';
		lname.focus();
		return false;
	} else if(!isValid(lname.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in username!';
		lname.focus();
		return false;
	} else if(document.frmList.hidMode.value == 'm') {
		//document.frmList.action="includes/updateUsersList.php";
		document.frmList.action="manage_lists.php?action=edit";
		return true;
	} else {
		//document.frmList.action="includes/addUsersList.php";
		document.frmList.action="manage_lists.php?action=add";
		return true;
	}
}

function isValidSenderId ()
{
	var senderid;
	with (window.document.frmSenderId) {
		senderid = txtSender;
	}
	if(trim(senderid.value) == '') {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter sender id!';
		senderid.focus();
		return false;
	} else if (!(isNaN(senderid.value)) && senderid.value.length>11) {
		window.scrollTo(0,0);
		document.getElementById('notification').innerHTML = 'Please enter valid sender id !!! <br>Alphanumeric sender could not be more than 11 characters.<br>Numeric sender could not be more than 18 characters';
		document.frmSenderId.txtSender.select();
		senderid.focus();
		return false;
	} else if(document.frmSenderId.hidMode.value == 'm') {
		//document.frmSenderId.action="includes/updateUsersSenderId.php";
		document.frmSenderId.action="manage_sender_id.php?action=edit";
		return true;
	} else {
		//document.frmSenderId.action="includes/addUsersSenderId.php";
		document.frmSenderId.action="manage_sender_id.php?action=add";
		return true;
	}
}

function isValidContact ()
{
	var  cname,cmobile;
	with (window.document.frmContact) {
		cgroup = cmbGroup;
		cname = txtContactName;
		cmobile = txtMobile;
	}
	if (cgroup.selectedIndex == "") {
		document.getElementById('notification').innerHTML = 'Please select group!';
		return false;
	} else if(trim(cname.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter contact name!';
		cname.focus();
		return false;
	} else if(!isValid(cname.value)){
		document.getElementById('notification').innerHTML = 'Special characters not allowed in contact name!';
		cname.focus();
		return false;
	} else if(trim(cmobile.value) == '') {
		document.getElementById('notification').innerHTML = 'Please enter mobile number!';
		cmobile.focus();
		return false;
	} else if(!isValid(cmobile.value)){
		document.getElementById('notification').innerHTML = 'Special characters are not allowed in mobile number!';
		cmobile.focus();
		return false;
	} else if(document.frmContact.hidMode.value == 'm') {
		//document.frmContact.action="includes/updateUsersContact.php";
		document.frmContact.action="manage_contact.php?action=edit";
		return true;
	} else {
		document.frmContact.action="manage_contact.php?action=add";
		return true;
	}
}

function CheckAll()
{
	var count = document.frmSelectGroup.elements.length;
	for (i=0; i < count; i++)
	{
		document.frmSelectGroup.elements[i].checked = document.frmSelectGroup.checkAll.checked? true:false
	}
}

function selectCheckAll()
{
	var count = 0;
	for (i=0;i<document.frmSelectGroup.elements.length;i++)
	{
		if ((document.frmSelectGroup.elements[i].checked==true) && (document.frmSelectGroup.elements[i].name=='checkMobile'))
		{
			count = count + 1;
		}
	}
	if (count > 0 ) {
		document.frmSelectGroup.checkAll.checked = true;
	} else {
		document.frmSelectGroup.checkAll.checked = false;
	}
}
//-------------


function ApproveCreditTransfer(CreditTransferID)
{
	  var Code = prompt("Please Enter the Code !","");
       if ( Code != null )
        {
		 if( Code != "")
		 {
		  window.location ='includes/approveCreditTransfer.php?iCreditTransferID=' + CreditTransferID +'&iCode='+ Code;
			
		 }
		 else
		 {
		 alert("Please enter the Code.");
		 }	
        }
		else
		{
			
		}    
	    
}

function UnapproveCreditTransfer(CreditTransferID)
{
      
       window.location ='includes/unapproveTransferCredit.php?iCreditTransferID=' + CreditTransferID ;

      
}


//--------------------

function isValidSelect()
{
	var allMobile = "";
	if ( document.frmSelectGroup.checkAll.checked == false)
	{
		document.getElementById('notification').innerHTML = 'Please select contact numbers to send sms!';
		return false;
	} else {
		for (i=0;i<document.frmSelectGroup.elements.length;i++)
		{
			if ((document.frmSelectGroup.elements[i].checked==true) && (document.frmSelectGroup.elements[i].name=='checkMobile'))
			{
				allMobile=document.frmSelectGroup.elements[i].value +","+ allMobile;
			}
		}
		allMobile = allMobile.substring(0,allMobile.length-1);
		document.frmSelectGroup.action = 'group_sms.php?sMobile=' + allMobile;
	}
}

var xmlHttp;

function displayAllContacts(groupid) 
{ 
	var url="select_group.php";
	url=url+"?iGroupId="+groupid;
	window.location = url;
	//
	/*document.getElementById('nf').innerHTML = '<center><img src=../images/loading.gif></center>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);*/
}

function displayContacts(groupid)
{

	var url="manage_contact.php";
	url=url+"?iGroupId="+groupid;
	//alert(url);
	window.location = url;
	//window.document.location.href = 'manage_contact.php?iGroupId=' + groupid;
	// document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	// xmlHttp=GetXmlHttpObject();
	// if (xmlHttp==null)
	// {
		// alert ("Browser does not support HTTP Request");
		// return;
	// }
	// var url="manage_contact.php";
	// url=url+"?iGroupId="+groupid;

	// xmlHttp.onreadystatechange=stateChanged;
	// xmlHttp.open("GET",url,true);
	// xmlHttp.send(null);
}

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

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 ModifyGroup(groupid){

	// var url="manage_group.php";
	// url=url+"?iGroupId="+groupid;

	//window.location = url;
	window.location ='manage_group.php?mode=m&iGroupId=' + groupid;
	// document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	// xmlHttp=GetXmlHttpObject();
	// if (xmlHttp==null)
	// {
			// alert ("Browser does not support HTTP Request");
			// return;
	// }
	// var url="manage_group.php";
	// url=url+"?iGroupId="+groupid;
	// url = url + "&mode=m";
	// xmlHttp.onreadystatechange=stateChanged;
	// xmlHttp.open("GET",url,true);
	// xmlHttp.send(null);
	// window.scrollTo(0,0);
}

function DeleteGroup(groupid){
	if (confirm('Are you sure you want to delete this group ?')){
		if (confirm('All contacts within the group will be deleted!\nDo you want to continue deleting ?')){
			//window.location ='includes/deleteUsersGroup.php?iGroupId=' + groupid;
			window.location ='manage_group.php?action=delete&iGroupId=' + groupid;
		}
	}
}

function ModifyList(Listid){
	window.location ='manage_lists.php?mode=m&iListId=' + Listid;
	// document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	// xmlHttp=GetXmlHttpObject();
	// if (xmlHttp==null)
	// {
			// alert ("Browser does not support HTTP Request");
			// return;
	// }
	// var url="manage_lists.php";
	// url=url+"?iListId="+Listid;
	// url = url + "&mode=m";
	// xmlHttp.onreadystatechange=stateChanged;
	// xmlHttp.open("GET",url,true);
	// xmlHttp.send(null);
	// window.scrollTo(0,0);
}

function DeleteList(Listid){
	if (confirm('Are you sure you want to delete this List ?')){
		if (confirm('All contacts within the List will be deleted!\nDo you want to continue deleting ?')){
			//window.location ='includes/deleteUsersList.php?iListId=' + Listid;
			window.location ='manage_lists.php?action=delete&iListId=' + Listid;
		}
	}
}

function ImportContacts(Listid){
	window.location ='import_numbers.php?iListId=' + Listid;
}

function ExportContacts(Listid){
	window.location ='export_numbers.php?iListId=' + Listid;
}

function ModifySenderId(senderid){
	window.location ='manage_sender_id.php?mode=m&iSenderId=' + senderid;
	// document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	// xmlHttp=GetXmlHttpObject();
	// if (xmlHttp==null)
	// {
		// alert ("Browser does not support HTTP Request");
		// return;
	// }
	// var url="manage_sender_id.php";
	// url=url+"?iSenderId="+senderid;
	// url = url + "&mode=m";
	// xmlHttp.onreadystatechange=stateChanged;
	// xmlHttp.open("GET",url,true);
	// xmlHttp.send(null);
	// window.scrollTo(0,0);
}

function DeleteSenderId(senderid){
	if (confirm('Are you sure you want to delete this sender id ?')){
		//window.location ='includes/deleteUsersSenderId.php?iSenderId=' + senderid;
		window.location ='manage_sender_id.php?action=delete&iSenderId=' + senderid;

	}
}

function ModifyContact(contactid){
	window.location ='manage_contact.php?mode=m&iContactId=' + contactid;
	// document.getElementById('nf').innerHTML = '<img src=../images/loading.gif>';
	// xmlHttp=GetXmlHttpObject();
	// if (xmlHttp==null)
	// {
		// alert ("Browser does not support HTTP Request");
		// return;
	// }
	// var url="manage_contact.php";
	// url=url+"?iContactId="+contactid;
	// url = url + "&mode=m";
	// xmlHttp.onreadystatechange=stateChanged;
	// xmlHttp.open("GET",url,true);
	// xmlHttp.send(null);
	// window.scrollTo(0,0);
}

function DeleteContact(contactid){
	if (confirm(' Are you sure you want to delete this contact ?')){
		window.location ='manage_contact.php?action=delete&iContactId=' + contactid;
	}
}

function setMessageLength()
{
	if(document.frmSendSms.cmbMessageType.value=="0")
	{
		document.frmSendSms.hiddcount.value = "160" ;
		setCounter();
		document.frmSendSms.txtMessage.dir="ltr";
	}
	if(document.frmSendSms.cmbMessageType.value=="1")
	{
		document.frmSendSms.hiddcount.value  = "160";
		setCounter();
		document.frmSendSms.txtMessage.dir="ltr";
	}
	if(document.frmSendSms.cmbMessageType.value=="2")
	{
		document.frmSendSms.hiddcount.value  = "280";
		setCounter();
		document.frmSendSms.txtMessage.dir="ltr";
	}
	if(document.frmSendSms.cmbMessageType.value=="3")
	{
		document.frmSendSms.hiddcount.value  = "280";
		setCounter();
		document.frmSendSms.txtMessage.dir="ltr";
	}
	if(document.frmSendSms.cmbMessageType.value=="4")
	{
		document.frmSendSms.hiddcount.value  = "70";
		setCounter();
		document.frmSendSms.txtMessage.dir="rtl";
	}
	if(document.frmSendSms.cmbMessageType.value=="5")
	{
		document.frmSendSms.hiddcount.value  = "70";
		setCounter();
		document.frmSendSms.txtMessage.dir="ltr";
	}
}

function textCounter(field, maxlimit)
{
	var messagelen=1;
	var mesagelenudh;
	var messagelenudh1;
	var charactercount = checkLength(field);
	if (charactercount > maxlimit) {
		if(maxlimit == 160) {
			messagelen = Math.ceil(charactercount/maxlimit)*7;
		} else if(maxlimit == 280) {
			messagelen = Math.ceil(charactercount/maxlimit)*12;
		} else {
			messagelen = Math.ceil(charactercount/maxlimit)*3;
		}
		messagelenudh1 = messagelen + charactercount;
		messagelenudh = Math.ceil(messagelenudh1/maxlimit);
		return checkLength(field) + " : " + messagelenudh + " SMS Message(s)" ;
	} else { // otherwise, update 'characters left' counter
		return checkLength(field) + " : 1 SMS Message(s)";
	}
}

function checkLength(field)
{
	//var countMe = field.value.replace(/[\n\r\n]+/g, '');
	if (BrowserDetect.browser == "Firefox") {
		var countMe = field.value.replace(/[\n\r\n]/g, '  ');
	} else if (BrowserDetect.browser == "Safari") {
		var countMe = field.value.replace(/[\n\r\n]/g, '  ');
	} else {
		var countMe = field.value;
	}
        var escapedStr = encodeURI(countMe);
        if (escapedStr.indexOf("%") != -1) {
            var count = escapedStr.split("%").length - 1;
	    /*var occur = escapedStr.match(/%0A/g);
	    count = count + occur.length;*/
            if (count == 0) count++;  //perverse case; can't happen with real UTF-8
            var tmp = escapedStr.length - (count * 3);
            count = count + tmp;
        } else {
            count = escapedStr.length;
        }
        //alert(escapedStr + ": size is " + count)
	return count;
}

function setCounter(count)
{
	var charactercount = textCounter(document.frmSendSms.txtMessage,document.frmSendSms.hiddcount.value);
	document.frmSendSms.txtcount.value  = charactercount;
}

function isValidFile(path)
{
	start = path.lastIndexOf(".")
	if (start == -1) {
		return true;
	} else {
		start++
		extension = path.substring(start, path.length).toLowerCase()
	}

	if ((extension == "txt") || (extension == "csv") || (extension == "xls")) {
		return false;
	} else {
		return true;
	}
}

function ExportUserLog(username,fromdate,todate) {
        if (confirm('Do you want to export user log ?')){
			window.location ='includes/exportUserLog.php?sUsername=' + username + '&dtFrom=' + fromdate + '&dtTo=' + todate;
        }
}

//Returns true if parameter doesn't contains any special character other than given character else false.
function isValid(text)
{
	var val='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_ ';
	for (i=0; i<text.length; i++){
		if (val.indexOf(text.charAt(i),0) == -1)
			return false;
	}
	return true;
}

//Trims the leading and trailing spaces
function trim(text)
{
	return text.replace(/^\s+|\s+$/g,'');
}

//Validates whether the input is number or not.
function isNaN(text)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < text.length && IsNumber == true; i++)
	{
		Char = text.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}
//Validates sender id.
function isValidSender(text)
{
	var validChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.- ";
	for (i=0; i<text.length; i++)
	{
		if (validChars.indexOf(text.charAt(i),0) == -1)
			return false;
	}
	return true;
}

function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
}

//Validates mobile numbers.
function isValidMobile(text)
{
	var validChars = "0123456789+,";
	for (i=0; i<text.length; i++)
	{
      	if (validChars.indexOf(text.charAt(i),0) == -1)
      		return false;
	}
	return true;
}

var debug1 = true;
var debug2 = true;

function dec2hex ( textString ) {
	return (textString+0).toString(16).toUpperCase();
}

function  dec2hex2 ( textString ) {
	var hexequiv = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	return hexequiv[(textString >> 4) & 0xF] + hexequiv[textString & 0xF];
}

function  dec2hex4 ( textString ) {
	var hexequiv = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	return hexequiv[(textString >> 12) & 0xF] + hexequiv[(textString >> 8) & 0xF] + hexequiv[(textString >> 4) & 0xF] + hexequiv[textString & 0xF];
}

function convertCP2Char ( textString ) {
	var outputString = '';
	textString = textString.replace(/^\s+/, '');
	if (textString.length == 0) { return ""; }
	textString = textString.replace(/\s+/g, ' ');
	var listArray = textString.split(' ');
	for ( var i = 0; i < listArray.length; i++ ) {
		var n = parseInt(listArray[i], 16);
		if (n <= 0xFFFF) {
			outputString += String.fromCharCode(n);
		} else if (n <= 0x10FFFF) {
		n -= 0x10000
		outputString += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF));
    } else {
      outputString += '!erreur ' + dec2hex(n) +'!';
    }
  }
  return( outputString );
}

function convertCP2UTF8 ( textString ) {
  var outputString = "";
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var n = parseInt(listArray[i], 16);
    if (i > 0) { outputString += ' ';}
    if (n <= 0x7F) {
      outputString += dec2hex2(n);
    } else if (n <= 0x7FF) {
      outputString += dec2hex2(0xC0 | ((n>>6) & 0x1F)) + ' ' + dec2hex2(0x80 | (n & 0x3F));
    } else if (n <= 0xFFFF) {
      outputString += dec2hex2(0xE0 | ((n>>12) & 0x0F)) + ' ' + dec2hex2(0x80 | ((n>>6) & 0x3F)) + ' ' + dec2hex2(0x80 | (n & 0x3F));
    } else if (n <= 0x10FFFF) {
      outputString += dec2hex2(0xF0 | ((n>>18) & 0x07)) + ' ' + dec2hex2(0x80 | ((n>>12) & 0x3F)) + ' ' + dec2hex2(0x80 | ((n>>6) & 0x3F)) + ' ' + dec2hex2(0x80 | (n & 0x3F));
    } else {
      outputString += '!erreur ' + dec2hex(n) +'!';
    }
  }
  return( outputString );
}

function convertCP2UTF16 ( textString ) {
  var outputString = "";
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var n = parseInt(listArray[i], 16);
    if (i > 0) { outputString += '';}
    if (n <= 0xFFFF) {
      outputString += dec2hex4(n);
    } else if (n <= 0x10FFFF) {
      n -= 0x10000
      outputString += dec2hex4(0xD800 | (n >> 10)) + '' + dec2hex4(0xDC00 | (n & 0x3FF));
    } else {
      outputString += '!erreur ' + dec2hex(n) +'!';
    }
  }
  return( outputString );
}

function convertCP2HexNCR ( textString ) {
  var outputString = "";
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var n = parseInt(listArray[i], 16);
    outputString += '&#x' + dec2hex(n) + ';';
  }
  return( outputString );
}

function convertCP2DecNCR ( textString ) {
  var outputString = "";
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var n = parseInt(listArray[i], 16);
    outputString += ('&#' + n + ';');
  }
  return( outputString );
}

function convertChar2CP ( textString ) {
  var outputString = "";
  var haut = 0;
  var n = 0;
  for (var i = 0; i < textString.length; i++) {
    var b = textString.charCodeAt(i);  // alert('b:'+dec2hex(b));
    if (b < 0 || b > 0xFFFF) {
      outputString += '!erreur ' + dec2hex(b) + '!';
    }
    if (haut != 0) {
      if (0xDC00 <= b && b <= 0xDFFF) {
        outputString += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';
        haut = 0;
        continue;
      } else {
        outputString += '!erreur ' + dec2hex(haut) + '!';
        haut = 0;
      }
    }
    if (0xD800 <= b && b <= 0xDBFF) {
      haut = b;
    } else {
      outputString += dec2hex(b) + ' ';
    }
  }
  return( outputString.replace(/ $/, '') );
}

function convertUTF82CP ( textString ) {
  var outputString = "";
  var compte = 0;
  var n = 0;
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var b = parseInt(listArray[i], 16);  // alert('b:'+dec2hex(b));
    switch (compte) {
      case 0:
        if (0 <= b && b <= 0x7F) {  // 0xxxxxxx
          outputString += dec2hex(b) + ' ';
        } else if (0xC0 <= b && b <= 0xDF) {  // 110xxxxx
          compte = 1;
          n = b & 0x1F;
        } else if (0xE0 <= b && b <= 0xEF) {  // 1110xxxx
          compte = 2;
          n = b & 0xF;
        } else if (0xF0 <= b && b <= 0xF7) {  // 11110xxx
          compte = 3;
          n = b & 0x7;
        } else {
          outputString += '!erreur ' + dec2hex(b) + '! ';
        }
        break;
      case 1:
        if (b < 0x80 || b > 0xBF) {
          outputString += '!erreur ' + dec2hex(b) + '! ';
        }
        compte--;
        outputString += dec2hex((n << 6) | (b-0x80)) + ' ';
        n = 0;
        break;
      case 2: case 3:
        if (b < 0x80 || b > 0xBF) {
          outputString += '!erreur ' + dec2hex(b) + '! ';
        }
        n = (n << 6) | (b-0x80);
        compte--;
        break;
    }
  }
  return( outputString.replace(/ $/, '') );
}

function convertUTF162CP ( textString ) {
  var outputString = "";
  var haut = 0;
  var n = 0;
  textString = textString.replace(/^\s+/, '');
  if (textString.length == 0) { return ""; }
  textString = textString.replace(/\s+/g, ' ');
  var listArray = textString.split(' ');
  for ( var i = 0; i < listArray.length; i++ ) {
    var b = parseInt(listArray[i], 16);  // alert('b:'+dec2hex(b));
    if (b < 0 || b > 0xFFFF) {
      outputString += '!erreur ' + dec2hex(b) + '!';
    }
    if (haut != 0) {
      if (0xDC00 <= b && b <= 0xDFFF) {
        outputString += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';
        haut = 0;
        continue;
      } else {
        outputString += '!erreur ' + dec2hex(haut) + '!';
        haut = 0;
      }
    }
    if (0xD800 <= b && b <= 0xDBFF) {
      haut = b;
    } else {
      outputString += dec2hex(b) + ' ';
    }
  }
  return( outputString.replace(/ $/, '') );
}

function convertHexNCR2CP ( textString ) {
  var outputString = '';
  textString = textString.replace(/\s/g, '');
  var listArray = textString.split(';');
  for (var i = 0; i < listArray.length-1; i++) {
    if (i > 0) { outputString += ' ';}
    var n = parseInt(listArray[i].substring(3, listArray[i].length), 16);
    outputString += dec2hex(n);
  }
  return( outputString );
}

function convertDecNCR2CP ( textString ) {
  var outputString = '';
  textString = textString.replace(/\s/g, '');
  var listArray = textString.split(';');
  for (var i = 0; i < listArray.length-1; i++) {
    if (i > 0) { outputString += ' ';}
    var n = parseInt(listArray[i].substring(2, listArray[i].length), 10);
    outputString += dec2hex(n);
  }
  return( outputString );
}

function enable_common_setting(){
	if(document.frmSendSms.chk_comm_setting.checked){
		document.frmSendSms.common_options.disabled=false;
		document.frmSendSms.minute_options.disabled=true;
		document.frmSendSms.hour_options.disabled=true;
		document.frmSendSms.day_options.disabled=true;
		document.frmSendSms.month_options.disabled=true;
		document.frmSendSms.weekday_options.disabled=true;
		document.frmSendSms.weekday_options.disabled=true;
	}else{
		document.frmSendSms.common_options.disabled=true;
		document.frmSendSms.minute_options.disabled=false;
		document.frmSendSms.hour_options.disabled=false;
		document.frmSendSms.day_options.disabled=false;
		document.frmSendSms.month_options.disabled=false;
		document.frmSendSms.weekday_options.disabled=false;
	}
}

function enable_advance_setting(){
	if(document.frmSendSms.chk_adva_setting.checked){
		document.frmSendSms.minute_options.disabled=false;
		document.frmSendSms.hour_options.disabled=false;
		document.frmSendSms.day_options.disabled=false;
		document.frmSendSms.month_options.disabled=false;
		document.frmSendSms.weekday_options.disabled=false;
		document.frmSendSms.common_options.disabled=true;
	}else{
		document.frmSendSms.common_options.disabled=true;
		document.frmSendSms.common_options.disabled=false;
	}
}

function show_hide(){
	if (document.getElementById("chk_adva_setting").checked){
		document.getElementById("hideablearea").style.display = 'block';
	}else{
	   document.getElementById("hideablearea").style.display = 'none';
	}
}

function change_date_hr_min(){
	if (minute_options.selectedIndex == "-1"){
		document.getElementById('minute_options').selectedIndex=1;
	}
	if(hour_options.selectedIndex == "-1"){
		document.getElementById('hour_options').selectedIndex=1;
	}
	if(day_options.selectedIndex == "-1"){
		document.getElementById('day_options').selectedIndex=1;
	}
}

function change_hr_min(){
	if (minute_options.selectedIndex == "-1" ){
		document.getElementById('minute_options').selectedIndex=1;
	}
	if(hour_options.selectedIndex == "-1" ){
		document.getElementById('hour_options').selectedIndex=1;
	}
}

function change_min(){
	if (minute_options.selectedIndex == "-1"){
		document.getElementById('minute_options').selectedIndex=1;
	}
}

function keep_every(){
	if (minute_options.selectedIndex == "0" ){
		document.getElementById('minute_options').selectedIndex=0;
	}
	if (hour_options.selectedIndex == "0" ){
		document.getElementById('hour_options').selectedIndex=0;
	}
	if (day_options.selectedIndex == "0" ){
		document.getElementById('day_options').selectedIndex=0;
	}
	if (month_options.selectedIndex == "0" ){
		document.getElementById('month_options').selectedIndex=0;
	}
	if (weekday_options.selectedIndex == "0" ){
		document.getElementById('weekday_options').selectedIndex=0;
	}

}

function enable_setting_option(){
	if(document.frmSendSms.chkRecurSchedule.checked){

		document.frmSendSms.chk_comm_setting.disabled=false;
		document.frmSendSms.chk_adva_setting.disabled=false;
	}else{
		document.frmSendSms.chk_comm_setting.disabled=true;
		document.frmSendSms.chk_adva_setting.disabled=true;
		document.frmSendSms.common_options.disabled=true;
		document.getElementById("chk_adva_setting").checked=false;
		document.getElementById("chk_comm_setting").checked=false;
		document.getElementById("hideablearea").style.display = 'none';
	}
}

function cleardate(){
	document.frmSendSms.dc2.value="";
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

