 /*
 CROFT COMMUNICATIONS
 Copyright©, 2008
 All Rights Reserved
 smsBug® is a registered trademark and patents exist on 
 the intellectual property expressed.
 This code is protected by international patent and copyright
 laws. It may not be sold, used or distributed in any form
 without prior written consent, signed by the executive
 members of CROFT COMMUNICATIONS.
 Coded By:
 Neil Croft (info@smsbug.com)
 */
		var iPrevValue = '';
		var iPrice = 0.28;
		var bLoggedIn = false;
		var bIdentifiers = false;
		var bCredits, bTempId, bGroupId, bGroupName;
		var strConnErr = 'Error making connection. Please check your internet connectivity.';
		var strError = "Could not load page. Please check your internet connectivity.";
		var fromDate = (new Date(new Date().getTime() - 3600*24*3*1000).getMonth()+1) + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getDate() + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getFullYear();
		var toDate = (new Date(new Date().getTime() + 3600*24*1000).getMonth()+1) + '/' + new Date(new Date().getTime() + 3600*24*1000).getDate() + '/' + new Date(new Date().getTime() + 3600*24*1000).getFullYear();
		var todaysDate = (new Date(new Date().getTime() + 3600*24*1000).getMonth()+1) + '/' + new Date(new Date().getTime()).getDate() + '/' + new Date(new Date().getTime() + 3600*24*1000).getFullYear();
		var strPrefix = 'http://sms.chillnet.co.za/api/webservice.asmx';
		var originalText = '';
		var xsldoc;
		var xHistory;
		var xmlObject; 
		var xsltProcessor; 
		
		function cmdLoad(strPage) {
			new ajax(strPage + '.htm',{method: 'get',errorText: strError,displayText:'Loading '+ strPage + ' page...',onError: $('strError'),onComplete: function(originalRequest){$('strContent').innerHTML=originalRequest.responseText;}});
		}
		
		function showAjax(text){
			$('strError').innerHTML = '';
			if (text == null){
				$('strIndicatorText').innerHTML = '';	
			}else{
				$('strSending').style.visibility='visible';
				$('strIndicatorText').innerHTML = text;
				$('strError').style.visibility='visible';
			}
		}
		
		function hideAjax(){
			$('strSending').style.visibility='hidden';
		}
		
		function cmdshowBubble(evt, bubblename, timeout){
			if ($(bubblename).style.visibility != 'visible') {
				evt = (evt)? evt: ((window.event) ? window.event : "");
				if (evt){
					$(bubblename).style.top = evt.clientY + document.body.scrollTop + 10 + 'px';
					$(bubblename).style.left = evt.clientX + 'px';
					$(bubblename).style.position = 'absolute';
					$(bubblename).style.visibility = 'visible';
				}else{alert('cant show bubble!');}
				window.setTimeout('cmdhideBubble(' + bubblename + ')',timeout);
			}
		}
		
		function cmdhideBubble(bubblename) {
			try{
				$(bubblename).style.visibility = 'hidden';
			}catch(e){}
	    }
		
		function cmdRegister(){
			for (s = 0; s < document.getElementsByName('chkagree').length; s++) {
				if (document.getElementsByName('chkagree')[s].checked){
					new ajax(strPrefix + '/registerBulkWebAccount', {method: 'post',errorText: strConnErr, displayText: 'Registering Bulk Web Account', onError: $('strError'), postBody: 'Username=' + $('username').value + '&Password=' + $('password').value + '&Email_Address=' + $('emailaddress').value + '&Web_Verification=' + $('turing').value, onComplete: function(originalRequest){
					loadXSL('verify.xsl');
					displayXML(originalRequest.responseXML, 'strContent');
					}});
				}else{
					alert('Please check Terms and Conditions of this site!')
				}
			}
		}
		
		function cmdValidate(){
			try{
				$('username').value = $('vusername').value;
				$('password').value	= $('vpassword').value;
			}catch(ex) {alert(ex);}	
			new ajax(strPrefix + '/validateBulkWebAccount', {method: 'post',errorText: strConnErr, displayText: 'Validating Web Account', onError: $('strError'), postBody: 'Username=' + $('vusername').value + '&Activation_Code='  + $('vverification').value + '&Web_Verification=' + $('vturing').value, onComplete: function(originalRequest){
				loadXSL('validate.xsl');
				displayXML(originalRequest.responseXML, 'strContent');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('ValidateBulkAccount')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'BulkAuthenticationType'){
							if (x[i].firstChild.nodeValue == '0'){
								setTimeout(function wait(){}, 1000);
								cmdLogin();
							}
						}
					}
				}catch(ex){
					alert(ex);
				}}});		
		}
		
		function getUP(){
			return 'Username=' + $('username').value + '&Password=' + $('password').value;
		}
		
		function getUPEncoded(){
			strUsername = new String($('username').value);
			strUsername = encodeWebMessage(strUsername);
			return 'Username=' + strUsername + '%26Password=' + $('password').value;
		}
		
		function cmdLogin(){
			new ajax(strPrefix + '/getProfile', {method: 'post',errorText: strConnErr, displayText:'Retrieving Account Information',onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				displayLoginXML(originalRequest.responseXML);
				}});
		}
		
		function displayLoginXML(originalRequest){
			try{
				var x = originalRequest.documentElement.getElementsByTagName('Account')[0].childNodes;
				for (var i=0; i<x.length;i++){
					if (x[i].tagName == 'BulkAuthenticationType'){
						if (x[i].firstChild.nodeValue == 'OK')
							bLoggedIn = true;
					}else if (x[i].tagName == 'Credits'){
						bCredits = x[i].firstChild.nodeValue; 
					}else if (x[i].tagName == 'Identifiers'){
						if (x[i].firstChild.nodeValue == 'true')
							bIdentifiers = true; 
					}else if (x[i].tagName == 'TempId'){
						bTempId = x[i].firstChild.nodeValue;
					}	
				}
				
				if (bLoggedIn){	
					$('strCredits').innerHTML = bCredits;
					$('tempid').value = bTempId;
					if (!bIdentifiers){
						cmdGetSenderIds('false');
					}else{
						cmdGetQuickFireMessage();
					}
					$('strLoggedOut').style.display = 'none';
					$('strLoggedIn').style.display = '';
					$('strMainMenu').style.display = 'none';
				}else{	
					$('strError').innerHTML = "Login Error, please check your credentials.";
				}
			} catch (exe) {
				$('strError').innerHTML = 'Could not connect to chillnet.co.za. Check your internet connection.';
			}
		}
		
		function cmdForgotten() {
			new ajax(strPrefix + '/getForgottenPassword', {method: 'post',errorText: strConnErr,displayText:'Retrieving Forgotten Password', onError: $('strError'), postBody: 'Username=' + $('fusername').value + '&Web_Verification=' + $('vturing').value, onComplete: function(originalRequest){
				loadXSL('forgotten.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdLogout() {
			$('strLoggedOut').style.display = '';
			$('strLoggedIn').style.display = 'none';
			$('strMainMenu').style.display = '';
			$('strError').innerHTML = '';
			bLoggedIn = false;
			cmdLoad('home');
		}
		
		function cmdGetMessage(){
			new ajax(strPrefix + '/getContactListandSenderIdList', {method: 'post',errorText: strConnErr, displayText: 'Retrieving Contacts', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('send.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdGetScheduledMessage(){
			new ajax(strPrefix + '/getContactListandSenderIdList', {method: 'post',errorText: strConnErr, displayText: 'Retrieving Contacts', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('scheduledsend.xsl');
				displayXML(originalRequest.responseXML, 'strContent');
				try{
				$('dScheduled').value = todaysDate;
				}catch(ex){}	
			}});
		}
		
		function cmdGetQuickFireMessage(){
			new ajax(strPrefix + '/getSenderIdList', {method: 'post',errorText: strConnErr, displayText:'Retrieving Sender Identifiers',onError: $('strError'), postBody: getUP() + '&Verified=true', onComplete: function(originalRequest){
				loadXSL('quicksend.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdGetWAPMessage(){
			new ajax(strPrefix + '/getContactListandSenderIdList', {method: 'post',errorText: strConnErr, displayText: 'Retrieving Contacts', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('sendwap.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdGetContacts() {
			new ajax(strPrefix + '/getContactList', {method: 'post',errorText: strConnErr, displayText:'Retrieving Contacts', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('contacts.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdAddContact(){
			if ($('To_Mobile_Number').value == ''){
				alert('Contact values cannot be empty!');	
			}else{
				new ajax(strPrefix + '/addContact', {method: 'post',errorText: strConnErr,displayText: 'Adding Contact',onError: $('strError'), postBody: getUP() + '&Contact_Name=' + $('Contact_Name').value + '&Contact_Mobile_Phone=' + $('To_Mobile_Number').value, onComplete: function(originalRequest){
					loadXSL('addcontact.xsl');
					displayXML(originalRequest.responseXML, 'strAddResult');
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('Contacts')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Status_Code'){
								if (x[i].firstChild.nodeValue == '0'){
									setTimeout(function wait(){}, 10000);
									cmdGetContacts();
								}
							}
						}
					}
					catch(ex){alert(ex);}
				}});
			}
		}
		
		function cmdDeleteContact(contactname, contactmobilephone) {
			new ajax(strPrefix + '/deleteContact', {method: 'post',errorText: strConnErr,displayText: 'Deleting Contact', onError: $('strError'), postBody: getUP() + '&Contact_Name=' + contactname + '&Contact_Mobile_Phone=' + contactmobilephone, onComplete: function(originalRequest){
				loadXSL('deletecontact.xsl');
				displayXML(originalRequest.responseXML, 'strDeleteResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('Contacts')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								setTimeout(function wait(){}, 300);
								cmdGetContacts();
							}
						}
					}
				}
				catch(ex){alert(ex);}
				}});
		}
		
		function cmdGetGroups(){
			new ajax(strPrefix + '/getGroups', {method: 'post',errorText: strConnErr, displayText:'Retrieving Groups',onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('groups.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function jsUploadGroup(){    
			if (document.ddGroupForm.strGroupIdentifier.value == ''){
				alert('Please select a Group Identifier!');
				return;
			}
			try{
			$('uploadmobilenumber').value = $('username').value; 
			$('uploadpassword').value = $('password').value;
			$('uploadgroupid').value = document.ddGroupForm.strGroupIdentifier.value;
			}catch(ex){
				alert('default values: ' + ex);
			}
			var re_text = /\.csv/i;   
			var filename = $('file').value;   
			if (filename.search(re_text) == -1)    {
				$('myDiv').style.color = 'red';
				$('myDiv').innerHTML = "File does not have .csv extension";
				$('file').form.reset();
				return false;   
			}
			$('myDiv').style.color = '#CE1D51';   
			$('myDiv').innerHTML = "<img src='images/chillnet_indicator.gif'> Uploading file...";    
			$('file').form.submit();    
			$('file').disabled = true;    
			return true;
		}
		
		function jsUpload(){    
			try{
			$('uploadmobilenumber').value = $('username').value; 
			$('uploadpassword').value = $('password').value;
			}catch(ex){
				alert('default values: ' + ex);
			}
			var re_text = /\.csv/i;   
			var filename = $('file').value;   
			if (filename.search(re_text) == -1)    {
				$('myDiv').style.color = 'red';
				$('myDiv').innerHTML = "File does not have .csv extension";
				$('file').form.reset();
				return false;   
			}
			$('myDiv').style.color = '#CE1D51';   
			$('myDiv').innerHTML = "<img src='images/chillnet_indicator.gif'> Uploading file...";    
			$('file').form.submit();    
			$('file').disabled = true;    
			return true;
		}
		
		function checkLoaded(upload_field){
			try{
			if (document.getElementById('file').disabled == true){
				setTimeout(function wait(){}, 3000);
				if (document.all)
					document.getElementById('myDiv').innerHTML = upload_iframe.document.body.innerHTML; // IE way
				else{
				    document.getElementById('myDiv').innerHTML = document.getElementById('upload_iframe').contentDocument.body.innerHTML; //NN way
				}
				setTimeout(function wait(){}, 10000);	
				//cmdGetContacts();	
			}
			}catch(ex){
				document.getElementById('myDiv').innerHTML = "An error ocurred." + ex;
				setTimeout(function wait(){}, 10000);	
				//cmdGetContacts();
			}
			document.getElementById('file').disabled = false;
		}
		
		function checkLoadedGroup(upload_field){
			try{
			if (document.getElementById('file').disabled == true){
				setTimeout(function wait(){}, 3000);
				if (document.all)
					document.getElementById('myDiv').innerHTML = upload_iframe.document.body.innerHTML; // IE way
				else{
				    document.getElementById('myDiv').innerHTML = document.getElementById('upload_iframe').contentDocument.body.innerHTML; //NN way
				}
				setTimeout(function wait(){}, 10000);	
				//cmdGetGroups();	
			}
			}catch(ex){
				document.getElementById('myDiv').innerHTML = "An error ocurred." + ex;
				setTimeout(function wait(){}, 10000);	
				//cmdGetGroups();
			}
			document.getElementById('file').disabled = false;
		}
		
		function showReport(answerNo) {
			currentQA = eval("rp" + answerNo);
			if (currentQA.style.display == '') {
				currentQA.style.display = 'none';
			}
			else {
				currentQA.style.display = '';
			}
		}
		
		function cmdDropDownValidNumber(){
			new ajax(strPrefix + '/getNetworkInformation', {method: 'post',errorText: strConnErr,displayText:'Retrieving Network Information', onError: $('strError'), postBody: 'Mobile_Number=' + $('strSelect').value, onComplete: function(originalRequest){
				$('strDropDownValidNumber').style.display = '';
				loadXSL('cost.xsl');
				displayXML(originalRequest.responseXML, 'strDropDownValidNumber');}});	
		}
		
		function cmdCheckBoxValidNumber(){
			$('strCheckBoxValidNumber').style.display = 'none';
			var iChecked = '';
			for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
				if (document.getElementsByName('strCheckboxes')[s].checked){
					iChecked = iChecked + document.getElementsByName('strCheckboxes')[s].value + ',';
				}
			}
			new ajax(strPrefix + '/getNetworkInformation', {method: 'post',errorText: strConnErr,displayText:'Retrieving Network Information', onError: $('strError'), postBody: 'Mobile_Number=' + iChecked, onComplete: function(originalRequest){
				$('strCheckBoxValidNumber').style.display = '';
				loadXSL('cost.xsl');
				displayXML(originalRequest.responseXML, 'strCheckBoxValidNumber');}});	
		}
		
		function cmdAddGroup(){
			if ($('groupname').value == ''){
				alert('Group values cannot be empty!');	
			}else{
				new ajax(strPrefix + '/addGroup', {method: 'post',errorText: strConnErr,displayText:'Adding Group', onError: $('strError'), postBody: getUP() + '&Group_Name=' + $('groupname').value, onComplete: function(originalRequest){
					loadXSL('addgroup.xsl');
					displayXML(originalRequest.responseXML, 'strAddResult');
					
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('Groups')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Status_Code'){
								if (x[i].firstChild.nodeValue == '0'){
									setTimeout(function wait(){}, 10000);
									cmdGetGroups();
								}
							}
						}
					}
					catch(ex){alert(ex);}
					
					}});
			}
		}
		
		function cmdGetSenderIds(verified){
			new ajax(strPrefix + '/getSenderIdList', {method: 'post',errorText: strConnErr, displayText:'Retrieving Sender Identifiers',onError: $('strError'), postBody: getUP() + '&Verified=' + verified, onComplete: function(originalRequest){
				loadXSL('identifiers.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdAddSenderId(){
			if ($('Sender_Identifier').value == ''){
				alert('Sender identifiers values cannot be empty!');	
			}else{
				new ajax(strPrefix + '/addSenderId', {method: 'post',errorText: strConnErr,displayText: 'Adding Sender Identifier',onError: $('strError'), postBody: getUP() + '&Sender_Identifier=' + $('Sender_Identifier').value, onComplete: function(originalRequest){
					loadXSL('addsenderid.xsl');
					displayXML(originalRequest.responseXML, 'strAddResult');
					
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('identifiers')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Status_Code'){
								if (x[i].firstChild.nodeValue == '0'){
									setTimeout(function wait(){}, 10000);
									cmdGetSenderIds('false');
									getCredits();
								}
							}
						}
					}
					catch(ex){alert(ex);}
					}});
			}
		}
		
		function cmdDeleteSenderId(senderId){
			if (senderId == ''){
				alert('Sender identifiers values cannot be empty!');	
			}else{
				new ajax(strPrefix + '/deleteSenderId', {method: 'post',errorText: strConnErr,displayText: 'Deleting Sender Identifier',onError: $('strError'), postBody: getUP() + '&Sender_Identifier=' + senderId, onComplete: function(originalRequest){
					loadXSL('deletesenderid.xsl');
					displayXML(originalRequest.responseXML, 'strDeleteResult');
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('identifiers')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Status_Code'){
								if (x[i].firstChild.nodeValue == '0'){
									setTimeout(function wait(){}, 300);
									cmdGetSenderIds('false');
								}
							}
						}
					}
					catch(ex){alert(ex);}
					}});
			}
		}
		
		function cmdDisplayProfile(){
			new ajax(strPrefix + '/getProfile', {method: 'post',errorText: strConnErr, displayText:'Retrieving Account Information',onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('profile.xsl');
				displayXML(originalRequest.responseXML, 'strContent');
			}});
		}
		
		function cmdEditProfile(){
			$('strUsername').style.display = 'none';
			$('strUsernameInput').style.display = '';
			$('strEmail').style.display = 'none';
			$('strEmailInput').style.display = '';
			$('strUpdate').style.display = '';
			$('strUpdateCancel').style.display = '';
			$('strEdit').style.display = 'none';
			$('strResetPassword').style.display = 'none';
		}
		
		function cmdResetPassword(){
			$('strPassword').style.display = 'none';
			$('strPasswordInput').style.display = '';
			$('strUpdate').style.display = 'none';
			$('strUpdateCancel').style.display = 'none';
			$('strEdit').style.display = 'none';
			$('strResetPassword').style.display = 'none';
			$('strSavePassword').style.display = '';
			$('strSavePasswordCancel').style.display = '';
		}
		
		function cmdCancelProfile(){
			$('strUsername').style.display = '';
			$('strUsernameInput').style.display = 'none';
			$('strPassword').style.display = '';
			$('strPasswordInput').style.display = 'none';
			$('strEmail').style.display = '';
			$('strEmailInput').style.display = 'none';
			$('strUpdate').style.display = 'none';
			$('strUpdateCancel').style.display = 'none';
			$('strEdit').style.display = '';
			$('strResetPassword').style.display = '';
		}
		
		function cmdSavePasswordCancel(){
			$('strUsername').style.display = '';
			$('strUsernameInput').style.display = 'none';
			$('strPassword').style.display = '';
			$('strPasswordInput').style.display = 'none';
			$('strEmail').style.display = '';
			$('strEmailInput').style.display = 'none';
			$('strUpdate').style.display = 'none';
			$('strUpdateCancel').style.display = 'none';
			$('strEdit').style.display = '';
			$('strResetPassword').style.display = 'none';
			$('strSavePassword').style.display = 'none';
			$('strSavePasswordCancel').style.display = 'none';
		}
		
		function cmdUpdateProfile(){
			new ajax(strPrefix + '/updateProfile', {method: 'post',errorText: strConnErr,displayText: 'Updating Profile', onError: $('strError'), postBody: getUP() + '&New_Username=' + $('newusername').value + '&New_Email=' + $('newemail').value, onComplete: function(originalRequest){
				loadXSL('profile.xsl');
				$('username').value = $('newusername').value;
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdSavePassword(){
			new ajax(strPrefix + '/resetPassword', {method: 'post',errorText: strConnErr,displayText: 'Resetting Password', onError: $('strError'), postBody: getUP() + '&New_Password=' + $('newpassword').value, onComplete: function(originalRequest){
				loadXSL('profile.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdValidateNetwork(){
			new ajax(strPrefix + '/getNetworkInformation', {method: 'post',errorText: strConnErr,displayText: 'Retrieving Network Information', onError: $('strError'), postBody: 'Mobile_Number=' + $('To_Mobile_Number').value, onComplete: function(originalRequest){
				$('strValidNetwork').style.display = '';
				loadXSL('cost.xsl');
				displayXML(originalRequest.responseXML, 'strValidNetwork');}});	
		}
		
		function cmdVerifySenderId(senderId){
			if (senderId == ''){
				alert('Sender identifiers values cannot be empty!');	
			}else{
				new ajax(strPrefix + '/verifySenderId', {method: 'post',errorText: strConnErr,displayText: 'Verifying Sender Identifier',onError: $('strError'), postBody: getUP() + '&Sender_Identifier=' + senderId + '&Verification_Code=' + $(senderId).value, onComplete: function(originalRequest){
					loadXSL('verifyIdentifier.xsl');
					displayXML(originalRequest.responseXML, 'str' + senderId + '');
					
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('identifiers')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Status_Code'){
								if (x[i].firstChild.nodeValue == '0'){
									setTimeout(function wait(){}, 10000);
									cmdGetSenderIds('false');
								}
							}
						}
					}
					catch(ex){alert(ex);}
					}});
			}
			
		}
		
		function cmdSubmitPayment() {
			  var bValidated = true;
		      var strName = '';
		      var strInput = '';
			  var strBundle = document.InvoiceForm.strBundle.value;
		      $('button_submit_authorize').disabled = true; 
		      
			  strInput = $('cc').value;
			  while (strInput.indexOf(' ') >= 0){
				strInput = strInput.replace(' ','');
			  }
			  if (isNumeric(strInput) == false){
		         bValidated = false;
		         strName = 'Credit Card Number';
		         document.all.cc.focus();
		      }
		      if (bValidated){
		      	cmdLoad('creditcardprocessing');
				new ajax(strPrefix + '/addCreditCardPurchase', {method: 'post',errorText: strConnErr,displayText:'Submitting Payment Request', onError: $('strError'), postBody: getUP() + '&cardholder=' + $('cardholder').value + '&cc=' + $('cc').value + '&expmon=' + $('expmon').value + '&expyear=' + $('expyear').value + '&cvv=' + $('cvv').value + '&amount=' + $('price').value + '&credits=' + strBundle + '&tempId=' + $('tempid').value, onComplete: function(originalRequest){
					loadXSL('creditcard.xsl');
					displayXML(originalRequest.responseXML, 'strContent');
					getCredits();}});
			  }
		      else{
			 		$('button_submit_authorize').disabled = false; 
		      		alert('Please enter valid data into ' + strName + ' field.');
		      }
	    }
		
		function cmdGetHistory(){	
			new ajax(strPrefix + '/getSenderIdList', {method: 'post',errorText: strConnErr,displayText:'Retrieving SenderId List', onError: $('strError'), postBody: getUP() + '&Verified=true', onComplete: function(originalRequest){
				loadXSL('history.xsl');;
				displayXML(originalRequest.responseXML, 'strContent');
				try{
				$('dFrom').value = fromDate;
				$('dTo').value = toDate;
				}catch(ex){}
				}});	
		}
		
		function cmdGetHistoryReport(){	
			new ajax(strPrefix + '/getSenderIdList', {method: 'post',errorText: strConnErr,displayText:'Retrieving SenderId List', onError: $('strError'), postBody: getUP() + '&Verified=true', onComplete: function(originalRequest){
				loadXSL('historyreport.xsl');;
				displayXML(originalRequest.responseXML, 'strContent');
				try{
				$('dFrom').value = fromDate;
				$('dTo').value = toDate;
				}catch(ex){}
				}});	
		}
		
		function getSMSHistoryList(){	
			try {	
				fromDate = $('dFrom').value;
				toDate = $('dTo').value;
			} catch (nd) {
				fromDate = (new Date(new Date().getTime() - 3600*24*3*1000).getMonth()+1) + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getDate() + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getFullYear();
				toDate = (new Date(new Date().getTime() + 3600*24*1000).getMonth()+1) + '/' + new Date(new Date().getTime() + 3600*24*1000).getDate() + '/' + new Date(new Date().getTime() + 3600*24*1000).getFullYear();	
			}
			
			
			if (document.ddForm.strSelect.value == ''){
				alert('Please select a Sender Identifier!');
				return;	
			}
			new ajax(strPrefix + '/getSMSHistoryandSenderIdList', {method: 'post',errorText: strConnErr,displayText:'Retrieving SMS History', onError: $('strError'), postBody: getUP() + '&Sender_Id=' + document.ddForm.strSelect.value + '&Start_Date=' + fromDate + '&End_Date=' + toDate, onComplete: function(originalRequest){
				loadXSL('history.xsl');;
				displayXML(originalRequest.responseXML, 'strContent');
				try{
					$('dFrom').value = fromDate;
					$('dTo').value = toDate;
				}catch(ex){}
				}});
				
		}
		
		function getCredits(){
			new ajax(strPrefix + '/getCredits', {method: 'post',errorText: strConnErr, displayText:'Retrieving Available Credits', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				$('strCredits').innerHTML = originalRequest.responseXML.documentElement.firstChild.nodeValue;
				bCredits = originalRequest.responseXML.documentElement.firstChild.nodeValue;
				}});
		}
		
		function cmdGetGroupMessage(){
			new ajax(strPrefix + '/getGroupListandSenderIdList', {method: 'post',errorText: strConnErr,displayText: 'Retrieving Groups', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('sendgroup.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdGetGroupList(groupId, groupName){
			bGroupId = groupId;
			bGroupName = groupName;
			new ajax(strPrefix + '/getCombinationGroupList', {method: 'post',errorText: strConnErr,displayText:'Retrieving Group List', onError: $('strError'), postBody: getUP() + '&Group_Id=' + groupId, onComplete: function(originalRequest){
				loadXSL('grouplist.xsl');
				displayXML(originalRequest.responseXML, 'strGroupList');
				$('strGroupName').innerHTML = bGroupName;
				}});	 
		}
		
		function cmdDropDownGetNumberGroupContacts(){
			$('strGroupCheckBoxCost').innerHTML = '';
			$('strGroupCheckBoxCost').style.display = '';
			new ajax(strPrefix + '/getNumberContactsInGroup', {method: 'post',errorText: strConnErr,displayText:'Retrieving Contacts in Group', onError: $('strError'), postBody: getUP() + '&Group_Id=' + document.ddForm.strSelect.value, onComplete: function(originalRequest){
				$('strGroupCheckBoxCost').innerHTML = "<table class='fullborder' width='225'><tr><td>There are <b>" + originalRequest.responseXML.documentElement.firstChild.nodeValue + "</b> contacts in this group.</td></tr></table>";
				}});
		}
		
		function cmdCheckBoxGetNumberGroupContacts(){
			$('strGroupCheckBoxCost').innerHTML = '';
			$('strGroupCheckBoxCost').style.display = '';
			var iChecked = '';
			for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
				if (document.getElementsByName('strCheckboxes')[s].checked){
					iChecked = iChecked + document.getElementsByName('strCheckboxes')[s].value + ',';
				}
			}
			if (iChecked == ''){
				alert('No checkboxes selected');
				$('strGroupCheckBoxCost').style.display = 'none';
			}else{
				new ajax(strPrefix + '/getNumberContactsInGroup', {method: 'post',errorText: strConnErr,displayText:'Retrieving Contacts in Group', onError: $('strError'), postBody: getUP() + '&Group_Id=' + iChecked, onComplete: function(originalRequest){
					$('strGroupCheckBoxCost').innerHTML = "<table class='fullborder' width='225'><tr><td>There are <b>" + originalRequest.responseXML.documentElement.firstChild.nodeValue + "</b> contacts in these groups.</td></tr></table>";
					}});
			}
		}
		
		function cmdDeleteGroup(groupName, groupId) {
			new ajax(strPrefix + '/deleteGroup', {method: 'post',errorText: strConnErr,displayText:'Deleting Group', onError: $('strError'), postBody: getUP() + '&Group_Name=' + groupName + '&Group_Identifier=' + groupId, onComplete: function(originalRequest){
				loadXSL('deletegroup.xsl');
				displayXML(originalRequest.responseXML, 'strDeleteResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('Groups')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								setTimeout(function wait(){}, 300);
								cmdGetGroups();
							}
						}
					}
				}
				catch(ex){alert(ex);}
				}});
		}
		
		function cmdAddGroupContact(fromObject) {
		    var output = '';
		    for (var i=0, l=fromObject.options.length;i<l;i++) {
		            output += escape(fromObject.options[i].value) + ',';
		    }
			if (output == ''){
				alert('Group List is empty');
			}else{
					new ajax(strPrefix + '/addGroupContact', {method: 'post',errorText: strConnErr, displayText:'Adding Contact to Group',onError: $('strError'), postBody: getUP() + '&Group_Id=' + bGroupId + '&Contact_Mobile_Number=' + output, onComplete: function(originalRequest){
					var success, failed, statuscode, strResult;
					try{
						var x = originalRequest.responseXML.documentElement.getElementsByTagName('GroupContact')[0].childNodes;
						for (var i=0; i<x.length;i++){
							if (x[i].tagName == 'Add_Success')
								success = x[i].firstChild.nodeValue;
							else if (x[i].tagName == 'Add_Failed')
								failed = x[i].firstChild.nodeValue;
							else if (x[i].tagName == 'Status_Code')
								statuscode = x[i].firstChild.nodeValue;  							
						}
					}catch(ex){alert(ex);}
					if (statuscode == '0'){
						strResult = success + " added successfully. " + failed + " failed to add.";
					}else{
						strResult = "Error occured.";
					}
					$('strGroupContactResult').innerHTML = strResult;
					}});
			}    
		}
		
		function cmdCheckBoxGroupValidNumber(){
			$('strGroupCheckBoxCost').style.display = 'none';
			var iChecked = '';
			for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
				if (document.getElementsByName('strCheckboxes')[s].checked){
					iChecked = iChecked + document.getElementsByName('strCheckboxes')[s].value + ',';
				}
			}
			new ajax(strPrefix + '/getGroupNetworkInformation', {method: 'post',errorText: strConnErr,displayText:'Retrieving Group Network Information', onError: $('strError'), postBody: getUP() + '&Group_Id=' + iChecked, onComplete: function(originalRequest){
				$('strGroupCheckBoxCost').style.display = '';
				loadXSL('cost.xsl');
				displayXML(originalRequest.responseXML, 'strGroupCheckBoxCost');}});	
		}
		
		function cmdSelectCheckBoxAll(){
			for (i=0; i<document.getElementsByName('strCheckboxes').length; i++){
				document.getElementsByName('strCheckboxes')[i].checked = true;		
			}
		}
		
		function cmdUnSelectCheckBoxAll(){
			for (i=0; i<document.getElementsByName('strCheckboxes').length; i++){
				document.getElementsByName('strCheckboxes')[i].checked = false;	
			}
		} 
		
		function clearMessage(){
			$('strMsg').value = '';
			$('charsLeft').value = '160';
			$('btnSend').disabled = false;
			$('strResult').style.color = '#336699';
			$('strResult').style.visibility = 'hidden';
			originalText = '';
		}
		
		function displayAmount(){
			$('price').value = (document.InvoiceForm.strBundle.value * iPrice);
			var wd="w";
			var tempnum=$('price').value;
			for (i=0;i<tempnum.length;i++){
				if (tempnum.charAt(i)=="."){
					wd="d";
					break;
				}
			}
			if (wd=="w")
				$('price').value=tempnum+".00";
			else{
				if (tempnum.charAt(tempnum.length-2)=="."){
					$('price').value=tempnum+"0";
				}
				else{
					tempnum=Math.round(tempnum*100)/100;
					$('price').value=tempnum;
				}
			}
		}
		
		function sendQuickMessage() {
			if ($('strMsg').value == ''){
				alert('Message box cannot be empty!');
				return;
			}
			if (document.ddIdenForm.strSelectIdentifier.value == ''){
				alert('Please select a Sender Identifier!');
				return;	
			}
			
			strMessage = new String($('strMsg').value);
			strMessage = encodeWebMessage(strMessage);
						
			$('btnSend').disabled = true;
			$('strResult').style.visibility = 'visible';
			$('strResult').innerHTML = '<br/>Sending message to: ' + $('To_Mobile_Number').value + '<br/>';
			
			if ($('To_Mobile_Number').value == ''){
				alert('To Mobile cannot be empty!');
				$('btnSend').disabled = false;
				return;
			}else{
				new ajax(strPrefix + '/singlesms', {method: 'post',errorText: strConnErr,displayText:'Sending Quick SMS Message', onError: $('strError'), postBody: getUP()+ '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + $('To_Mobile_Number').value + '&Message=' + strMessage, onComplete: function(originalRequest){
				loadXSL('sendsms.xsl');
				displayXML(originalRequest.responseXML, 'strResult');
				
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('SendSMS')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								getCredits();
							}
						}
					}
				}catch(ex){alert(ex);}
				}});
			$('btnSend').disabled = false;
			}
		}
		
		function sendMessage() {
			if ($('strMsg').value == ''){
				alert('Message box cannot be empty!');
				return;
			}
			if (document.ddIdenForm.strSelectIdentifier.value == ''){
				alert('Please select a Sender Identifier!');
				return;
			}
			
			var url = strPrefix + '/singlesms';
			var strTo = '';
			var strBody = '';
			strMessage = new String($('strMsg').value);
			strMessage = encodeWebMessage(strMessage);
			$('btnSend').disabled = true;
			if ($('method1').checked){
				strTo = document.ddForm.strSelect.value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Message=' + strMessage;
			}else if ($('method3').checked){
				strTo = $('To_Mobile_Number').value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Message=' + strMessage;
			}else if ($('method2').checked){
				for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
					if (document.getElementsByName('strCheckboxes')[s].checked) 
						strTo = strTo + ',' + document.getElementsByName('strCheckboxes')[s].value;
				}
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strTo = strTo.substring(1, strTo.length);
				url = strPrefix + '/multiplesms';
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Numbers=' + strTo + '&Message=' + strMessage;
			}
			$('strResult').style.visibility = 'visible';
			$('strResult').innerHTML = '<br/>Sending message to: ' + strTo + '<br/>';
			if (strTo == ''){
				alert('To Mobile cannot be empty!');
				$('btnSend').disabled = false;
				return;
			}else{
				new ajax(url, {method: 'post',errorText: strConnErr,displayText:'Sending SMS Message', onError: $('strError'), postBody: strBody, onComplete: function(originalRequest){
				if ($('method2').checked){
					loadXSL('sendsmsmulti.xsl');
				}else{
					loadXSL('sendsms.xsl');
				}
				displayXML(originalRequest.responseXML, 'strResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('SendSMS')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								getCredits();
							}
						}
					}
				}catch(ex){alert(ex);}
				}});
			}
			$('btnSend').disabled = false;
		}
		
		function sendScheduledMessage() {
			if ($('strMsg').value == ''){
				alert('Message box cannot be empty!');
				return;
			}
			if (document.ddIdenForm.strSelectIdentifier.value == ''){
				alert('Please select a Sender Identifier!');
				return;
			}
			
			var url = strPrefix + '/singlescheduledsms';
			var strTo = '';
			var strBody = '';
			strMessage = new String($('strMsg').value);
			strMessage = encodeWebMessage(strMessage);
			strDate = $('dScheduled').value;
			var word = strDate.split("/");
			var strDateTime = word[2] + '-' + word[0] + '-' + word[1] + 'T' + document.ddScheduleForm.thSchedule.value + document.ddScheduleForm.tmSchedule.value;
			strDateTime = encodeWebMessage(strDateTime);
			$('btnSend').disabled = true;
			if ($('method1').checked){
				strTo = document.ddForm.strSelect.value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Message=' + strMessage + '&Scheduled_DateTime=' + strDateTime;
			}else if ($('method3').checked){
				strTo = $('To_Mobile_Number').value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Message=' + strMessage + '&Scheduled_DateTime=' + strDateTime;
			}else if ($('method2').checked){
				for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
					if (document.getElementsByName('strCheckboxes')[s].checked) 
						strTo = strTo + ',' + document.getElementsByName('strCheckboxes')[s].value;
				}
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strTo = strTo.substring(1, strTo.length);
				url = strPrefix + '/multiplescheduledsms';
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Numbers=' + strTo + '&Message=' + strMessage + '&Scheduled_DateTime=' + strDateTime;
			}
			$('strResult').style.visibility = 'visible';
			$('strResult').innerHTML = '<br/>Sending Scheduled message to: ' + strTo + '<br/>';
			if (strTo == ''){
				alert('To Mobile cannot be empty!');
				$('btnSend').disabled = false;
				return;
			}else{
				new ajax(url, {method: 'post',errorText: strConnErr,displayText:'Sending Scheduled SMS Message', onError: $('strError'), postBody: strBody, onComplete: function(originalRequest){
				if ($('method2').checked){
					loadXSL('sendscheduledsmsmulti.xsl');
				}else{
					loadXSL('sendscheduledsms.xsl');
				}
				displayXML(originalRequest.responseXML, 'strResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('SendSMS')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								getCredits();
							}
						}
					}
				}catch(ex){alert(ex);}
				}});
			}
			$('btnSend').disabled = false;
		}
		
		function sendWAPMessage() {
			if ($('strTitle').value == ''){
				alert('Title cannot be empty!');
				return;
			}
			if ($('strUrl').value == ''){
				alert('URL cannot be empty!');
				return;
			}
			if (document.ddIdenForm.strSelectIdentifier.value == ''){
				alert('Please select a Sender Identifier!');
				return;
			}
            //if ($('strUrl').value.substring(3,0).toLowerCase() != "www"){
			//	alert('URL must start with www');
			//	return;
			//}

			var url = strPrefix + '/singleWAPPush';
			var strTo = '';
			var strBody = '';
			
			$('btnSend').disabled = true;
			if ($('method1').checked){
				strTo = document.ddForm.strSelect.value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Title=' + $('strTitle').value + '&URL=' + $('strUrl').value;
			}else if ($('method3').checked){
				strTo = $('To_Mobile_Number').value;
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Number=' + strTo + '&Title=' + $('strTitle').value + '&URL=' + $('strUrl').value;
			}else if ($('method2').checked){
				for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
					if (document.getElementsByName('strCheckboxes')[s].checked) 
						strTo = strTo + ',' + document.getElementsByName('strCheckboxes')[s].value;
				}
				if (strTo.length == 0){
					alert('Please select a Recipient!');
					return;
				}
				strTo = strTo.substring(1, strTo.length);
				url = strPrefix + '/multipleWAPPush';
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&To_Numbers=' + strTo + '&Title=' + $('strTitle').value + '&URL=' + $('strUrl').value;
			}
			
			$('strResult').style.visibility = 'visible';
			$('strResult').innerHTML = '<br/>Sending message to: ' + strTo + '<br/>';
			
			if (strTo == ''){
				alert('To Mobile cannot be empty!');
				$('btnSend').disabled = false;
				return;
			}else{
				new ajax(url, {method: 'post',errorText: strConnErr,displayText:'Sending SMS Message', onError: $('strError'), postBody: strBody, onComplete: function(originalRequest){
				if ($('method2').checked){
					loadXSL('sendsmsmulti.xsl');
				}else{
					loadXSL('sendsms.xsl');
				}
				displayXML(originalRequest.responseXML, 'strResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('SendSMS')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								getCredits();
							}
						}
					}
				}catch(ex){alert(ex);}
				}});
			}
			$('btnSend').disabled = false;
		}
		
		
		function sendGroupMessage() {
			if ($('strMsg').value == ''){
				alert('Message box cannot be empty!');
				return;
			}
			if (document.ddIdenForm.strSelectIdentifier.value == ''){
				alert('Please select a Sender Identifier!');
				return;
			}
			
			var url = strPrefix + '/singlegroupsms';
			var strTo = '';
			var strBody = '';
			
			strMessage = new String($('strMsg').value);
			strMessage = encodeWebMessage(strMessage);
			
			$('btnSend').disabled = true;
			if ($('method1').checked){
				strTo = document.ddForm.strSelect.value;
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&Group_Id=' + strTo + '&Message=' + strMessage;
			}else if ($('method2').checked){
				for (s = 0; s < document.getElementsByName('strCheckboxes').length; s++) {
					if (document.getElementsByName('strCheckboxes')[s].checked) 
						strTo = strTo + ',' + document.getElementsByName('strCheckboxes')[s].value;
				}
				strTo = strTo.substring(1, strTo.length);
				url = strPrefix + '/multiplegroupsms';
				strBody = getUP() + '&Sender_Id=' + document.ddIdenForm.strSelectIdentifier.value + '&Group_Id=' + strTo + '&Message=' + strMessage;
			}
			$('strResult').style.visibility = 'visible';
			$('strResult').innerHTML = '<br/>Sending group message<br/>Please be patient this may take a while!<br/>';
			
			new ajax(url, {method: 'post',errorText: strConnErr,displayText:'Sending Group SMS Message', onError: $('strError'), postBody: strBody, onComplete: function(originalRequest){
				//if ($('method2').checked){
					loadXSL('sendsmsmulti.xsl');
				//}else{
				//	loadXSL('sendsms.xsl');
				//}
				displayXML(originalRequest.responseXML, 'strResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('SendSMS')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								getCredits();
							}
						}
					}
				}catch(ex){alert(ex);}
				}});	
				$('btnSend').disabled = false;			
		}
		
		function cmdGetPayments() {
			cmdLoad('payments');
			new ajax(strPrefix + '/getUserBankDepositPayments', {method: 'post',errorText: strConnErr,displayText:'Retrieving Payments', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('bankpayments.xsl');
				displayXML(originalRequest.responseXML, 'strBankPayments');
				}});	
		}
		
		function cmdGenerateInvoice(){
			new ajax(strPrefix + '/addInvoice', {method: 'post',errorText: strConnErr, displayText:'Generating Invoice', onError: $('strError'), postBody: getUP() + '&Company_Name=' + $('companyname').value + '&Company_Contact_Person=' + $('companycontactperson').value + '&Email=' + $('emailaddress').value + '&Credits=' + document.InvoiceForm.strBundle.value, onComplete: function(originalRequest){
				loadXSL('addinvoice.xsl');
				displayXML(originalRequest.responseXML, 'strBankResult');}});
		}
		
		function cmdGetInvoices(){
				new ajax(strPrefix + '/getInvoiceList', {method: 'post',errorText: strConnErr, displayText:'Retrieving Invoices', onError: $('strError'), postBody: getUP(), onComplete: function(originalRequest){
				loadXSL('invoices.xsl');
				displayXML(originalRequest.responseXML, 'strContent');}});
		}
		
		function cmdDeleteInvoice(invoiceId) {
			new ajax(strPrefix + '/deleteInvoice', {method: 'post',errorText: strConnErr,displayText: 'Deleting Invoice', onError: $('strError'), postBody: getUP() + '&InvoiceId=' + invoiceId, onComplete: function(originalRequest){
				loadXSL('deleteinvoice.xsl');
				displayXML(originalRequest.responseXML, 'strDeleteResult');
				try{
					var x = originalRequest.responseXML.documentElement.getElementsByTagName('Invoices')[0].childNodes;
					for (var i=0; i<x.length;i++){
						if (x[i].tagName == 'Status_Code'){
							if (x[i].firstChild.nodeValue == '0'){
								setTimeout(function wait(){}, 300);
								cmdGetInvoices();
							}
						}
					}
				}
				catch(ex){alert(ex);}
				}});
		}
				
		function showContacts(selection) {
			$('strResult').style.color = '#336699';
			$('strResult').style.visibility = 'hidden';
			$('sendinput').style.display = 'none';
			$('senddropdown').style.display = 'none';
			$('multiple').style.display = 'none';
			$(selection).style.display = '';
			$('strValidNetwork').style.display = 'none';
			$('strDropDownValidNumber').style.display = 'none';
			$('strCheckBoxValidNumber').style.display = 'none';
		}
		
		function showGroups(selection){
			$('strGroupCheckBoxCost').style.display = 'none';
			$('strResult').style.color = '#336699';
			$('strResult').style.visibility = 'hidden';
			$('senddropdown').style.display = 'none';
			$('multiple').style.display = 'none';
			$(selection).style.display = '';
		}
		
		function showBundle(selection){
			$('strbundle').style.display = 'none';
			$('strfreeform').style.display = 'none';
			$(selection).style.display = '';
		}
		
		function checkLen(Target, Source) {
			if (Source == null)
				originalText = $('strMsg').value;
			var StrLen = Target.value.length;
			var charsLeft;
			if (StrLen > 160 ) {
				Target.value = Target.value.substring(0,160);
				charsLeft = 0;
			}
			else 
				charsLeft = 160 - StrLen;
			$('charsLeft').value = charsLeft;
		}
		
		function isNumeric(str){
			if (str.length < 1) {
				return false;
			}
			for (var i=0; i < str.length; i++){
				var ch = str.substring(i, i+1);
				if(ch != "." && ch < "0" || ch > "9"){
					return false;
				}
			}
			return true;
		}
		
		function loadXSL(stylesheet) {
				try{
				if (window.XMLHttpRequest && document.implementation.createDocument) {
					try{
						xsldoc = document.implementation.createDocument("", "", null);
						var serializer = new XMLSerializer();
						xsldoc.async = false;
						xsldoc.load('stylesheets/' + stylesheet);
						var parser = new DOMParser();
						var dom = parser.parseFromString(serializer.serializeToString(xsldoc), "text/xml");
						xsltProcessor = new XSLTProcessor();
						xsltProcessor.importStylesheet(dom);
					}catch(e){
						xsldoc = document.implementation.createDocument("", "", null);
						xsldoc.async = false;
						xsldoc.load('stylesheets/' + stylesheet);
						xsltProcessor = new XSLTProcessor();
						xsltProcessor.importStylesheet(xsldoc);
					}
				}
				else if (window.ActiveXObject) {
					try{
						xsldoc = new ActiveXObject("Msxml2.XMLDOM");
						xsldoc.async = false;
						xsldoc.load('stylesheets/' + stylesheet);
						xsldoc.loadXML(xsldoc.xml);
					}catch(e){
						try{
						xsldoc = new ActiveXObject("Microsoft.XMLDOM");
						xsldoc.async = false;
						xsldoc.load('stylesheets/' + stylesheet);
						xsldoc.loadXML(xsldoc.xml);
						}catch(e){alert('Failed to load stylesheet (' + stylesheet + '): ' + e);}
					}
				}
				}catch(ex){alert('Failed to load stylesheet (' + stylesheet + '): ' + ex);}

		}
		
		function displayXML(xml,inlineHTML) {
			if (window.XSLTProcessor){
				try {
					$(inlineHTML).innerHTML = '';
					$(inlineHTML).appendChild(xsltProcessor.transformToFragment(xml, document));
				}catch(e){alert('An unexpected error has occurred with the XSLTProcessor. Pls contact support@chillnet.co.za!'); }
			}
			else if (window.ActiveXObject){
				try {
					xmlObject = new ActiveXObject("Msxml2.XMLDOM");
					xmlObject.load(xml);
					$(inlineHTML).innerHTML = xmlObject.transformNode(xsldoc);
				}catch(e){
						try{
							xmlObject = new ActiveXObject("Microsoft.XMLDOM");
							xmlObject.load(xml);
							$(inlineHTML).innerHTML = xmlObject.transformNode(xsldoc);
						
						} catch (f) { alert('An unexpected error has occurred. Pls contact support@chillnet.co.za!'); }
				}
			}
		}
		
		//for group contacts
		function deleteOption(object,index) {
		    object.options[index] = null;
		}
		
		function addOption(object,text,value) {
		    var defaultSelected = true;
		    var selected = true;
		    var optionName = new Option(text, value, defaultSelected, selected);
		    object.options[object.length] = optionName;
		}
		
		function copySelected(fromObject,toObject, direction) {
		    for (var i=0, l=fromObject.options.length;i<l;i++) {
		        if (fromObject.options[i].selected)
		            addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
		    }
		    for (var i=fromObject.options.length-1;i>-1;i--) {
		        if (fromObject.options[i].selected)
		            deleteOption(fromObject,i);
		    }
			if (direction){
				$('strCombinationGroupList').innerHTML = escape(toObject.options.length);
				$('strExclusionGroupList').innerHTML = escape(fromObject.options.length);
			}else{
				$('strCombinationGroupList').innerHTML = escape(fromObject.options.length);
				$('strExclusionGroupList').innerHTML = escape(toObject.options.length);
			}
		}
		
		function copyAll(fromObject,toObject,direction) {
		    for (var i=0, l=fromObject.options.length;i<l;i++) {
		        addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
		    }
		    for (var i=fromObject.options.length-1;i>-1;i--) {
		        deleteOption(fromObject,i);
		    }
			if (direction){
				$('strCombinationGroupList').innerHTML = escape(toObject.options.length);
				$('strExclusionGroupList').innerHTML = '0';
			}else{
				$('strCombinationGroupList').innerHTML = '0'; 
				$('strExclusionGroupList').innerHTML = escape(toObject.options.length);
			}
				
		}
		
		function refreshImage(){
			var url = "http://sms.chillnet.co.za/api/image.aspx?p=" + Math.random();
			$('verImage').setAttribute('src', url);
		}
		
		function encodeWebMessage(strMessage){
			strMessage = strMessage.toString().replace(/\%/g, '%25');
			strMessage = strMessage.toString().replace(/\+/g, '%2B');
			strMessage = strMessage.toString().replace(/\&/g, '%26');
			strMessage = strMessage.toString().replace(/\?/g, '%3F');
			strMessage = strMessage.toString().replace(/\;/g, '%3B');
			strMessage = strMessage.toString().replace(/\:/g, '%3A');
			strMessage = strMessage.toString().replace(/\}/g, '%7D');
			strMessage = strMessage.toString().replace(/\{/g, '%7B');
			strMessage = strMessage.toString().replace(/\"/g, '%22');
			strMessage = strMessage.toString().replace(/\~/g, '%7E');
			strMessage = strMessage.toString().replace(/\`/g, '%60');
			strMessage = strMessage.toString().replace(/\!/g, '%21');
			strMessage = strMessage.toString().replace(/\#/g, '%23');
			strMessage = strMessage.toString().replace(/\$/g, '%24');
			strMessage = strMessage.toString().replace(/\^/g, '%5E');
			return strMessage;
		}
		
		function InsertCharts()
		{
			
			if (document.ddForm.strSelect.value == ''){
				alert('Please select a Sender Identifier!');
				return;	
			}else{
				var senderId = document.ddForm.strSelect.value;
			}
			
			try {	
					fromDate = $('dFrom').value;
					toDate = $('dTo').value;
				} catch (nd) {
					fromDate = (new Date(new Date().getTime() - 3600*24*3*1000).getMonth()+1) + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getDate() + '/' + new Date(new Date().getTime() - 3600*24*3*1000).getFullYear();
					toDate = (new Date(new Date().getTime() + 3600*24*1000).getMonth()+1) + '/' + new Date(new Date().getTime() + 3600*24*1000).getDate() + '/' + new Date(new Date().getTime() + 3600*24*1000).getFullYear();	
				}
				
      	      var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="200px" id="ie_chart" align="middle">\n';
			  str = str + '<param name="allowScriptAccess" value="sameDomain" />\n';
			  str = str + '<param name="movie" value="charts/open-flash-chart.swf?data=http://sms.chillnet.co.za/api/graphData.aspx?' + getUPEncoded() + '%26Sender_Id=' + senderId + '%26Start_Date=';
			  str = str + fromDate + '%26End_Date=';
			  str = str + toDate + '" />\n';
			  str = str + '<param name="quality" value="high" />\n';
			  str = str + '<param name="bgcolor" value="#FFFFFF" />\n';
			  str = str + '<embed width="100%" height="200px" src="charts/open-flash-chart.swf?data=http://sms.chillnet.co.za/api/graphData.aspx?' + getUPEncoded() + '%26Sender_Id=' + senderId + '%26Start_Date=';
			  str = str + fromDate + '%26End_Date=';
			  str = str + toDate + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart"/>\n';
			  str = str + '</object><br/><br/>\n';
			  
			  str = str + '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="200px" id="ie_chart" align="middle">\n';
			  str = str + '<param name="allowScriptAccess" value="sameDomain" />\n';
			  str = str + '<param name="movie" value="charts/open-flash-chart.swf?data=http://sms.chillnet.co.za/api/pieData.aspx?' + getUPEncoded() + '%26Sender_Id=' + senderId + '%26Start_Date=';
			  str = str + fromDate + '%26End_Date=';
			  str = str + toDate + '" />\n';
			  str = str + '<param name="quality" value="high" />\n';
			  str = str + '<param name="bgcolor" value="#FFFFFF" />\n';
			  str = str + '<embed width="100%" height="200px" src="charts/open-flash-chart.swf?data=http://sms.chillnet.co.za/api/pieData.aspx?' + getUPEncoded() + '%26Sender_Id=' + senderId + '%26Start_Date=';
			  str = str + fromDate + '%26End_Date=';
			  str = str + toDate + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart"/>\n';
			  str = str + '</object>\n';
			  $('strGraph').innerHTML = str;
		}
		
		
		 



		
		
		
		