var globalCursorPos;

/***********************************************
* Cool DHTML tooltip script II- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX =12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, theheight, thecolor)
{
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof theheight!="undefined") tipobj.style.height=theheight+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e)
{
	if (enabletip)
	{
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
		{
			tipobj.style.left="5px"
		}
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		{
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}
		else
		{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos)
		{
			pointerobj.style.visibility="visible"
		}
		else
		{
			pointerobj.style.visibility="hidden"
		}
	}
}

function hideddrivetip()
{
	if (ns6||ie)
	{
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
		}
}
document.onmousemove=positiontip



function Selection(textareaElement) 
{
    this.element = textareaElement;
}

Selection.prototype.create = function() 
{
    if (document.selection != null && this.element.selectionStart == null) 
    {
        return this._ieGetSelection();
    } 
    else 
    {
        return this._mozillaGetSelection();
    }
}

Selection.prototype._mozillaGetSelection = function() 
{
    return { 
        start: this.element.selectionStart, 
        end: this.element.selectionEnd 
    };
}

Selection.prototype._ieGetSelection = function() 
{
    this.element.focus();

    var range = document.selection.createRange();
    var bookmark = range.getBookmark();

    var contents = this.element.value;
    var originalContents = contents;
    var marker = this._createSelectionMarker();
    while(contents.indexOf(marker) != -1) {
        marker = this._createSelectionMarker();
    }
    var selection = range.text;

    var parent = range.parentElement();
    if (parent == null || parent.type != "textarea") 
    {
        return { start: 0, end: 0 };
    }
    range.text = marker + range.text + marker;
    contents = this.element.value;

    var result = {};
    result.start = contents.indexOf(marker);
    contents = contents.replace(marker, "");
    result.end = contents.indexOf(marker);

    this.element.value = originalContents;
    range.moveToBookmark(bookmark);
    range.select();

    return result;
}

Selection.prototype._createSelectionMarker = function() 
{
    return "##SELECTION_MARKER_" + Math.random() + "##";
}

//Kelvin (8th October 2008)
//Preview message content.
function popwindow()
{
	var thisForm = document.frmSendsms;
	var lf = (screen.width - 480)/2;
	var tf = (screen.height - 350)/2;
	var sizeIt = "width=265,height=370,scrollbars=no,resizable=no,top="+tf+",left="+lf;
	
	var contents = thisForm.messagebody.value;
	contents = contents.replace("&",":;:");
	//contents = escape(contents);
	if (contents.indexOf('{Col_Name}')!=-1 || contents.indexOf('{Col_Mobile}')!=-1 || contents.indexOf('{Col_Email}')!=-1 || contents.indexOf('{Col_Description}')!=-1 || contents.indexOf('{Col_PrefName}')!=-1)
	//if(contents.indexOf('%7BCol_Name%7D') != -1 || contents.indexOf('%7BCol_Mobile%7D') != -1 || contents.indexOf('%7BCol_Email%7D') != -1 || contents.indexOf('%7BCol_Description%7D') != -1 || contents.indexOf('%7BCol_PrefName%7D') != -1)
	{
		if (thisForm.contactlist.value != "")
		{
			var firstrecord = thisForm.contactlist.value.split(":::");
			var id = firstrecord[0].split("#");
			win = window.open('/sendsms/preview?id='+id[1]+'&type=individual&content='+contents,'mywindow',sizeIt);
		}
		else
		{
			if (thisForm.grouplist.value != "")
			{
				var firstrecord = thisForm.grouplist.value.split(":::");
				var id = firstrecord[0];
				win = window.open('/sendsms/preview?id='+id+'&type=group&content='+contents,'mywindow',sizeIt);
			}
			else
			{
				win = window.open('/sendsms/preview?content='+contents+'&type=empty&id=empty','mywindow',sizeIt);
			}
		}
	}
	else
	{
                win = window.open('/sendsms/preview?content='+contents,'mywindow',sizeIt);
	}
}

//Kelvin (8th October 2008)
//Select message template.
function SelectTemplate()
{
	var thisForm = document.frmSendsms;
	thisForm.messagebody.value = thisForm.col_template.value;
	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);	
}

function getcaretpos(txtReading)
{
	if (txtReading.createTextRange)
	{
		txtReading.caretPos = document.selection.createRange().duplicate();
	}
}

//Kelvin (8th October 2008)
//Personalise message - insert the reserve word into message content.
function insertintomsg()
{
	var thisForm = document.frmSendsms;
        divcal4.style.display = "";
        divcal3.style.display = "";

		
	var Source = document.getElementById('col_msg');
	if (thisForm.txt_send_to.value != "" && thisForm.phoneflagerror.value == "0")
	{
		alert(thisForm.wlerrmsg35.value + "'" + Source.options[Source.options.selectedIndex].value + "' " + thisForm.wlerrmsg36.value + ".\n" + thisForm.wlerrmsg37.value);
		thisForm.phoneflagerror.value = "1";
	}

	var first_part = thisForm.messagebody.value.substr(0, globalCursorPos);
	var second_part = thisForm.messagebody.value.substr(globalCursorPos, thisForm.messagebody.value.length);
		
	first_part = first_part + Source.options[Source.options.selectedIndex].text;
	var full_content = first_part = first_part + second_part;
		
	thisForm.messagebody.value = full_content;
		
	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);
	
}

function dispnosms()
{
	var thisForm = document.frmSendsms;
	thisForm.txt_no_sms.value = thisForm.crdtcal.value;
}

//Kelvin (8th October 2008)
//for WAP Push SMS and Picture SMS
function displaybrowse(type)
{
	var thisForm = document.frmSendsms;
	if(type == "check")
	{
		if(thisForm.function_WPS.value == 1)
		{
			if(thisForm.isWAP.checked)
			{
				type = "push_sms";
			}
		}
		
		if(thisForm.function_PS.value == 1)
		{
			if(thisForm.isPic.checked)
			{
				type = "picture_sms";
			}
		}
	}
	
	if(type == "push_sms" && thisForm.function_WPS.value == 1)
	{
		if(thisForm.isWAP.checked)
		{
			if(thisForm.function_PS.value == 1)
			{
				thisForm.isPic.checked = false;
				picture_div.style.display = "none";
			}
			browse_div.style.display = "";			
			if(thisForm.messagebody.value.indexOf('{'))
			{
				divcal3.style.display = "none";
				divcal4.style.display = "none";
			}
			
			var filename, ext;
			filename = thisForm.browse_file.value;
			ext = filename.substr(filename.length - 3, 3);
			if((ext.toLowerCase() != "png" && ext.toLowerCase() != "gif" && ext.toLowerCase() != "jpg" && ext.toLowerCase() != "jpeg") && filename != "")
			{
				thisForm.browse_file.value = "";
				alert(thisForm.wlerrmsg27.value);				
			}
		}
		else
		{
			browse_div.style.display = "none";
		}		
	}
	else if(type == 'picture_sms' && thisForm.function_PS.value == 1)
	{
		if(thisForm.isPic.checked)
		{
			if(thisForm.function_WPS.value == 1)
			{
				thisForm.isWAP.checked = false;
				browse_div.style.display = "none";
			}
			picture_div.style.display = "";			
                        divcal4.style.display = "";
                        divcal3.style.display = "";
			thisForm.unicheckbox.checked = false;
			
			var filename, ext;
			filename = thisForm.browse_picture.value;
			ext = filename.substr(filename.length - 3, 3);
			if(ext.toLowerCase() != "bmp" && filename != "")
			{
				thisForm.browse_picture.value = "";
				alert(thisForm.wlerrmsg23.value);				
			}
		}
		else
		{
			picture_div.style.display = "none";			
			if(thisForm.messagebody.value.indexOf('{'))
			{
				divcal3.style.display = "none";
				divcal4.style.display = "none";
			}
		}		
	}
	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);
}

function displaysch(type)
{
	var thisForm = document.frmSendsms;
	if (thisForm.chksch.checked)
	{
		divcal.style.display = "";
		thisForm.sendsubmit.value = thisForm.wlerrmsg2.value;
		thisForm.submitval.value = "Schedule Send";
	}
	else
	{
		divcal.style.display = "none";
		thisForm.submitval.value = "Send Now";
		thisForm.sendsubmit.value = thisForm.wlerrmsg1.value;
	}
		
	if(thisForm.function_PMFEF.value == 1)
	{	
		if (thisForm.isImport.checked)
		{
			divcal2.style.display = "";
		}
		else
		{
			divcal2.style.display = "none";
		}	
 	} 
}

function changesenderid()
{
	var thisForm = document.frmSendsms;
	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);
}

function populateDate(thisForm) 
{
	timeA = new Date(thisForm.mnuYr.options[thisForm.mnuYr.selectedIndex].text, thisForm.mnuMth.options[thisForm.mnuMth.selectedIndex].value, 1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	
	for (var i = 0; i < thisForm.mnuDay.length; i++) 
	{
		thisForm.mnuDay.options[0] = null;
	}
	
	for (var i = 0; i < daysInMonth; i++) 
	{	
		thisForm.mnuDay.options[i] = new Option(i+1);
		thisForm.mnuDay.options[i].value = i+1;
	}
	thisForm.mnuDay.options[0].selected = true;
}

//Kelvin (8th October 2008)
//Select contact from phone book. 
function MoveItem(ctrlSource, ctrlTarget, fg, contactType) 
{
	var thisForm = document.frmSendsms;
	var Source = document.getElementById(ctrlSource);
	var Target = document.getElementById(ctrlTarget);
	
	if ((Source != null) && (Target != null)) 
	{
		while ( Source.options.selectedIndex >= 0 ) 
		{
			var newOption = new Option(); // Create a new instance of ListItem
			newOption.text = Source.options[Source.options.selectedIndex].text;
			newOption.value = Source.options[Source.options.selectedIndex].value;
			
			Target.options[Target.length] = newOption; //Append the item in Target
			Source.remove(Source.options.selectedIndex);  //Remove the item from Source
		}
	}
	
	var sourcelen = 0;
	var TempSource;
	if (fg == 1) 
	{
		TempSource = Source;
	}
	else 
	{
		TempSource = Target;
	}	
		
	if (contactType == 1) 
	{
		var content = thisForm.allgroupinfo.value.split("||");
		thisForm.ttlgroup.value = 0;	
	} 
	else if (contactType == 0) 
	{
		thisForm.ttlindividual.value = 0;
	}
	sourcelen = TempSource.length
	var item = "";
	for (var i = 0; i < sourcelen; i++) 
	{  
		if (i == 0) 
		{
			item = TempSource.options[i].value;
		}  
		else 
		{
			item = item + ":::" + TempSource.options[i].value;
		}
		
		if (contactType == 1)
		{
			for(var x = 0; x < content.length; x++)
			{	
				var group_detail = content[x].split("@");
				if (group_detail[0] == TempSource.options[i].value) 
				{
					thisForm.ttlgroup.value = Number(thisForm.ttlgroup.value) + Number(group_detail[1]);
					break;					
				}
			}
		} 
		else if (contactType == 0) 
		{
			thisForm.ttlindividual.value = TempSource.length;
		}
	}
	if (contactType == 0) 
	{
		thisForm.contactlist.value = item;
		thisForm.txt_ttlind.value = TempSource.length
	}
	else 
	{
		thisForm.grouplist.value = item;
		thisForm.txt_ttlgrp.value = TempSource.length
	}
	
	thisForm.ttlreceipient.value = Number(thisForm.ttlgroup.value) + Number(thisForm.ttlindividual.value) + Number(thisForm.ttlcontact.value);
}

function cleartextbox() 
{
	var thisForm = document.frmSendsms;
	thisForm.txt_send_to.value = '';
}

function StatusWindow(mypage)//, myname, w, h, scroll) 
{
	var thisForm = document.frmSendsms;
	win = window.showModalDialog(mypage,"","dialogHeight: 540px; dialogWidth: 730px; center: Yes; help: No; resizable: No; status: No;");
	if (win != undefined)
	{
		thisForm.messagebody.value = win;
		textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);
	}	
}
function MM_openBrWindow(theURL,winName,features) 
{ 
	var width_height = features.split(",");	
  	var lf = (screen.width - 480)/2;
	var tf = (screen.height - 350)/2;
	var sizeIt = "width=400,height=250,scrollbars=yes,resizable=no,top="+tf+",left="+lf;
	win = window.open(theURL,'mywindow',sizeIt);
	if (window.focus) 
	{
		win.focus();
	}
}

function selected_pic(value)
{ 
	var thisForm = document.frmSendsms;
	thisForm.select_picture.value = value;
	document.getElementById("preview_pic").innerHTML = '<img src="/web/images/pictures/' + value + '" oncontextmenu="return false")/>';

}

function MM_modelDialog(theURL,winName,w,h,features) 
{
	// Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	// IE5 and other old browsers might allow a window that is
	// partially offscreen or wider than the screen. Fix that.
	// (Newer browsers fix this for us, but let's be thorough.)
	if (wleft < 0) 
	{
		w = screen.width;
		wleft = 0;
	}
	if (wtop < 0) 
	{
		h = screen.height;
		wtop = 0;
	}
	
	var win = window.open(theURL, winName, 'width=' + w + ',height=' + h + ',left=' + wleft + ',top=' + wtop + features);
	win.resizeTo(w, h);
	win.moveTo(wleft, wtop);
	win.focus();
}

function disable_getmethod() 
{
	var val = "";
	var thisForm = document.frmSendsms;
	for(var i = 0; i < thisForm.getmethod.length; i++ )
	{
		if( thisForm.getmethod[i].checked == true )
		{
			val = thisForm.getmethod[i].value;
		}
	}

	if(val == "browse_method")
	{
		thisForm.btnpicture.disabled = true;
		thisForm.browse_picture.disabled = false;
	}
	else
	{
		thisForm.btnpicture.disabled = false;
		thisForm.browse_picture.disabled = false;
	}
}

function disable_getmethod_wap() 
{
	var thisForm = document.frmSendsms;
	displaybrowse('push_sms');
	var val = "";

	for( i = 0; i < thisForm.getmethod_wap.length; i++ )
	{
		if( thisForm.getmethod_wap[i].checked == true )
		{
			val = thisForm.getmethod_wap[i].value;
		}
	}
	
	if(val != "enter_method_wap")
	{
		thisForm.browse_file.disabled = false;
		if(thisForm.function_WPSDIY.value == 1)
		{
			thisForm.enter_url.disabled = true;
		}
	}
	else
	{
		thisForm.browse_file.disabled = true;
		if(thisForm.function_WPSDIY.value == 1)
		{
			thisForm.enter_url.disabled = false;
		}
	}
}

function sendtocheck(objEvent) 
{ 
	var thisForm = document.frmSendsms;
	var iKeyCode;
	var last_char = "";
	if(thisForm.txt_send_to.value != "")
	{
		var ttlcharacter = thisForm.txt_send_to.value.length;
		last_char = thisForm.txt_send_to.value.substring(ttlcharacter - 1);
	}
	
	iKeyCode = objEvent.keyCode || objEvent.which;
	if(last_char == "," && (iKeyCode==44) || last_char == "" && (iKeyCode==44))
	{
		return false;
	}
	else
	{
		if((iKeyCode==44) || (iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==127) || (iKeyCode>=8 && iKeyCode<=9)) 
		{
			return true;
		}	
		else
		{
			return false;
		}
	}
}

function displayresend()
{
	var thisForm = document.frmSendsms;
	if (thisForm.mnuFrequency.value != "Once")
	{
		divresend.style.display = "";
	}
	else
	{
		divresend.style.display = "none";
	}	
}

function displaylimit()
{
	var thisForm = document.frmSendsms;
	var val = "";

	for( i = 0; i < thisForm.rdlimit.length; i++ )
	{
		if( thisForm.rdlimit[i].checked == true )
		{
			val = thisForm.rdlimit[i].value;
		}
	}

	if(val == "unlimit")
	{
		thisForm.txtlimit.disabled = true;
	}
	else
	{
		thisForm.txtlimit.disabled = false;
	}
}

function isIntegerKeyPress(objEvent)
{
	var thisForm = document.frmSendsms;
	var iKeyCode;
	iKeyCode = objEvent.keyCode || objEvent.which;
	
	if((iKeyCode>=48 && iKeyCode<=57) || iKeyCode==8 || iKeyCode==46 || iKeyCode==37 || iKeyCode==39 || iKeyCode==9)
	{		
		return true;
	}		
	else
	{
		alert(thisForm.wlerrmsg31.value);
		return false;
	}	
}

//Kelvin (8th October 2008)
//Calculate how many characters and number of SMS 
function smsCharCount(sms)
{
    var thisForm = document.frmSendsms;
    var str = new String(sms);
    var i = 0;
    var c = 0;
    var character;
    var previous_character;

    for (i = 0; i < str.length; i++) {
        character = str.charCodeAt(i);
        //Special characters need 2-byte to transmit.
        if ((character == 124) || (character == 94) || (character == 123) || (character == 125) || (character == 91) || (character == 93) || (character == 126) || (character == 92) || (thisForm.use_legacy_format.value == 0 && ((character > 255 && character < 913) || character == 930 || character > 937)) || (thisForm.use_legacy_format.value == 1 && character > 255)) {
            //for WAP Push sms
            if (thisForm.unicheckbox.checked == true) {
                    //If it's unicode, these special characters occupy 1 unicode only
                    c++;
            } else {
                    c += 2;
            }
        } else {
            if(character == 10) {
                if(previous_character == 13) {
                    //character code 13 = carriage return, 10 = line fit.
                    c++;
                } else {
                    c += 2;
                }
            } else {
                c++;
            }
        }
        previous_character = character;
    }
    return c;
}

function getCursorPosition()
{
	var sel = new Selection(document.getElementById("messagebody"));
	var s = sel.create();
	globalCursorPos = s.start;
}

function textCounter(field, countfield, numbersmsfield)
{
	var thisForm = document.frmSendsms;
	var result = true;
	var use_wap_push = false;
	var minus_number = 0;
	if(thisForm.function_WPS.value == 1)
	{
		if(thisForm.isWAP.checked == true)
		{
			use_wap_push = true;
		}
	}	
	
	if(thisForm.function_PS.value == 1)
	{
		if(thisForm.isPic.checked == true && thisForm.unicheckbox.checked == true)
		{
			result = false;
			alert(thisForm.wlerrmsg26.value);
			thisForm.unicheckbox.checked = false;			
		}
	}

	if(result == true)
	{
        var cchMsgContent = 0;
        var sSenderId = "";
        var cchSenderId = 0;
        var fConcate = true;
		
		//for WAP Push SMS
		var reserver_number = 0;
		if(thisForm.function_WPS.value == 1)
		{
			if (use_wap_push)
			{
				//Albert: check is browse file or user enter URL
				var ext_length = 0;
				var val = "";
				for(i = 0; i < thisForm.getmethod_wap.length; i++)
				{
					if(thisForm.getmethod_wap[i].checked==true)
					{
						val = thisForm.getmethod_wap[i].value;
					}
				}
				
				if(val != 'enter_method_wap')
				{
					if(thisForm.browse_file.value != "")
					{
						var position = '0';
						var keep_pos = '0';
						var keep_path = thisForm.browse_file.value;
						do 
						{
							position = keep_path.indexOf(".");						
							if (position != "-1")
							{
								keep_pos = Number(keep_pos) + Number(position) + 1;
								keep_path = keep_path.substring(position + 1);
							}				
						} while (position != '-1');							
						if(keep_pos != "0")
						{
							ext_length = Number(keep_path.length) + 1;
						}
					}		
					// /wap.pl?id=[5 characters file name] + Header info, Terminating, element or inline string = 34 characters
					var reserver_number = 34 + Number(thisForm.txturl.value.length) + Number(ext_length);
				}
				else
				{
					if(thisForm.enter_url.value.substr(0,11) == "http://www.")
					{
						minus_number = 11;
					}
					else
					{
						minus_number = 7;
					}
					//18 is referring to Header info, Terminating, element or inline string
					var reserver_number = 18 + Number(thisForm.enter_url.value.length) - Number(minus_number);
				}				
			}
		}

		var content = RTrim(field.value);
		
		if (thisForm.function_PMFPB.value == 1)
		{
			for (var i = 0; i < thisForm.col_msg.length; i++) 
			{	
				var add = "";
				while (content.indexOf(thisForm.col_msg.options[i].text) > -1) 
				{
					var pos = content.indexOf(thisForm.col_msg.options[i].text);
					content = "" + (content.substring(0, pos) + add + 
					content.substring((pos + thisForm.col_msg.options[i].text.length), content.length));
				}
			}
		}
        cchMsgContent = smsCharCount(content);
		
        var lSmsLength = cchMsgContent + cchSenderId + Number(reserver_number);
        // By Kelvin, 2011-10-13
        // Remove the checking as the max sms length exceed 10 SMS
        //if (lSmsLength > 1600)
        //{
                //var sMsgContent = field.value;
                //field.value = sMsgContent.substring(0, 1600 - cchSenderId);
                //alert (thisForm.wlerrmsg3.value);
        //}
        //else
        //{
            var lSingleSmsMax = 160;
            if (thisForm.concatenate_support.value == "1") 
            {
                var lConcateSmsMax = 153;
            } 
            else 
            {
                var lConcateSmsMax = 160;
            } 
                
            if (thisForm.unicheckbox.checked == true && use_wap_push == false)
            {
                lSingleSmsMax = 70;
                if (thisForm.concatenate_support.value == "1")
                {
                    var lConcateSmsMax = 67;
                }
                else
                {
                    var lConcateSmsMax = 70;
                }
            }
            else if (use_wap_push)
            {
                var lSingleSmsMax = 133;
                var lConcateSmsMax = 128;
            }
            else
            {
                var s = field.value;
                var j = 0;
                lSmsLength = lSmsLength + j;
            }
				
            if(thisForm.senderid_id)
            {
                var selected_senderid = thisForm.senderid_id.options[thisForm.senderid_id.options.selectedIndex].text;
            }
            else
            {
                var selected_senderid = "";
            }

            divcal5.style.display = "";

            if(document.getElementById("senderidcheckbox") && thisForm.senderidcheckbox.checked == true)
            {
                divsenderid.style.display = "";
                divsenderid2.style.display = "none";
                var append_senderid = true;
                var append_senderid_lSmsLength = lSmsLength + selected_senderid.length + 3;
            }
            else
            {
                divsenderid.style.display = "none";
                divsenderid2.style.display = "";
                var append_senderid = false;
            }
				
	
            if (lSmsLength > lSingleSmsMax)
            {
                if (fConcate)
                {
                    if (lSmsLength%lConcateSmsMax > 0)
                    {
                            countfield.value = lConcateSmsMax - (lSmsLength%lConcateSmsMax);
                            numbersmsfield.value = Math.floor(lSmsLength/lConcateSmsMax) + 1;
                    }
                    else
                    {
                            countfield.value = 0;
                            numbersmsfield.value = Math.floor(lSmsLength/lConcateSmsMax);
                    }
                }
                else
                {
                    if (lSmsLength%lSingleSmsMax > 0)
                    {
                            countfield.value = lSingleSmsMax - (lSmsLength%lSingleSmsMax);
                            numbersmsfield.value = Math.floor(lSmsLength/lSingleSmsMax) + 1;
                    }
                    else
                    {
                            countfield.value = 0;
                            numbersmsfield.value = Math.floor(lSmsLength/lSingleSmsMax);
                    }
                }
            }
            else
            {
                countfield.value = lSingleSmsMax - lSmsLength;
                numbersmsfield.value = 1;
            }
                
            if(append_senderid == true)
            {
                if (append_senderid_lSmsLength > lSingleSmsMax)
                {
                    if (fConcate)
                    {
                        if (append_senderid_lSmsLength%lConcateSmsMax > 0)
                        {

                                thisForm.charleftprefix.value = lConcateSmsMax - (append_senderid_lSmsLength%lConcateSmsMax);
                                thisForm.numberofsmsprefix.value = Math.floor(append_senderid_lSmsLength/lConcateSmsMax) + 1;
                        }
                        else
                        {
                                thisForm.charleftprefix.value = 0;
                                thisForm.numberofsmsprefix.value = Math.floor(append_senderid_lSmsLength/lConcateSmsMax);
                        }
                    }
                    else
                    {
                        if (append_senderid_lSmsLength%lSingleSmsMax > 0)
                        {
                                thisForm.charleftprefix.value = append_senderid_lSmsLength - (append_senderid_lSmsLength%lSingleSmsMax);
                                thisForm.numberofsmsprefix.value = Math.floor(append_senderid_lSmsLength/lSingleSmsMax) + 1;
                        }
                        else
                        {
                               thisForm.charleftprefix.value = 0;
                               thisForm.numberofsmsprefix.value = Math.floor(append_senderid_lSmsLength/lSingleSmsMax);
                        }
                    }
                }
                else
                {

                    thisForm.charleftprefix.value = lSingleSmsMax - append_senderid_lSmsLength;
                    thisForm.numberofsmsprefix.value = 1;
                }
            }
            else
            {

                thisForm.charleftprefix.value = countfield.value;
                thisForm.numberofsmsprefix.value = numbersmsfield.value;
            }

        //}
		thisForm.ttlcontact.value = 0;
		var replace_contact = thisForm.txt_send_to.value.replace(" ","");
		var lstReceipient = replace_contact.split(",");
		for(var x = 0; x < lstReceipient.length; x++) 
		{
			if (lstReceipient[x] != "") 
			{
				thisForm.ttlcontact.value = Number(thisForm.ttlcontact.value) + 1;
			}
		}

		thisForm.ttlreceipient.value = Number(thisForm.ttlgroup.value) + Number(thisForm.ttlindividual.value) + Number(thisForm.ttlcontact.value);        
	}
}

function validate(type)
{	
	var thisForm = document.frmSendsms;
	var result = true;
	var errormsg;
	
	thisForm.sendsubmit.disabled = true;
	thisForm.is_iso.value = "";

	//is import excel check?
	if (type == "import") 
	{
		thisForm.submitval.value = "Process Excel";
		var filename, ext;
		filename = thisForm.fileToUpload.value;
		ext = filename.substr(filename.length - 3, 3);

		if(ext.toLowerCase() != "xls")
		{
			alert(thisForm.wlerrmsg4.value);
			thisForm.sendsubmit.disabled=false;
		}
		else
		{
			smtindicator.style.display = "";
			excelindicator.style.display = "";
			processindicator.style.display = "";
			thisForm.submit();
		}		
	} 
	else
	{
		//for WAP Push SMS
		var val = "";	

		if(thisForm.function_WPS.value == 1)
		{
			for(i = 0; i < thisForm.getmethod_wap.length; i++)
			{
				if(thisForm.getmethod_wap[i].checked == true)
				{
					val = thisForm.getmethod_wap[i].value;
				}
			}
					
			
			if(thisForm.isWAP.checked)
			{
				//Albert: check is browse file or user enter URL
				if((thisForm.browse_file.value == "" && val == "browse_method_wap") || (val == "enter_method_wap"  && thisForm.enter_url.value == "")) 
				{
					result = false;
					if(thisForm.browse_file.value == '')
					{
						alert(thisForm.wlerrmsg22.value);
					}
					else
					{
						alert(thisForm.wlerrmsg32.value);
					}
				}
				else
				{
					if(val != "enter_method_wap")
					{
						var filename, ext;
						filename = thisForm.browse_file.value;
						ext = filename.substr(filename.length - 3, 3);
						if(ext.toLowerCase() == "png" || ext.toLowerCase() == "gif" || ext.toLowerCase() == "jpg" || ext.toLowerCase() == "jpeg")
						{
							thisForm.txtusrpath.value = thisForm.browse_file.value;									
						}
						else
						{
							result = false;
							thisForm.browse_file.value = "";
							alert(thisForm.wlerrmsg27.value);
						}	
					}
					else
					{
						filename = thisForm.enter_url.value;
						ext = filename.substr(0, 7);
						if(ext.toLowerCase()!= "http://")
						{
							result = false;
							alert(thisForm.wlerrmsg33.value);
						}
					}		
				}
			}
		}
		//End for wap push SMS
		
		
		//for Picture SMS
		var val = "";
		
		if(thisForm.function_PS.value == 1)
		{
			for(i = 0; i < thisForm.getmethod.length; i++)
			{
				if(thisForm.getmethod[i].checked == true)
				{
					val = thisForm.getmethod[i].value;
				}
			}			
			
			if(thisForm.isPic.checked)
			{
				if((thisForm.browse_picture.value == "" && val == "browse_method") || (thisForm.select_picture.value == "" && val == "select_method"))
				{
					result = false;
					alert(thisForm.wlerrmsg24.value);
				}
				else
				{
					var filename, ext;
					if(val == "browse_method")
					{
						filename = thisForm.browse_picture.value;
					}
					else
					{
						filename = thisForm.select_picture.value;
					}
					ext = filename.substr(filename.length - 3, 3);
					if(ext.toLowerCase() != "bmp")
					{
						result = false;
						alert(thisForm.wlerrmsg23.value);
					}
					else
					{
						thisForm.txtusrpath.value = thisForm.browse_picture.value;
					}
				}
			}
		}
	
		if (thisForm.submitval.value == "")
		{
			thisForm.submitval.value = "Send Now";
		}
		if (result == true)
		{
			if (Trim(thisForm.txt_send_to.value).length == 0 && thisForm.contactlist.value == "" && thisForm.grouplist.value == "")
			{
				result = false;
				thisForm.txt_send_to.focus();
				alert (thisForm.wlerrmsg5.value);
			}
			
			if (Trim(thisForm.txt_send_to.value).length > 0)
			{
				while(Trim(thisForm.txt_send_to.value).substring(Trim(thisForm.txt_send_to.value).length - 1) == ",") 
				{
        			thisForm.txt_send_to.value = Trim(thisForm.txt_send_to.value).substring(0, Trim(thisForm.txt_send_to.value).length - 1);
    			}
		
				var txtNumber = thisForm.txt_send_to.value;
				re =/ /gi;
				txtNumber = txtNumber.replace(re, "");
				var sendSplit = txtNumber.split(",");
				var invalidString = "";
			
				for (var i = 0; i < sendSplit.length; i++)
				{
					var isValidString = false;
					sendSplit[i] = Trim(sendSplit[i]);

					if(sendSplit[i] == "")
					{
						isValidString = false;
						sendSplit[i] = " ";
					}
					else if (!isitInteger(sendSplit[i])) 
					{
						isValidString = false;
					}					
					else
					{
						isValidString = true;
						if (sendSplit[i].length < 7)
						{
							isValidString = false;
						}
					}

					if (!isValidString)
					{
						if (invalidString.length == 0)
						{
							invalidString = invalidString + sendSplit[i];
						}
						else
						{
							invalidString = invalidString + "," + sendSplit[i];
						}
					}
				}//End for loop			
		
			if (invalidString.length != 0)
			{
				result = false;
				thisForm.txt_send_to.focus();
				alert (thisForm.wlerrmsg6.value + "\n[" + invalidString + "]\n" + thisForm.wlerrmsg7.value + "\n " + thisForm.wlerrmsg8.value);
			}
		}		
	}
	
	if (result == true)
	{
		if(Trim(thisForm.messagebody.value).length == 0)
		{
			result = false;
			thisForm.messagebody.focus();
			alert (thisForm.wlerrmsg9.value);
		}
		else
		{
			thisForm.messagebody.value = RTrim(thisForm.messagebody.value);
			//2009-05-22 By Kelvin
			//Replace smart quotes copy from Microsoft Word  
			thisForm.messagebody.value = thisForm.messagebody.value.replace(new RegExp(String.fromCharCode(8216),"g"),"'");
			thisForm.messagebody.value = thisForm.messagebody.value.replace(new RegExp(String.fromCharCode(8217),"g"),"'");
			thisForm.messagebody.value = thisForm.messagebody.value.replace(new RegExp(String.fromCharCode(8220),"g"),"\"");
			thisForm.messagebody.value = thisForm.messagebody.value.replace(new RegExp(String.fromCharCode(8221),"g"),"\"");	
			thisForm.messagebody.value = thisForm.messagebody.value.replace(new RegExp(String.fromCharCode(8211),"g"),"-");				
		}
	}

	if (result == true)
	{
		var Alpha = ' !"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ ]^_`abcdefghijklmnopqrstuvwxyz{|}~\'';
		var s = Trim(thisForm.messagebody.value);
		var isoValue = "";
		var is_wap_push = true;
		//var isoArray = ['00','01','02','03','04','05','06','07','08','09','0A','0B','0C','0D','0E','0F','10','11','12','13','14','15','16','17','18','19','1A','1B','1C','1D','1E','1F','20','21','22','23','24','25','26','27','28','29','2A','2B','2C','2D','2E','2F','30','31','32','33','34','35','36','37','38','39','3A','3B','3C','3D','3E','3F','40','41','42','43','44','45','46','47','48','49','4A','4B','4C','4D','4E','4F','50','51','52','53','54','55','56','57','58','59','5A','5B','5C','5D','5E','5F','60','61','62','63','64','65','66','67','68','69','6A','6B','6C','6D','6E','6F','70','71','72','73','74','75','76','77','78','79','7A','7B','7C','7D','7E','7F','80','81','82','83','84','85','86','87','88','89','8A','8B','8C','8D','8E','8F','90','91','92','93','94','95','96','97','98','99','9A','9B','9C','9D','9E','9F','A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','AA','AB','AC','AD','AE','AF','B0','B1','B2','B3','B4','B5','B6','B7','B8','B9','BA','BB','BC','BD','BE','BF','C0','C1','C2','C3','C4','C5','C6','C7','C8','C9','CA','CB','CC','CD','CE','CF','D0','D1','D2','D3','D4','D5','D6','D7','D8','D9','DA','DB','DC','DD','DE','DF','E0','E1','E2','E3','E4','E5','E6','E7','E8','E9','EA','EB','EC','ED','EE','EF','F0','F1','F2','F3','F4','F5','F6','F7','F8','F9','FA','FB','FC','FD','FE','FF'];		
		//var decimalcode2 = [161,163,164,165,167,191,196,197,198,201,209,214,216,220,223,224,228,229,230,231,232,233,236,241,242,246,248,249,252];
		if(thisForm.use_legacy_format.value == 1) {
                    var decimalcode = ['161','163','164','165','167','191','196','197','198','201','209','214','216','220','223','224','228','229','230','231','232','233','236','241','242','246','248','249','252','92','39'];
                    //var hexadecimalcode = ['A1','A3','A4','A5','A7','BF','C4','C5','C6','C9','D1','D6','D8','DC','DF','E0','E4','E5','E6','E7','E8','E9','EC','F1','F2','F6','F8','F9','FC'];
                } else {
                    var decimalcode = ['161','163','164','165','167','191','196','197','198','201','209','214','216','220','223','224','228','229','230','231','232','233','236','241','242','246','248','249','252','92','39','8217','8364','199','913','914','915','916','917','918','919','920','921','922','923','924','925','926','927','928','929','931','932','933','934','935','936','937'];
                }
		for (var i = 0; i < s.length; i++)
		{
			var single = s.charAt(i);
			var myKey = Alpha.indexOf(single)+ 32;

			if(myKey == 31 && (thisForm.is_iso.value == "" || thisForm.is_iso.value == "true"))
			{
				var gsm_charset = false;
				for(var c = 0; c < decimalcode.length; c++)
				{
					if(decimalcode[c] == s.charCodeAt(i))
					{
						gsm_charset = true;
						break;
					}
				}					
				if(gsm_charset == true)
				{					
					myKey = 0; 
					thisForm.is_iso.value = "true"; 
				}
				else
				{ 
					thisForm.is_iso.value = "false";
				}
			}
								
			if (myKey == 31 && single != 0)
			{
                                if (thisForm.unicheckbox.checked == 0)
                                {
                                        var totallength = Trim(thisForm.messagebody.value).length + Trim(thisForm.txt_send_to.value).length;
                                        totallength = totallength -1;
                                        if (Trim(thisForm.txt_send_to.value).length != 0)
                                        {
                                                totallength = totallength + 3;
                                        }
                                        var totalsms = Math.floor(totallength / 70);
                                        totalsms = totalsms + 1;
                                        var message;
                                        totalsms += ""
                                        i = s.length;

                                        //for Picture sms
                                        if (thisForm.function_PS.value == 1)
                                        {
                                                if(thisForm.isPic.checked == true)
                                                {
                                                        message = thisForm.wlerrmsg25.value;
                                                }
                                                else
                                                {
                                                        if (totalsms != thisForm.numberofsms.value)
                                                        {
                                                                message = thisForm.wlerrmsg10.value + "\n" + thisForm.wlerrmsg11.value + " " + totalsms + " " + thisForm.wlerrmsg12.value;
                                                        }
                                                        else
                                                        {
                                                                message = thisForm.wlerrmsg10.value;
                                                        }
                                                }
                                        }
                                        else
                                        {
                                                if (totalsms != thisForm.numberofsms.value)
                                                {
                                                        message = thisForm.wlerrmsg10.value + "\n" + thisForm.wlerrmsg11.value + " " + totalsms + " " + dthisForm.wlerrmsg12.value;
                                                }
                                                else
                                                {
                                                        message = thisForm.wlerrmsg10.value;
                                                }
                                        }

                                        var name = confirm(message)
                                        if (name == true)
                                        {
                                                thisForm.unicheckbox.checked = 1;
                                        }
                                        else
                                        {
                                                result = false;
                                        }
                                }
			}
		}		
	}

	if (result == true)
	{
		if (thisForm.unicheckbox.checked == 1)
		{
			var o = "";
			var s = thisForm.messagebody.value;
			for(m = 0; s.charAt(m); ++m)
			{
				c = s.charCodeAt(m);
				o += "&#"+c+";";
			}
			thisForm.fulltext.value = o;
			
		}
	}
	
	if (result == true)
	{
		if (thisForm.submitval.value =='Schedule Send')
		{			
			var schedule = new Date()
			var schyear = thisForm.mnuYr.value;
			var schmonth = (thisForm.mnuMth.value)-1;
			var schday = thisForm.mnuDay.value;
			var schhour = thisForm.mnuHour.value;
			var schmin = thisForm.mnuMinute.value;
			
			schedule.setFullYear(schyear, schmonth, schday);
			schedule.setHours(schhour, schmin);
			
			var today = new Date();			

			if (schedule > today)
			{
				//Albert: reschedule sms
				if(thisForm.mnuFrequency.value != "Once"){
					var limit_select = "";
					for( i = 0; i < thisForm.rdlimit.length; i++ )
					{
						if( thisForm.rdlimit[i].checked == true )
							limit_select = thisForm.rdlimit[i].value;
					}
				
					if(limit_select == "limit")
					{
						if(Number(thisForm.txtlimit.value) <= 0 || thisForm.txtlimit.value == "" || !isitInteger(thisForm.txtlimit.value))
						{
							result = false;			
							alert(thisForm.wlerrmsg30.value);
						}
						else
						{
							result = true;
						}	
					}
					else
					{
						result = true;
					}
				}
				else
				{
					result = true;
				}
			}
			else
			{
				result = false;				
				alert(thisForm.wlerrmsg13.value);
			}
		}
	}

	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);
	if (result == false)
	{
		thisForm.sendsubmit.disabled = false;
	}
	else
	{
		if (thisForm.unicheckbox.checked == true) 
		{
			var isUnicode = thisForm.wlerrmsg20.value;
		} 
		else 
		{
			var isUnicode = thisForm.wlerrmsg21.value;
		}

		var diplay_msg = thisForm.wlerrmsg14.value + ": " + thisForm.ttlreceipient.value +  "\n" + thisForm.wlerrmsg15.value + ": " + thisForm.senderid_id.options[thisForm.senderid_id.options.selectedIndex].text + "\n" + thisForm.wlerrmsg16.value + ": " + thisForm.numberofsms.value + "\n" + thisForm.wlerrmsg17.value + ": " + isUnicode + "\n" + thisForm.wlerrmsg18.value + ": " + thisForm.messagebody.value + "\n\n" + thisForm.wlerrmsg19.value;		
		
		if(thisForm.function_CMBSS.value == 1)
		{
			if (confirm(diplay_msg)) 
			{
				smtindicator.style.display = "";
				var contents = thisForm.messagebody.value;
				if (contents.indexOf('{Col_Name}') != -1 || contents.indexOf('{Col_Mobile}') != -1 || contents.indexOf('{Col_Email}') != -1 || contents.indexOf('{Col_Description}') != -1 || contents.indexOf('{Col_PrefName}') != -1)	
				{
					thisForm.phoneflag.value = "1";
				}	
				else
				{
					thisForm.phoneflag.value = "0";
				}	
				thisForm.submit();
			} 
			else 
			{
				thisForm.sendsubmit.disabled = false;
			}
		}
		else
		{
			smtindicator.style.display = "";
			var contents = thisForm.messagebody.value;
			if (contents.indexOf('{Col_Name}') != -1 || contents.indexOf('{Col_Mobile}') != -1 || contents.indexOf('{Col_Email}') != -1 || contents.indexOf('{Col_Description}') != -1 || contents.indexOf('{Col_PrefName}') != -1)	
			{
				thisForm.phoneflag.value = "1";
			}
			else
			{
				thisForm.phoneflag.value = "0";
			}
			thisForm.submit();
		}

            }
	}
}

function validate_fax(type)
{	
	var thisForm = document.frmSendfax;
	var result = true;
	var errormsg;
	
	thisForm.sendsubmit.disabled = true;

	//is import excel check?
	if (type == "import") 
	{
		thisForm.submitval.value = "Process Excel";
		var filename, ext;
		filename = thisForm.fileToUpload.value;
		ext = filename.substr(filename.length - 3, 3);

		if(ext.toLowerCase() != "xls")
		{
			alert(thisForm.wlerrmsg4.value);
			thisForm.sendsubmit.disabled=false;
		}
		else
		{
			smtindicator.style.display = "";
			excelindicator.style.display = "";
			processindicator.style.display = "";
			thisForm.submit();
		}		
	} 
	else
	{
		if (thisForm.submitval.value == "")
		{
			thisForm.submitval.value = "Send Now";
		}

        if (Trim(thisForm.txt_send_to.value).length == 0 && thisForm.contactlist.value == "" && thisForm.grouplist.value == "")
        {
            result = false;
            thisForm.txt_send_to.focus();
            alert (thisForm.wlerrmsg5.value);
        }

        if (Trim(thisForm.txt_send_to.value).length > 0)
        {
            while(Trim(thisForm.txt_send_to.value).substring(Trim(thisForm.txt_send_to.value).length - 1) == ",") 
            {
                thisForm.txt_send_to.value = Trim(thisForm.txt_send_to.value).substring(0, Trim(thisForm.txt_send_to.value).length - 1);
            }

            var txtNumber = thisForm.txt_send_to.value;
            re =/ /gi;
            txtNumber = txtNumber.replace(re, "");
            var sendSplit = txtNumber.split(",");
            var invalidString = "";

            for (var i = 0; i < sendSplit.length; i++)
            {
                var isValidString = false;
                sendSplit[i] = Trim(sendSplit[i]);

                if(sendSplit[i] == "")
                {
                    isValidString = false;
                    sendSplit[i] = " ";
                }
                else if (!isitInteger(sendSplit[i])) 
                {
                    isValidString = false;
                }					
                else
                {
                    isValidString = true;
                    if (sendSplit[i].length < 7)
                    {
                        isValidString = false;
                    }
                }

                if (!isValidString)
                {
                    if (invalidString.length == 0)
                    {
                        invalidString = invalidString + sendSplit[i];
                    }
                    else
                    {
                        invalidString = invalidString + "," + sendSplit[i];
                    }
                }
            }//End for loop			

            if (invalidString.length != 0)
            {
                result = false;
                thisForm.txt_send_to.focus();
                alert (thisForm.wlerrmsg6.value + "\n[" + invalidString + "]\n" + thisForm.wlerrmsg7.value + "\n " + thisForm.wlerrmsg8.value);
            }
        }		

        if (result == true)
        {
            if (thisForm.submitval.value =='Schedule Send')
            {			
                var schedule = new Date()
                var schyear = thisForm.mnuYr.value;
                var schmonth = (thisForm.mnuMth.value)-1;
                var schday = thisForm.mnuDay.value;
                var schhour = thisForm.mnuHour.value;
                var schmin = thisForm.mnuMinute.value;

                schedule.setFullYear(schyear, schmonth, schday);
                schedule.setHours(schhour, schmin);

                var today = new Date();			

                if (schedule > today)
                {
                    //Albert: reschedule sms
                    if(thisForm.mnuFrequency.value != "Once"){
                        var limit_select = "";
                        for( i = 0; i < thisForm.rdlimit.length; i++ )
                        {
                            if( thisForm.rdlimit[i].checked == true )
                                limit_select = thisForm.rdlimit[i].value;
                        }

                        if(limit_select == "limit")
                        {
                            if(Number(thisForm.txtlimit.value) <= 0 || thisForm.txtlimit.value == "" || !isitInteger(thisForm.txtlimit.value))
                            {
                                result = false;			
                                alert(thisForm.wlerrmsg30.value);
                            }
                            else
                            {
                                result = true;
                            }	
                        }
                        else
                        {
                            result = true;
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
                else
                {
                    result = false;				
                    alert(thisForm.wlerrmsg13.value);
                }
            }
        }

        if (result == false)
        {
            thisForm.sendsubmit.disabled = false;
        }
        else
        {

            var diplay_msg = thisForm.wlerrmsg14.value + ": " + thisForm.ttlreceipient.value +  "\n" + thisForm.wlerrmsg15.value + ": " + thisForm.senderid_id.options[thisForm.senderid_id.options.selectedIndex].text + "\n" + thisForm.wlerrmsg16.value + ": " + thisForm.numberofsms.value + "\n" + thisForm.wlerrmsg17.value + ": " + isUnicode + "\n" + thisForm.wlerrmsg18.value + ": " + thisForm.messagebody.value + "\n\n" + thisForm.wlerrmsg19.value;		

            if(thisForm.function_CMBSS.value == 1)
            {
                if (confirm(diplay_msg)) 
                {
                    smtindicator.style.display = "";
                    var contents = thisForm.messagebody.value;
                    if (contents.indexOf('{Col_Name}') != -1 || contents.indexOf('{Col_Mobile}') != -1 || contents.indexOf('{Col_Email}') != -1 || contents.indexOf('{Col_Description}') != -1 || contents.indexOf('{Col_PrefName}') != -1)	
                    {
                        thisForm.phoneflag.value = "1";
                    }	
                    else
                    {
                        thisForm.phoneflag.value = "0";
                    }	
                    thisForm.submit();
                } 
                else 
                {
                    thisForm.sendsubmit.disabled = false;
                }
            }
            else
            {
                smtindicator.style.display = "";
                var contents = thisForm.messagebody.value;
                if (contents.indexOf('{Col_Name}') != -1 || contents.indexOf('{Col_Mobile}') != -1 || contents.indexOf('{Col_Email}') != -1 || contents.indexOf('{Col_Description}') != -1 || contents.indexOf('{Col_PrefName}') != -1)	
                {
                    thisForm.phoneflag.value = "1";
                }
                else
                {
                    thisForm.phoneflag.value = "0";
                }
                thisForm.submit();
            }

        }
	}
}


function initialSetup() 
{
	var thisForm = document.frmSendsms;
	if(thisForm.function_PS.value == 1) {
		disable_getmethod();
	}
	if(thisForm.function_WPS.value == 1) {
		disable_getmethod_wap();
	}

	if(thisForm.txtdisplay.value == 'true')
	{
		if(thisForm.txtwindowenable.value == "yes")
		{
			var alert_title = thisForm.txtwindowtitle.value;
			var alert_body = thisForm.txtwindowcontent.value;
			if(thisForm.txtwindowtype.value == "inline")
			{
				var win_inline = dhtmlwindow.open("alert", "inline", alert_body, alert_title, "width=240px,height=120px,resize=1,scrolling=1,center=1,showmin=0", "recal");
			}
			else
			{
				var win_iframe = dhtmlwindow.open("popup_window", "iframe", "http://" + thisForm.txturl.value + "/sendsms/message", alert_title, "width=320px,height=160px,left=150px,top=10px,resize=1,scrolling=1,center=1,showmin=0", "recal");
			}
		}
	}
		
	textCounter(thisForm.messagebody, thisForm.charleft, thisForm.numberofsms);

	if(thisForm.check_wap.value == "on")
	{
		//for WAP Push SMS
		displaybrowse('check');
		displaysch('schedule');
		thisForm.mnuDay.options[thisForm.txtselectedday.value - 1].selected = true;
	} 
	else if(thisForm.check_pic.value == "on") 
	{
		//for Picture SMS
		displaybrowse('check');
		displaysch('schedule');
		thisForm.mnuDay.options[thisForm.txtselectedday.value - 1].selected = true;
	} 
	else 
	{ 
	
		var d = new Date();
		var todaymin = d.getMinutes()+90;
		d.setMinutes(todaymin);
		advanceyr = d.getFullYear();
		advancemth = d.getMonth()+1;
		advanceday = d.getDate();
		advancehr = d.getHours();

		for (var i = 0; i < thisForm.mnuYr.length; i++) 
		{
			if (advanceyr == thisForm.mnuYr.options[i].value)
			{
				thisForm.mnuYr.options[i].selected = true;
			}
		}
		for (var i = 0; i < thisForm.mnuMth.length; i++) 
		{
			if (advancemth == thisForm.mnuMth.options[i].value)
			{
				thisForm.mnuMth.options[i].selected = true;
			}
		}
                populateDate(document.frmSendsms);
		for (var i = 0; i < thisForm.mnuDay.length; i++) 
		{
			if (advanceday == thisForm.mnuDay.options[i].value)
			{
				thisForm.mnuDay.options[i].selected = true;
			}
		}
		for (var i = 0; i < thisForm.mnuHour.length; i++) 
		{
			if (advancehr == thisForm.mnuHour.options[i].value)
			{
				thisForm.mnuHour.options[i].selected = true;
			}
		}
	}
        
}
