function submitbpl(questionNumber){

       $('submit'+questionNumber).disbled = true;
       $('cancel'+questionNumber).disbled = true;
       
       if($('messageQuestion'+questionNumber).value == ''){
                                                                                                                
              alert('Your Question is empty!');
              $('submit'+questionNumber).disbled = false;
              $('cancel'+questionNumber).disbled = false;
              new Effect.Highlight('messageQuestion'+questionNumber);              
                                                                                                                       
       }
       else if(questionNumber == 1 && $('messageAnswer'+questionNumber).value == ''){
                                                                                                                
              alert('Your Answer is empty!');
              $('submit'+questionNumber).disbled = false;
              $('cancel'+questionNumber).disbled = false; 
              new Effect.Highlight('messageAnswer'+questionNumber);             
                                                                                                                       
       }
       else {
       
              updater('status','../bpl/edit_bpl_processor.php?qn='+questionNumber,'form'+questionNumber);
       
       }       

}

function submitAddUnsubContact(){

       $("NextStep").disabled = true;
       $("indicator").style.visibility = "visible";
              
       if($("unsubType").value == "SMS"){
                                                                                                  
              if($("mobile_country_code").value == ""){
                                                                                                  
                     $("add_unsub_status").innerHTML = "<span class='body_box_alert'>Please input mobile country code!</span>";
                     $("NextStep").disabled = false;
                     $("indicator").style.visibility = "hidden";                     
                                                                                                  
              }
              else if($("mobile_number").value == ""){
                                                                                                  
                     $("add_unsub_status").innerHTML = "<span class='body_box_alert'>Please input mobile number!</span>";
                     $("NextStep").disabled = false;
                     $("indicator").style.visibility = "hidden";                     
                                                                                                  
              }
              else if($("mobile_number").value.length < 8){
                                                                                                  
                     $("add_unsub_status").innerHTML = "<span class='body_box_alert'>Your Mobile Number is too short, please try again!</span>";
                     $("NextStep").disabled = false;
                     $("indicator").style.visibility = "hidden";                     
                                                                                                  
              }
              else if(isNaN($("mobile_country_code").value) || isNaN($("mobile_number").value)){
                                                                                                  
                     $("add_unsub_status").innerHTML = "<span class='body_box_alert'>Only digits are allowed for the Mobile Number field, please try again!</span>";
                     $("NextStep").disabled = false;
                     $("indicator").style.visibility = "hidden";                     
                                                                                                  
              }
              else {
              
                     updater('add_unsub_status','../processors/add_unsub_processors.php','add_unsub_form');
              
              }                                             
              
       }
       else if($("unsubType").value == "Email"){
       
              if($("mobile_country_code").value == ""){
                                                                                                  
                     $("add_unsub_status").innerHTML = "<span class='body_box_alert'>Please input email addresss!</span>";
                     $("NextStep").disabled = false;
                     $("indicator").style.visibility = "hidden";                     
                                                                                                  
              }
              else{   
                  
                     updater('add_unsub_status','../processors/add_unsub_processors.php','add_unsub_form');
              
              }
       
       }

}

function updateDefaultReplyUrl(){

       $('update').disabled=true;
       $('cancel').disabled=true;
       
       var pattern = /^http:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_%&\?\/.=:]+$/;//url validation pattern
       
       if ($('defaultReplyUrl').value == ''){
       
              $('editDefaultReplyUrlStatus').innerHTML = '<span class="body_box_alert">You default reply URL is empty!</span>';
              $('update').disabled=false;
              $('cancel').disabled=false;
                            
       }
       else if (pattern.test($('defaultReplyUrl').value) == false){
       
              $('editDefaultReplyUrlStatus').innerHTML = '<span class="body_box_alert">You default reply URL is invalid!</span>';
              $('update').disabled=false;
              $('cancel').disabled=false;
                            
       }
       else updater('editDefaultReplyUrlStatus','../processors/edit_api_config_processor.php?action=updateDefaultReplyUrl','defaultReplyUrlForm');
              
}

function checkKeywordValidity(keywordCounter,formCounter){

       var myRegxp = /^([a-zA-Z0-9]+)$/;//only alphanumeric can become keyword
       
       var keyword = $('keyword'+keywordCounter+'Form'+formCounter).value;
       
       if($('dedicatedShortcode').value == '73333' && keyword.toUpperCase() == 'NO'){
       
              alert("NO is a system-reserved keyword used for unsubscribes and is not available, do choose something else!");
              $('update'+formCounter).disabled = true;
              $('cancel'+formCounter).disabled = true;
                                   
              if($('addKeywordLink'+keywordCounter+'Form'+formCounter)){
                     
                     $('addKeywordLink'+keywordCounter+'Form'+formCounter).style.display = "none";
                     
              }       
       
       }
       else if($('dedicatedShortcode').value == '73333' && keyword == '1' || $('dedicatedShortcode').value == '73333' && keyword == '2' || $('dedicatedShortcode').value == '73333' && keyword == '3' || $('dedicatedShortcode').value == '73333' && keyword == '4'){
       
              alert("The keyword "+keyword+" is not available, do choose something else!");
              $('update'+formCounter).disabled = true;
              $('cancel'+formCounter).disabled = true;
                                   
              if($('addKeywordLink'+keywordCounter+'Form'+formCounter)){
                     
                     $('addKeywordLink'+keywordCounter+'Form'+formCounter).style.display = "none";
                     
              }        
       
       }
       else if(keyword != ''){

              if(myRegxp.test(keyword) == false){
       
                     alert("This keyword "+keyword+" is invalid, please try another keyword, no space or punctuation allowed!");
                     $('update'+formCounter).disabled = true;
                     $('cancel'+formCounter).disabled = true;
                     
                     if($('addKeywordLink'+keywordCounter+'Form'+formCounter)){
                     
                            $('addKeywordLink'+keywordCounter+'Form'+formCounter).style.display = "none";
                     
                     }

              }
              else{
              
                     $('update'+formCounter).disabled = false;
                     $('cancel'+formCounter).disabled = false;
                     
                     if($('addKeywordLink'+keywordCounter+'Form'+formCounter)){
                     
                            $('addKeywordLink'+keywordCounter+'Form'+formCounter).style.display = "";
                     
                     }                     
              
              }
       
       }
       else if(keyword == ''){
       
              $('update'+formCounter).disabled = false;
              $('cancel'+formCounter).disabled = false;
              
              if($('addKeywordLink'+keywordCounter+'Form'+formCounter)){
                     
                     $('addKeywordLink'+keywordCounter+'Form'+formCounter).style.display = "none";
                     
              }                     
       
       }
        
}

function createNewApiConfigForm(formCounter){

       if($('dedicatedShortcode').value == '73333' && $('currentKeywordCount').value == $('maxKeywordAllowed').value ){
       
              alert('You have reached the maximum no. of keywords allowed, please contact Support if you wish to add more.');
       
       }
       else if($('dedicatedShortcode').value != '73333' || $('dedicatedShortcode').value == '73333' && $('currentKeywordCount').value < $('maxKeywordAllowed').value ){

              var formCounter = $('formCounter').value;
              
              var newForm = '<br />'+
                     '<div id="editApiConfigStatus'+formCounter+'"></div>'+
                     '<br />'+			
                     '<div name="apiConfig'+formCounter+'" id="apiConfig'+formCounter+'" class="input_form" method="post">'+
                            '<span class="subtitle2">API Config Set '+formCounter+'</span>'+
                            '<br /><br />'+ 	
                            '<img src="../images/icons/sms_campaign.png" width="16" height="16" />'+
                            '<br /><br /><input type="hidden" name="apiConfigForm'+formCounter+'Content" id="apiConfigForm'+formCounter+'Content" />'+
                            '<div name="apiConfigDisplay'+formCounter+'" id="apiConfigDisplay'+formCounter+'">'+
                                   'Your Current Assigned Keyword 1 : <span class="subtitle2"> NONE </span>'+
                                   '<br /><br />'+
                                   'Reply URL:'+ 
                                   '<br />'+ 
                                   '<textarea disabled="disabled" rows="3" cols="48"></textarea>'+
                                   '<br /><br />'+
                                   '<span id="editLink'+formCounter+'" style="padding-right:20px;">'+
                                          '<a href="#" onClick="$(\'apiConfigForm'+formCounter+'Content\').value = $(\'apiConfigForm'+formCounter+'\').innerHTML;new Effect.SlideUp(\'apiConfigDisplay'+formCounter+'\');new Effect.Appear(\'apiConfigForm'+formCounter+'\');return false;">Edit</a>'+
                                   '</span>'+
                            '</div>'+
                            '<div id="apiConfigForm'+formCounter+'" style="display:none">'+
                                   '<input type="hidden" name="dedicatedShortcode" id="dedicatedShortcode" value="'+$('dedicatedShortcode').value+'" />'+
                                   '<input type="hidden" name="keywordCounterForm'+formCounter+'" id="keywordCounterForm'+formCounter+'" value="0" />'+
                                   '<span id="keywordTab1Form'+formCounter+'"><br /><br />'+
                                          'Keyword 1: '+
                                          '<input name="keyword1Form'+formCounter+'" type="text" size="15" maxlength="50" id="keyword1Form'+formCounter+'" onKeyUp="checkKeywordValidity(\'1\',\''+formCounter+'\');return false;" />'+
                                   '</span>'+ 
                                          '   <span id="addKeywordLink1Form'+formCounter+'" style="display:none;">'+
                                                 '<a href="#" onclick="createKeywordInputTab(1,'+formCounter+');return false;">&raquo;Add another keyword</a>'+
                                          '</span>'+
                                   '<input type="hidden" name="totalKeywordCounter'+formCounter+'" id="totalKeywordCounter'+formCounter+'" value="1" />'+
                                   '<input type="hidden" name="origReplyUrlForm'+formCounter+'" id="origReplyUrlForm'+formCounter+'" />'+
                                   '<br /><br />'+
                                   'Reply URL: <br />'+
                                   '<textarea id="replyUrlForm'+formCounter+'" name="replyUrlForm'+formCounter+'" cols="48" rows="3" class="text_field_app"></textarea>'+
                                   '<br />'+
                                   '<span class="footerstyle">'+
                                          'This is the URL where your application will receive incoming SMS that we forward to you in HTTP format. Keywords must appear at the front of the message that mobile users send in.'+
                                   '</span>'+
                                   '<br />'+
                                   '<br />'+
                                   '<input id="update'+formCounter+'" name="update'+formCounter+'" type="button" value="Update" onClick="updateApiConfig('+formCounter+');return false;"/>'+
                                   '<input id="cancel'+formCounter+'" name="cancel'+formCounter+'" type="button" value="Cancel" onClick="$(\'currentKeywordCount\').value -= $(\'keywordCounterForm'+formCounter+'\').value;$(\'keywordCounterForm'+formCounter+'\').value = 0;new Effect.SlideDown(\'apiConfigDisplay'+formCounter+'\');$(\'apiConfigForm'+formCounter+'\').style.display=\'NONE\';$(\'apiConfigForm'+formCounter+'\').innerHTML = $(\'apiConfigForm'+formCounter+'Content\').value;return false;"/>'+   				                     
                            '</div>'+
                     '</div>'+
                     '<br />'+
                     '<span id="addNewFormLink" style="display:none;">'+
                            '<a href="#" onclick="createNewApiConfigForm();return false;">Add another API config set</a>'+
                     '</span>';
                     
              $('addNewFormLink').remove();              
              $('event_4').insert({bottom:newForm});
              $('formCounter').value++;
              $('currentKeywordCount').value++;
       
       }
       
}

function createKeywordInputTab(keywordCounter,formCounter){

       if($('dedicatedShortcode').value == '73333' && $('currentKeywordCount').value == $('maxKeywordAllowed').value ){
       
              alert('You have reached the maximum no. of keywords allowed, please contact Support if you wish to add more.');
       
       }
       else if($('dedicatedShortcode').value != '73333' || $('dedicatedShortcode').value == '73333' && $('currentKeywordCount').value < $('maxKeywordAllowed').value ){ 

              $('addKeywordLink'+keywordCounter+'Form'+formCounter).innerHTML="";
              $('totalKeywordCounter'+formCounter).value++;
       
              var nextKeywordCounter = keywordCounter+1;
       
              var newKeywordInputTab = '<span id="keywordTab'+nextKeywordCounter+'Form'+formCounter+'"><br /><br />'+
                                       '         Keyword '+nextKeywordCounter+':'+
                                       '         <input name="keyword'+nextKeywordCounter+'Form'+formCounter+'" type="text" size="15" maxlength="50" id="keyword'+nextKeywordCounter+'Form'+formCounter+'" onKeyUp="checkKeywordValidity(\''+nextKeywordCounter+'\',\''+formCounter+'\');return false;" />'+
                                       '</span>'+
                                       '<span id="addKeywordLink'+nextKeywordCounter+'Form'+formCounter+'" style="display:none;">'+
                                       '         <a href="#" onclick="createKeywordInputTab('+nextKeywordCounter+','+formCounter+');return false;">&raquo;Add another keyword</a>'+
                                       '</span>';
                                       
                                
              //$('keywordTab'+keywordCounter+'Form'+formCounter).insert({after:newKeywordInputTab});
              $('totalKeywordCounter'+formCounter).insert({before:newKeywordInputTab});
              if($('dedicatedShortcode').value == '73333'){
              
                     $('currentKeywordCount').value++;
                     $('keywordCounterForm'+formCounter).value++;
              
              }
              
       }
}

function updateApiConfig(formCounter){

       $('update'+formCounter).disabled=true;
       $('cancel'+formCounter).disabled=true;
       
       var maxKeywordCounter = $('totalKeywordCounter'+formCounter).value;
       var duplicate = false;
       var empty = true;
       var pattern = /^http:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_%&\?\/.=:]+$/;
       var replyUrl = $('replyUrlForm'+formCounter).value;
       
       for (var keywordCounter = 1; keywordCounter <= maxKeywordCounter; keywordCounter++){
       
              if($('keyword'+keywordCounter+'Form'+formCounter).value != '') empty = false;             
              
       }
       
       if(empty == false){
       
              for (var keywordCounter = 1; keywordCounter <= maxKeywordCounter; keywordCounter++){//check for duplicate keyword input
       
                     if(keywordCounter != maxKeywordCounter){
              
                            for(var i = keywordCounter+1 ;  i <= maxKeywordCounter ; i++){
                     
                                   if($('keyword'+keywordCounter+'Form'+formCounter).value == $('keyword'+i+'Form'+formCounter).value && $('keyword'+keywordCounter+'Form'+formCounter).value != ''){
                            
                                          alert('Please do not enter duplicate keywords: "'+$('keyword'+keywordCounter+'Form'+formCounter).value+'"!');
                                          new Effect.Highlight('keyword'+keywordCounter+'Form'+formCounter);                            
                                          new Effect.Highlight('keyword'+i+'Form'+formCounter);
                                          $('update'+formCounter).disabled=false;
                                          $('cancel'+formCounter).disabled=false;
                                          i = maxKeywordCounter+1;
                                          keywordCounter = i;
                                          duplicate = true;
                                                                                                   
                                   }
                     
                            }
              
                     } 
               
              }
       
       }
       
       if(empty == true){
       
              alert('Your keyword is empty!');
              $('update'+formCounter).disabled=false;
              $('cancel'+formCounter).disabled=false;       
       
       }
       else if(empty == false && duplicate == false && replyUrl == ''){
                                                          
              alert('Your reply URL is empty!');
              new Effect.Highlight('replyUrlForm'+formCounter);
              $('update'+formCounter).disabled=false;
              $('cancel'+formCounter).disabled=false;
                     
       }
       else if(empty == false && duplicate == false && pattern.test(replyUrl) == false){
       
              alert('You reply URL is invalid!');
              new Effect.Highlight('replyUrlForm'+formCounter);
              $('update'+formCounter).disabled=false;
              $('cancel'+formCounter).disabled=false;
                            
       }       
       else if(empty == false && duplicate == false){
              
              $('update'+formCounter).disabled=false;
              $('cancel'+formCounter).disabled=false;
              updater('editApiConfigStatus'+formCounter,'../processors/edit_api_config_processor.php?formCounter='+formCounter,'apiConfigForm'+formCounter);
       
       }
       
}

//if broadcast status != 100%, it will start periodical executer
function getBroadcastStatus(caId,tr){

       var executePeriodicalFunction = function(respond) {
       
              if(respond.responseText != '100%'){
       
                     new PeriodicalExecuter(function(pe) {
       
                            var handlerFunc = function(t) {
              
                                   if(t.responseText == '100%'){
                            
                                          pe.stop();
                                                               
                                   }
                     
                                   if($('broadcast_status_'+caId)){
                     
                                          $('broadcast_status_'+caId).update(t.responseText);
                     
                                   }                
              
                            }
                           
                            new Ajax.Request("../processors/load_broadcast_status_processor.php?ca_id="+caId+"&tr="+tr, {evalScripts:true , onSuccess:handlerFunc, onFailure:errFunc});

                     }, 15);
              
              }
              
              $('broadcast_status_'+caId).update(respond.responseText);
       
       }
       
       var errFunc = function(t) {
					
              alert('Error : An unexpected error has occurred please try again or contact support');

       } 
       
       new Ajax.Request("../processors/load_broadcast_status_processor.php?ca_id="+caId+"&tr="+tr, {evalScripts:true , onSuccess:executePeriodicalFunction, onFailure:errFunc});

}

function editTemplate(temId){

       $('NextStep_'+temId).disabled=true;

       if($('template_name_'+temId).value == ''){
    
              alert('Please Enter Tamplate name!');
              new Effect.Highlight('template_name_'+temId);
              $('NextStep_'+temId).disabled=false;              
    
       }
       else if($('messageCampaign_'+temId).value == ''){
    
              alert('Your Template Content Is Empty!');
              new Effect.Highlight('template_name_'+temId);
              $('NextStep_'+temId).disabled=false;              
    
       }
       else{
    
              updater('list_'+temId,'../processors/update_templates_processor.php?temId='+temId,'edit_templates_form_'+temId);

       }

}

function addTemplate(){

       $('NextStep').disabled=true;
       
       if($('template_name').value == ''){
       
              $('add_templates_status').innerHTML = '<div class="body_box_alert">Please enter tamplate name!</div>';
              new Effect.Highlight('template_name');
              $("NextStep").disabled=false;       
       
       }
       else if($('messageCampaign').value == ''){
       
              $('add_templates_status').innerHTML = '<div class="body_box_alert">Your template content is empty!</div>';
              new Effect.Highlight('messageCampaign');
              $("NextStep").disabled=false;
       
       }
       else {
              
              updater('add_templates_status','../processors/insert_templates_processor.php','add_templates_form');
       
       }


}

function checkTemplateCount(currentTemplateCount){

       if(currentTemplateCount >= 10){
    
              alert('You have reached template maximum, pls remove one template!');
    
       }
       else{
       
              $('event_2').update('<a href="#" onclick="updaterWithoutSpinner(\'event_2\',\'../processors/load_menu_campaign_templates.php\',\'event_2\');updater(\'event_3\',\'../processors/load_campaign_templates_contents.php\',\'event_3\');">&#171; Back to Templates List</a>');
              updater('event_3','../forms/add_templates_form.php','event_3');

       }

}
//According to Prototype, only new Ajax.updater support evalscripts = true, new Ajax.request doesn't support
//so can only use below way
function campaignContactGroupsRequest(){

       var handlerFunc = function(t) {

              $("campaign_sms_main_message").insert({after:t.responseText});
       
              Sortable.create
                     ("firstlist",
                            {
                                   tag: "div",
					dropOnEmpty:true,
					containment:["firstlist","secondlist"],
					constraint:false

				}
			);
		   
		Sortable.create
			("secondlist",
				{
					tag: "div",
					dropOnEmpty:true,
					handle:"handle",
					containment:["firstlist","secondlist"],
					constraint:false,
					onUpdate: function() 
					{  
						new Ajax.Request
							("../includes_campaign/update_recipients.php", 
								{  
									method: "post",  
									parameters: { data: Sortable.serialize("secondlist") }  
								}
							);  
					}
				}
			);
				               
       }
		
       var errFunc = function(t) {
					
              alert('Error : There is error in system, please contact system administrator');

       }

       new Ajax.Request('../includes_campaign/campaign_sms_recipients.inc.php', {evalScripts:true , onSuccess:handlerFunc, onFailure:errFunc });

}  

function editSmsSubscribeKeyword(formCounter){

       $('nextStep_'+formCounter).disabled=true;
       $('cancel_'+formCounter).disabled=true;
      
       var pattern=new RegExp("[^a-zA-Z0-9]");

       if(pattern.test($('keywordSubscribe_'+formCounter).value) == true){
       
              smsSubscribeErrorPrompt("Your Subscribe keyword is invalid, please try another keyword, no space or punctuation allowed!",formCounter,$('keywordSubscribe_'+formCounter));   
       
       }
       else if(pattern.test($('keywordUnsubscribe_'+formCounter).value) == true){
              
              smsSubscribeErrorPrompt("Your Unsubscribe keyword is invalid, please try another keyword, no space or punctuation allowed!",formCounter,$('keywordUnsubscribe_'+formCounter));
       
       } 
       
       else if ($('keywordSubscribe_'+formCounter).value == ''){
       
              smsSubscribeErrorPrompt("Please fill in a Subscribe keyword!",formCounter,$('keywordSubscribe_'+formCounter));   
       
       }
       else if ($('keywordSubscribe_'+formCounter).value.toUpperCase() == 'NO'){
       
              smsSubscribeErrorPrompt("'NO' is a system-reserved keyword used for unsubscribes and is not available, do choose something else!",formCounter,$('keywordSubscribe_'+formCounter));   
       
       }       
       else if ($('keywordSubscribe_'+formCounter).value == '1' || $('keywordSubscribe_'+formCounter).value == '2' ||  $('keywordSubscribe_'+formCounter).value == '3' || $('keywordSubscribe_'+formCounter).value == '4' || $('keywordSubscribe_'+formCounter).value == 'test'){
       
              smsSubscribeErrorPrompt("Note that the keyword "+$('keywordSubscribe_'+formCounter).value+" is not available, do choose something else!",formCounter,$('keywordSubscribe_'+formCounter));   
       
       }         
       else if ($('keywordUnsubscribe_'+formCounter).value == ''){
              
              smsSubscribeErrorPrompt("Please fill in a Unsubscribe keyword!",formCounter,$('keywordUnsubscribe_'+formCounter));
       
       } 
       else if ($('keywordUnsubscribe_'+formCounter).value == 'NO'){
       
              smsSubscribeErrorPrompt("'NO' is a system-reserved keyword used for unsubscribes and is not available, do choose something else!",formCounter,$('keywordUnsubscribe_'+formCounter));   
       
       }
       else if ($('keywordUnsubscribe_'+formCounter).value == '1' || $('keywordUnsubscribe_'+formCounter).value == '2' || $('keywordUnsubscribe_'+formCounter).value == '3' || $('keywordUnsubscribe_'+formCounter).value == '4' || $('keywordUnsubscribe_'+formCounter).value == 'test'){
       
              smsSubscribeErrorPrompt("Note that the keyword "+$('keywordUnsubscribe_'+formCounter).value+" is not available, do choose something else!",formCounter,$('keywordUnsubscribe_'+formCounter));   
       
       }                                 
       else if($('keywordSubscribe_'+formCounter).value == $('keywordUnsubscribe_'+formCounter).value){
                     
              smsSubscribeErrorPrompt("Your Subscribe keyword and Unsubscribe keyword cannot be same!",formCounter,$('keywordSubscribe_'+formCounter));                   
              new Effect.Highlight($('keywordUnsubscribe_'+formCounter),{duration:5});
       
       }
       else if($('groupNameInput_'+formCounter).checked == true && $('groupNameInputField_'+formCounter).value == ''){
       
              smsSubscribeErrorPrompt("Your Contact group name is empty!",formCounter,$('groupNameInputField_'+formCounter));
       
       }
       else if($('groupNameSelect_'+formCounter).checked == true && $('groupNameSelectList_'+formCounter).options[0].selected == true){
       
              smsSubscribeErrorPrompt("You must select a Contact group!",formCounter,$('groupNameSelectList_'+formCounter));
       
       }
       else{
                            
              updater('editSmsSubscribeStatus','../processors/edit_sms_subscribe_processor.php?formId='+formCounter,'editSmsSubscribeForm_'+formCounter);

       }
       
}

function smsSubscribeErrorPrompt(message,formCounter,id){

              alert(message);
              document.getElementById('nextStep_'+formCounter).disabled=false;
              document.getElementById('cancel_'+formCounter).disabled=false;
              new Effect.ScrollTo(id);  
              new Effect.Highlight(id,{duration:5});


}

function checkPauseContinueTime(){

       if($('pause').checked == true
          && $('pause_hour').value == $('continue_hour').value
          && $('pause_minute').value == $('continue_minute').value){

              alert("Your pause timestamp cannot be same with continue timestamp!");

       }
       else{

              new Effect.SwitchOff("campaign_advanced_options");

       }

}

function quicksendContactGroupsRequest(){

       var handlerFunc = function(t) {

              $('sms_recipients_select_group').innerHTML=t.responseText; 

       }
		
       var errFunc = function(t) {
					
              alert('An error has occured, please contact support');

       }

       new Ajax.Request('../includes_campaign/quicksend_selectgroups.inc.php', {onSuccess:handlerFunc, onFailure:errFunc});

}

//allow user upload their own logo
function removeCurrentCompanyLogo(){

       var answer = confirm("Are you sure you want to remove your custom logo? Click on Save, to make change permanent")
       if (answer){

              document.getElementById('company_logo').innerHTML ='NONE<br /><br /><a href="#" onclick="new Effect.SlideDown(\'upload_field\');return false;">Upload New Logo</a><br /><br />';
              document.getElementById('logoUploaded').value ="0";
              //document.getElementById('upload_field').style.display ="";

       }
}

//view as fullscreen for MO campaign only
//reference http://accessify.com/features/tutorials/the-perfect-popup/
function viewAsFullScreen(filePath){

       maxWidth = screen.availWidth;
       maxHeight = screen.availHeight;

       window.open(filePath,"COMMZGATE","resizable=1,toolbar=no,location=no,scrollbars=yes,width="+maxWidth+",height="+maxHeight+",left=0,top=0");

}


//autoexpand textarea
//Reference : http://tore.darell.no/posts/auto_expanding_textarea
function mobileTextareaExpand(textareaId){ 

       var oldValue = $(textareaId).value;
       setInterval(function(){
    
              var newValue = $(textareaId).value;
              if (newValue != oldValue) {//Value has changed
                     
                     if(newValue.split("\n").length <= 4){//if number of lines <=10 set the textarea rows to default value 12


                            $(textareaId).writeAttribute('rows', 6);

                     }
                     else{
                            //Set the "rows" attribute to the number of lines + 2
                            $(textareaId).writeAttribute('rows', newValue.split("\n").length+2);

                     }

                     oldValue = newValue;

              }

       }, 500);//Check every 0.5s

}

function quicksendCountRequest(){

       var handlerFunc = function(t) {

              $('count').innerHTML=t.responseText; 

       }
		
       var errFunc = function(t) {
					
              alert('Error : There is error in system, please contact system administrator');

       }

       new Ajax.Request('../processors/quicksend_count_processor.php', {onSuccess:handlerFunc, onFailure:errFunc});

}

function updaterWithoutSpinner(div_id,file,form_id){ 
			 
       var ajax1;			
       ajax1=new Ajax.Updater(div_id, file, {asynchronous:true, parameters: Form.serialize(form_id), onSuccess: new Effect.Appear(div_id), evalScripts:true  } );
	    
}

function checkKeywordUniqueness(inputId,addKeywordLink,addKeywordLinkNeeded){

	var keyword=document.getElementById(inputId).value;

       var handlerFunc = function(t) {
					
              if (t.responseText!="")  {
						
                     document.getElementById(inputId).blur();
                     if(addKeywordLinkNeeded == "yes"){

                            document.getElementById(addKeywordLink).style.display="NONE";

                     }
                     document.getElementById("update").disabled=true;
                     alert(t.responseText);
			
                     return false;
		}
		else {
                     document.getElementById("update").disabled=false;
                     return true;

          	}
	}

	var errFunc = function(t) {
					
              alert('Error ' + t.status + ' -- ' + t.statusText);
              return false;

	}

       var ajax1;			

       ajax1= new Ajax.Request('../processors/check_keyword_for_api.php', {parameters:'keyword='+keyword, onSuccess:handlerFunc, onFailure:errFunc});
			

}

function displayAddKeywordLink(inputId,addKeywordLink){

       if( document.getElementById(inputId).value.length > 0 ){

              new Effect.Appear(addKeywordLink,{duration:1});

       }
       else if( document.getElementById(inputId).value.length <= 0 ){

              document.getElementById(addKeywordLink).style.display="NONE";

       }       

}

function display_search_field(type,file){

       if(type =='')$("colAEvent_3").innerHTML = '';
            
       else updaterWithoutSpinner("colAEvent_3","../widgets/search_field.php?keywordInputName=contact&type="+type+"&div=event_5&file="+file,"colAEvent_3");      
       
}

function backToReportList(){

       $('event_6').innerHTML = '';
       $('event_3').style.display = '';
       $('event_5').style.display = '';
       $('colAEvent_1').style.display = '';
              
       updaterWithoutSpinner('event_2','../processors/load_menu_reports.php?reportType=list','event_2');

}

function prompt(type,keywordInputName){

       var keyword = $("keyword"+keywordInputName).value;

       if(type =='number' && isNaN(keyword) ){

              $("prompt"+keywordInputName).innerHTML='Please enter numbers only!';
              var limit=keyword.length-1;
              keyword=keyword.substring(0,limit);//notice: never use substr, due to no cross browse
              $("keyword"+keywordInputName).value=keyword;
                                         
       }
       else $("prompt"+keywordInputName).innerHTML= "";
       
       if(keyword.length > 0){       

              $("searchButton"+keywordInputName).style.display = "";
              $("closeButton"+keywordInputName).style.display = "";
                     
       }
       else if(keyword.length == 0){
       
              $("searchButton"+keywordInputName).style.display = "none";
              $("closeButton"+keywordInputName).style.display = "none";
       
       }

}

function changeCaType(){

       var parameter = '';
       
       if($("userId")) parameter = 'selectedUserId='+$("userId").value;
                     
       if($("caType")) {
       
              $('caType').value=$('campaign_type_list').value;
              parameter += '&selectedCaType='+$("caType").value;
                            
       }

       parameter += '&keyword='+$('selectedKeyword').value;

       updater('event_5', '../processors/load_reports_list_processor.php?'+parameter,'event_5');

}

//Modify
function changeUserReport(div,file)  {

       if($('select_user_list')) {
       
              var parameter = '?selectedUserId='+$('select_user_list').value;
              $('userId').value=$('select_user_list').value;
       
       }
       else var parameter;

       updater(div, file+parameter,div)
          	
       if ($("reports_filter"))$("reports_filter").style.display="none";
          	
       if ($("campaign_type_list")) {
       
              $("campaign_type_list").options[0].selected = true;
              $('caType').value='';
                     
       }
       
       $('selectedKeyword').value = '' ;
       $('keyword').value = '' ;
       prompt('name','');
       $('keyword').value = 'Type to Search' ;
       

}

function searchReportByDate(div, file, keywordInputName){

       var parameter ='?search=1';
       
       if($("userId")) parameter += '&selectedUserId='+$("userId").value;
                     
       if($('campaign_type_list'))parameter += '&selectedCaType='+$("caType").value;
       
       if($('caId'))parameter += '&caId='+$('caId').value+'&caType='+$('caTypeDesc').value+'&caName='+$('caName').value+'&keywordInputName=reportLogs';
       
       if($('from'))parameter += '&fromDate='+$('from').value+'&toDate='+$('to').value;
       
       if($('selectedKeyword'+keywordInputName))parameter += '&keyword='+$('selectedKeyword'+keywordInputName).value;
       
       if($('bounces_report_type')) parameter +='&bouncesType='+$('bounces_report_type').value;
       
       updater(div,file+parameter,div);


}

function filterEmailCampaignBounceType(){

       var parameter = '';
       
       if($('userId')) parameter = 'selectedUserId='+$('userId').value;
       
       if($('caId'))parameter += '&caId='+$('caId').value+'&caType='+$('caTypeDesc').value+'&caName='+$('caName').value+'&keywordInputName=reportLogs';
       
       if($('from'))parameter += '&fromDate='+$('from').value+'&toDate='+$('to').value;              
       
       if($('show_date_filter').style.display == '') parameter += '&search=1';
       
       parameter += '&keyword='+$("selectedKeywordreportLogs").value+'&bouncesType='+$('bounces_report_type').value;

       updater('event_6', '../processors/load_report_logs.php?'+parameter,'event_6');

}

function keyword_search(div,file,cancel,type,keywordInputName){

       $("searchButton"+keywordInputName).style.display="none";
       $("closeButton"+keywordInputName).style.display="none";
       $("wait"+keywordInputName).style.display="";
             
       var parameter ='&keywordInputName='+keywordInputName;
       
       if($('userId'))parameter += '&selectedUserId='+$("userId").value;
                     
       if($('caType'))parameter += '&selectedCaType='+$("caType").value;
       
       if($('from')){
       
              parameter += '&fromDate='+$('from').value+'&toDate='+$('to').value;
              if($('date_filter').style.display != 'none') parameter += '&search=1';
               
       }
       
       if($('caId'))parameter += '&caId='+$('caId').value+'&caType='+$('caTypeDesc').value+'&caName='+$('caName').value+'&keywordInputName=reportLogs';
       
       if($('bounces_report_type')) parameter +='&bouncesType='+$('bounces_report_type').value;
                     
       if(cancel != 'cancel')parameter += '&keyword='+$("keyword"+keywordInputName).value;
       
       if($('select_search_type'))parameter += '&searchType='+$('select_search_type').value;

       if(cancel == 'cancel'){
              
              $("searchButton"+keywordInputName).style.display = "none";
              $("closeButton"+keywordInputName).style.display = "none";
              $("keyword"+keywordInputName).value ='Type to Search';
              $("selectedKeyword"+keywordInputName).value ='';
              updater(div,file+parameter,div);
              $("wait"+keywordInputName).style.display="none";      
       
       }
       else{

              updater(div,file+parameter,div);
              $("wait"+keywordInputName).style.display="none";
              $("selectedKeyword"+keywordInputName).value = $("keyword"+keywordInputName).value;
              prompt(type,keywordInputName);
                            
       }
 
}


function deleteContact(contactId,listId,duplicate){   //delete the selected group when clicked 
	
       var answer = confirm("Are you sure you want to delete this contact?")
       if (answer){
					
              if(duplicate == 'duplicate'){
			    
                     updater('edit_duplicate_contact-'+contactId,'../processors/delete_contact_processor.php?contact_id='+contactId+'&list_id='+listId+'&duplicate=duplicate','edit_duplicate_contact-'+contactId);
                     $('edit_duplicate_link-'+contactId).style.visibility="hidden";
                     $('delete_duplicate_link-'+contactId).style.visibility="hidden";
                     
              }
              else{
              
                     updater('edit_contact-'+contactId,'../processors/delete_contact_processor.php?contact_id='+contactId+'&list_id='+listId,'edit_contact-'+contactId);
                     updaterWithoutSpinner('event_2','../processors/load_menu_group_contents.php?listId='+listId,'event_2');
                     $('edit_link-'+contactId).style.visibility="hidden";
                     $('delete_link-'+contactId).style.visibility="hidden";
                     
		}
		
       }

}
	
	
function go_Contacts_2_level(menu,content){  
	      		  
       $("colAEvent_1").style.display="none";
       $("event_5").style.display="none";
       $("event_3").innerHTML="";
			
       updaterWithoutSpinner("event_2",menu,"event_2");
       updater("event_6",content,"event_6");
		
}

function initContacts(action){  // shows contacts groups on body onload

       updaterWithoutSpinner("event_2","../processors/load_menu_groups.php","event_2");
	updaterWithoutSpinner("event_3","../processors/load_contacts_alert_processors.php","event_3");
		
	if(action =='import')updater("event_5","../processors/import_user_email_processor.php","event_5");
			
       updater("event_5","../processors/load_groups_processor.php","event_5");

}

function updater(div_id,file,form_id){ 
			 
			var ajax1;			
			ajax1=new Ajax.Updater(div_id, file, {asynchronous:true, parameters: Form.serialize(form_id), onSuccess: new Effect.Appear(div_id,{duration:1}),onFailure: new showWaitWheel(div_id), evalScripts:true  } );
	    
}

function delete_action(object,div_id,file,form_id){

			var answer = confirm("Are you sure you want to delete this "+object+"?")
			if (answer){
					
            updater(div_id,file,form_id);

      }	
 
}

function close_form(div_id){

      new Effect.SlideUp(div_id);

}



function initBlockedIPReports(){  //Get Payment Reports
	        			
			var ajax1;			
			ajax1=new Ajax.Updater('event_status_more', '../processors/load_blocked_IP_reports_processor.php', {asynchronous:true, onSuccess: new Effect.Appear('event_status_more',{duration:1}),onFailure: new showWaitWheel('event_status_more'), evalScripts:true  } );

}

function update_blocked_IP(block, blocked_IP){ 
		

		    if(document.getElementById("IP").value=='' && block =='1'){
        
            alert('Please input IP!');
        
        }


		    else {

		        document.getElementById("block").disabled=true;
		        //document.getElementById("unblock").disabled=true;		              
            var ajax1;			
		        ajax1=new Ajax.Updater('manage_blocked_ip_status','../processors/manage_blocked_ip_processor.php?block='+block+'&blocked_IP='+blocked_IP, {asynchronous:true,  parameters: Form.serialize('manage_blocked_ip_form'), onSuccess: new Effect.Appear('manage_blocked_ip_status',{duration:1}),onFailure: new showWaitWheel('manage_blocked_ip_status'), evalScripts:true  } );		
        }
}



function approve_Campaign(ca_id,approve_status) { //remove from Campaigns main page (does not delete data)
		
		if(approve_status == '1') {
		
		      var answer = confirm("Are you sure to approve this campaign?")
		
    }
		if(approve_status == '2') {
		
		      var answer = confirm("Are you sure to reject this campaign?")
		
    }	    	
		if (answer){
						
				
				//document.getElementById('campaigns_'+ca_id).style.display="none";
			
				var ajax1;			
				ajax1=new Ajax.Updater('campaigns_'+ca_id, '../processors/update_campaign_approve_status_processor.php?ca_id='+ca_id+'&approve_status='+approve_status, {asynchronous:true, onComplete: new Effect.Highlight('campaigns_'+ca_id,{duration:1}),onFailure: new showWaitWheel('campaigns_'+ca_id), evalScripts:true  } );
				
	
			}
			
			else{
				//answer=false;       
				//return answer;		
			}
}



function contacts_group_merge(){  // shows contacts groups on body onload

      if($("select").checked==true){

              if($("group_name_select_list").options[0].selected == true){

                      alert('Please select a group name!');
  
              }
              else{

                     updater('event_6','../processors/load_merge_contacts_groups_processor.php','event_6');
			              
              }

      }
      else if($("create").checked==true) {

              if($("group_name_input_field").value == ''){

                      alert('Please input a new group name!');
  
              }
              else{

			 updater('event_6','../processors/load_merge_contacts_groups_processor.php','event_6');
			               
              }
              
      }

}




function submit_merge_group(){  // shows contacts groups on body onload

     var boxesTicked = 0;
     for (i = document.getElementsByName('group[]').length - 1; i >= 0; i--) {

            if (document.getElementsByName('group[]')[i].checked == true) {

                boxesTicked++;

            }

      } 

      if(boxesTicked < 2){

            alert('Please select at least 2 group!');

      }
      else if(boxesTicked >= 2) {
			
              updater('event_2','../processors/load_menu_merge_groups_name_processor.php','event_2');
              updater('event_6','../processors/load_merge_groups_name_processor.php','event_6');
      }
}


function group_name_selection_disabled(){

    if(document.getElementById("select").checked==true){

          document.getElementById("group_name_input_field").disabled = true;
          document.getElementById("group_name_select_list").disabled = false;

    }
    else if(document.getElementById("create").checked==true) {

          document.getElementById("group_name_select_list").disabled = true;
          document.getElementById("group_name_input_field").disabled = false;
    
    }

}



function show_exportGroup_superadmin(list_id,corp_id_name){
      
       document.getElementById("event_3").innerHTML ='<br /><div ><img src="../images/icons/export.png" />&nbsp<img src="../images/icons/close_button.png" width="20" height="14" onClick="new Effect.SwitchOff(\'event_3\');" /><br /><a href="#" onclick="exportGroup_active('+list_id+');return false;">Export Active Contacts only</a> | <a href="#" onclick="exportGroup_all('+list_id+');return false;">Export All</a> | <div id="superadmin_export">Export By Corporate</div></div>';    
				
			 new Effect.SlideDown('event_3',{duration:0.2});

            new Ajax.InPlaceCollectionEditor(
                
                  'superadmin_export', '../processors/superadmin_export_email_processor.php?list_id='+list_id, {
                  collection        : corp_id_name,
                  okText            : 'Export',
                  savingText        : 'Please Wait...',
                  clickToEditText   : 'Export',
                  ajaxOptions       : {method: 'get'} //override so we can use a static for the result
            
            }); 

}





function update_star(ca_id,star_value){

      		var ajax1;				
      		ajax1=new Ajax.Updater('star_'+ca_id, '../processors/update_campaign_favorite_processors.php?ca_id='+ca_id+'&star_value='+star_value, {asynchronous:true, onSuccess: new Effect.Appear('star_'+ca_id,{duration:1}), evalScripts:true  } );

}

function change_quicksend_user_report(system_id, from_date, to_date)  {

      		var ajax1;	//			
      		ajax1=new Ajax.Updater('quicksend_sms_report', '../processors/load_quicksend_sms_report.php?from_date='+from_date+'&to_date='+to_date+'&keyword=cancel&system_id='+system_id, {asynchronous:true, onSuccess: new Effect.Appear('quicksend_sms_report',{duration:1}),onFailure: new showWaitWheel('wheel'), evalScripts:true  } );
				
				  var ajax2;	//load the blue action menu
			    ajax2=new Ajax.Updater('quicksend_sms_menu', '../processors/load_quicksend_sms_menu.php', {asynchronous:true, onSuccess: new Effect.Appear('quicksend_sms_menu',{duration:0.2}), evalScripts:true  } );

          
}




function empty_field(field){

      document.getElementById(field).value = '';

}




function search_Report_Mobilenumber(cancel,div_id,file_path,page,from_date,to_date){   //load the individual contacts in a group when clicked 

      var input     = document.getElementById("mobilenumber_keyword").value;
      //var from_date = document.getElementById("from").value;
      //var to_date   = document.getElementById("to").value;

      if(input != 'Type to Search' && isNaN(input)){

              alert('Please enter number only!');
              var limit=document.getElementById("mobilenumber_keyword").value.length-1;
              document.getElementById("mobilenumber_keyword").value=input.substr(0,limit);
              
              if(limit < 8){

                    document.getElementById("prompt").innerHTML='<font color="#999999">Please enter at least 8 digit number!</font>';

              }
      }

      else if(cancel != 'cancel'){

          if(document.getElementById("mobilenumber_keyword").value.length >= 8 ){
          
              document.getElementById("close_button").style.display="none";
              document.getElementById("wait").style.cssFloat="left";
              document.getElementById("wait").style.display="inline";
          
              keyword=document.getElementById("mobilenumber_keyword").value;
			
              var ajax1;		
			        ajax1=new Ajax.Updater(div_id, file_path+'?page='+page+'&from_date='+from_date+'&to_date='+to_date+'&keyword='+keyword, {asynchronous:true , onComplete: new Effect.SlideDown(div_id), onFailure: new showWaitWheel(div_id), evalScripts:true} );
			     //onComplete: new Effect.SlideUp("wait"), onComplete: new Effect.Appear("close_button"),
			        sleep(500);//0.5seconds	
              document.getElementById("close_button").style.cssFloat="left";
              document.getElementById("close_button").style.display="inline";
              document.getElementById("wait").style.display="none";	
              
          
          }   
      }
      else if(cancel == 'cancel'){
          
          document.getElementById("close_button").style.display="none";
          document.getElementById("wait").style.cssFloat="left";
          document.getElementById("wait").style.display="inline";          
          document.getElementById("mobilenumber_keyword").value='Type to Search';
          document.getElementById("prompt").innerHTML="";
			
			    var ajax1;		
			    ajax1=new Ajax.Updater(div_id, file_path+'?page='+page+'&from_date='+from_date+'&to_date='+to_date+'&keyword=cancel', {asynchronous:true , onComplete: new Effect.SlideDown(div_id), onFailure: new showWaitWheel(div_id) , evalScripts:true} );
		
          //document.getElementById("close_button").style.display="inline";
          sleep(500);//0.5seconds
          document.getElementById("wait").style.display="none";	
         
      }		      
			

}


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}




function search_Mobilenumber(cancel){   //load the individual contacts in a group when clicked 

      var input=document.getElementById("mobilenumber_keyword").value;

      if(isNaN(input)){

              alert('Please enter number only!');
              var limit=document.getElementById("mobilenumber_keyword").value.length-1;
              document.getElementById("mobilenumber_keyword").value=input.substr(0,limit);

              if(limit < 8){

                    document.getElementById("prompt").innerHTML='<font color="#999999">Please enter at least 8 digit number!</font>';

              }
      }

      else if(cancel != 'cancel'){

          if(document.getElementById("mobilenumber_keyword").value.length >= 8 ){
          
              document.getElementById("close_button").style.display="none";
              document.getElementById("wait").style.cssFloat="left";
              document.getElementById("wait").style.display="inline";
          
              keyword=document.getElementById("mobilenumber_keyword").value;
			     //onSuccess: new Effect.Fade('indicator2') ,
              var ajax1;		
			        ajax1=new Ajax.Updater('event_5', '../processors/load_groups_contents_processor.php?keyword='+keyword, {asynchronous:true , onFailure: new showWaitWheel('event_5'), evalScripts:true} );
	
              document.getElementById("close_button").style.cssFloat="left";
              document.getElementById("close_button").style.display="inline";
              document.getElementById("wait").style.display="none";	
              sleep(500);//0.5seconds	
          
          }   
      }
      else if(cancel == 'cancel'){
          
          document.getElementById("close_button").style.display="none";
          document.getElementById("wait").style.cssFloat="left";
          document.getElementById("wait").style.display="inline";          
          document.getElementById("mobilenumber_keyword").value='Type to Search';
          document.getElementById("prompt").innerHTML="";
			
          var ajax1;		
			    ajax1=new Ajax.Updater('event_5', '../processors/load_groups_contents_processor.php?keyword=cancel', {asynchronous:true , onFailure: new showWaitWheel('event_5'), evalScripts:true} );
	
          //document.getElementById("close_button").style.display="inline";
          document.getElementById("wait").style.display="none";	
          sleep(500);//0.5seconds
      }		      
			

}

function search_Contact_Groups(cancel) { //this is to support pagination 2007-07
	  		
      document.getElementById("close_name_button").style.display="none";
      document.getElementById("wait_name").style.cssFloat="left";
      document.getElementById("wait_name").style.display="inline";


      if(cancel != 'cancel'){

          name_keyword=document.getElementById("ca_search").value;
			    var ajax1;		
			    ajax1=new Ajax.Updater('event_5', '../processors/load_groups_processor.php?name_keyword='+name_keyword, {asynchronous:true, onSuccess: new Effect.Appear('event_5',{duration:0.5}), evalScripts:true  } );
			
          sleep(500);//0.5seconds	 		  
          document.getElementById("close_name_button").style.cssFloat="left";
          document.getElementById("close_name_button").style.display="inline";
          document.getElementById("wait_name").style.display="none";		          
  
      }				
      else if(cancel == 'cancel'){
          
          document.getElementById("ca_search").value='Type to Search';
          name_keyword='';


			    var ajax1;		
			    ajax1=new Ajax.Updater('event_5', '../processors/load_groups_processor.php?cancel=cancel', {asynchronous:true, onSuccess: new Effect.Appear('event_5',{duration:0.5}), evalScripts:true  } );
			
          sleep(500);//0.5seconds	 		  
          document.getElementById("close_name_button").style.display="none";
          document.getElementById("wait_name").style.display="none";		          

      }


}

function viewReportLogs(caId,caType,caName){   //load the SMS sent log details within a SMS Campaign Report
	
	if($('userId'))var selectedUserId = $('userId').value;
	else var selectedUserId = '';
	
       updater('event_6', '../processors/load_report_logs.php?caId='+caId+'&caType='+caType+'&caName='+caName+'&selectedUserId='+selectedUserId+'&keywordInputName=reportLogs', 'event_6');
			
	updaterWithoutSpinner('event_2', '../processors/load_menu_reports.php?reportType=logs&caId='+caId+'&caType='+caType+'&caName='+caName+'&selectedUserId='+selectedUserId, 'event_2');

	if(caType =='bounces'){
      
	      updaterWithoutSpinner('event_4', '../processors/load_bounces_reports_filter_processor.php?caId='+caId, 'event_4');

       }			
	if(caType =='read_email' || caType =='unsub_email' || caType =='unsub_email_filtered' || caType =='bounces' || caType =='duplicated_email'){
      
		updaterWithoutSpinner("colAEvent_2","../widgets/search_field.php?keywordInputName=reportLogs&type=name&div=event_6&file=../processors/load_report_logs.php?","colAEvent_2");
      
      	}
      	else{
             
              updaterWithoutSpinner("colAEvent_2","../widgets/search_field.php?keywordInputName=reportLogs&type=number&div=event_6&file=../processors/load_report_logs.php?","colAEvent_2");
             
       }
    				
}


function loadReportDetails(caId){   //load the individual campaign report details

       $('event_3').style.display = 'none';
       $('event_5').style.display = 'none';
       $('colAEvent_1').style.display = 'none';

       var parameter = 'caId='+caId;

       if($('userId')) {
       
              parameter += '&selectedUserId='+$('userId').value;
       
       }
	        		
       updater('event_6','../processors/load_reports_details_processor.php?'+parameter,'event_6');
				
	updaterWithoutSpinner('event_2', '../processors/load_menu_reports.php?reportType=details&'+parameter,'event_2');
		
}



// Add By Kuo Wei on 26-6-2008 start
//--Templates-----------

function applyTemplate(fieldName){
          
       $("message"+fieldName).value    = $("select_template_list").value;
       $("charCount"+fieldName).value  = $("select_template_list").value.length;
       checkMsgType(fieldName);
 
}


	

function display_use_template_link(){

      if(document.getElementById("select_template_list").value != ''){
  
          new Effect.Appear('use_template_link'); 
  
      }
      else if(document.getElementById("select_template_list").value == ''){
  
          document.getElementById("use_template_link").style.display="NONE"; 
  
      }
   
}

//Templates Ends
// Add By Kuo Wei on 27-6-2008 ENDS

function submitButton_editUser(){ 
		
    if(document.edit_user_form.email.value==''){
    
        alert('Please Input Email Address!');
    
    }
    else if(document.edit_user_form.fname.value==''){
    
        alert('Please Enter First Name!');
    
    }
    else if(document.edit_user_form.timezone.value==''){
    
        alert('Please Select a Timezone!');
    
    }
    else if(document.edit_user_form.country.value==''){
    
        alert('Please Select a Country!');
    
    }
    
    else {
		    
		    document.edit_user_form.NextStep.disabled=true;
		    document.getElementById("indicator").style.visibility="visible";
                     var ajax1;			
		    ajax1=new Ajax.Updater('edit_user_status','../processors/edit_user_processor.php', {asynchronous:true,  parameters: Form.serialize('edit_user_form'), onSuccess: new Effect.Appear('edit_user_status',{duration:1}),onFailure: new showWaitWheel('edit_user_status'), evalScripts:true  } );		
	
    }
     
}

function resetKeywordSearchField(type,keywordInputName){

       $('keyword'+keywordInputName).value='';
       prompt(type,keywordInputName)
       $('keyword'+keywordInputName).value='Type to Search';
       

}

function ContactsGroupSortByName(){

      resetKeywordSearchField("name","ContactGroups");
      updater("event_5","../processors/load_groups_processor.php?orderBy=name","event_5");      

}

function ContactsGroupSortByLastModified(){

      resetKeywordSearchField("name","ContactGroups");
      updater("event_5","../processors/load_groups_processor.php?orderBy=modify","event_5");

}

function display_recipients(list_id)  {

       updaterWithoutSpinner('quicksend_sms_recipients_drag', '../includes/quicksend_sms_recipients.inc.php?list_id='+list_id,'quicksend_sms_recipients_drag');
				
}



function show_sms_recipients_select_group(){ 
		    
		    display_recipients('NONE');		
    		
			document.getElementById('sms_recipients_select_group').style.display="block";
			hide_sms_recipients_freetext();
			document.getElementById('SelectGroupsTab').style.backgroundColor="#FFFFFF";
			document.getElementById('SelectGroupsTab').style.borderTop="1px solid #B8B8B8";
			document.getElementById('SelectGroupsTab').style.borderRight="1px solid #B8B8B8";
			document.getElementById('SelectGroupsTab').style.borderLeft="1px solid #B8B8B8";
}

function hide_sms_recipients_freetext(){ 
		
	  		document.getElementById("sms_recipients_freetext").style.display="none";
			document.quicksend.mobile_numbers.value = 'Enter Mobile Numbers';	
			
			document.getElementById('EnterNumbersTab').style.backgroundColor="";
			document.getElementById('EnterNumbersTab').style.border="";
						
}

function hide_sms_recipients_select_group(){ 
		
    		document.getElementById("sms_recipients_select_group").style.display="none";
			document.getElementById('select_sms_list').value='NONE';
    		//document.getElementById("quicksend_sms_recipients_drag").style.display="none"; 
    		display_recipients('NONE');		
    		
    		document.getElementById('SelectGroupsTab').style.backgroundColor="";
			document.getElementById('SelectGroupsTab').style.border="";
				
}

function show_sms_recipients_freetext(){ 
			
			document.getElementById('select_sms_list').value='NONE';
			display_recipients('NONE');
			document.getElementById('sms_recipients_freetext').style.display="block";
			
			hide_sms_recipients_select_group();
			
			document.getElementById('EnterNumbersTab').style.backgroundColor="#FFFFFF";
			document.getElementById('EnterNumbersTab').style.borderTop="1px solid #B8B8B8";
			document.getElementById('EnterNumbersTab').style.borderRight="1px solid #B8B8B8";
			document.getElementById('EnterNumbersTab').style.borderLeft="1px solid #B8B8B8";
}


function expandNumbersBox(){
			var currentRows;
			currentRows=document.getElementById("mobile_numbers").rows;
			//alert ("CurrentRows is"+currentRows);
			if (currentRows==10) {
				document.getElementById("mobile_numbers").rows="30";
				document.getElementById("BoxExpander").innerHTML ="[-]";
			}
			else {
			    document.getElementById("mobile_numbers").rows="10";
				document.getElementById("BoxExpander").innerHTML ="[+]";
			}	

}


function reset_recipients() { //pagination added by Kuo Wei on 25-2-2008
			
			//document.getElementById("api_report").style.display="none";	
		  
			var ajax1;		
			ajax1=new Ajax.Updater('campaign_sms_recepients', '../includes_campaign/campaign_sms_recipients.inc.php', {asynchronous:true , onComplete: new Effect.SlideDown('campaign_sms_recepients'), onFailure: new showWaitWheel('campaign_sms_recepients') , evalScripts:true} );
	
}

function show_date_filter(){ 
		document.getElementById("show_date_filter").innerHTML='<br /><a href="#" onclick="hide_date_filter(); return false;">Hide date filter</a><br />';				
		new Effect.SlideDown('date_filter'); 
						
}

function hide_date_filter(){ 
		document.getElementById("show_date_filter").innerHTML='<br /><a href="#" onclick="show_date_filter(); return false;">Show date filter</a><br />';				
		new Effect.SlideUp('date_filter'); 
						
}


function load_report_next_page(divId,file_path,page,fromDate,toDate) { //pagination added by Kuo Wei on 25-2-2008
			
      if($('bounces_report_type'))var bounces_type=$('bounces_report_type').value;

      var keyword = '';
      if($('keyword').value != 'Type to Search' && $('keyword').value != '')keyword=$('keyword').value;

      var ajax1;		
      ajax1=new Ajax.Updater(div_id, file_path+'?page='+page+'&fromDate='+fromDate+'&toDate='+toDate+'&keyword='+keyword+'&bounces_type='+bounces_type+'&search=1', {asynchronous:true , onComplete: new Effect.SlideDown(div_id), onFailure: new showWaitWheel(div_id) , evalScripts:true} );
	
}
function show_link(num){

       new Effect.Appear('reset_recipients'); 
       var id="show_select_options"+num;
       var select_list="select_sms_list"+num;
       num=num+1
       var select_id="select"+num;
       if($(select_id).style.visibility=="visible"){
      
          if($(select_list).options[0].selected || $(select_list).options[1].selected){
          $(id).style.visibility="hidden";
          }
      }
      else {
          //new Effect.Appear("show_select_options1");
          $(id).style.visibility="visible";
          
      }
			
}		

function hide_link(num){
			 
			if(num <5) {
        var id="show_select_options"+num;
        document.getElementById(id).style.visibility="hidden";
        
      }
    
			
}	

function show_select_options(i){
			 
			
      var id="show_select_options"+i;
      document.getElementById(id).style.visibility="hidden";
      
			i=i+1;
			var select_id="select"+i;
			document.getElementById(select_id).style.visibility="visible";
      	
}	

function check_recipient_group(group_count) {
		
	    for(var i = 2 ; i <=group_count+1 ; i++)   {
	    	      
	         var select_name1="select_sms_list1";
	         var select_name2="select_sms_list2";
	         var select_name3="select_sms_list3";
	         var select_name4="select_sms_list4";
	         var select_name5="select_sms_list5";
	         
	       if(document.getElementById(select_name1).options[i].selected || document.getElementById(select_name2).options[i].selected || document.getElementById(select_name3).options[i].selected || document.getElementById(select_name4).options[i].selected || document.getElementById(select_name5).options[i].selected) {
             
              for(var j = 1 ; j <=5 ; j++)   {  
            
                  var select_name="select_sms_list"+j;
                      
                      if(document.getElementById(select_name).options[i].selected) {
              
                           document.getElementById(select_name).options[i].disabled=false;
                           	document.getElementById(select_name).disabled=true;
				        //document.getElementById(select_name).disabled=false;
              
                      }
                      else  {
                       //alert("haha");
                       var block_id=j+"_"+i;
                      document.getElementById(select_name).options[i].value="NONE";
              	      document.getElementById(select_name).options[i].innerHTML="USED";
              	      //document.getElementById(select_name).disabled=true;
                      }
              }  
        }
        else {
              
              for(var k = 1 ; k <=5 ; k++)   {  
            
                  var select_name="select_sms_list"+k;  
                  document.getElementById(select_name).options[i].disabled=false;
              }
         
        }
        
    }
      
}
	
	function loadNextPage_api_report(ext_app_id,page,from_date,to_date) { //pagination added by Kuo Wei on 25-2-2008
			
			//document.getElementById("api_report").style.display="none";	
		  
			var ajax1;		
			ajax1=new Ajax.Updater('api_report', '../processors/load_report_api.php?ext_app_id='+ext_app_id+'&page='+page+'&from_date='+from_date+'&to_date='+to_date, {asynchronous:true , onComplete: new Effect.SlideDown('api_report'), onFailure: new showWaitWheel('api_report') , evalScripts:true} );
	
	}
	
	function loadNextPage_quicksend_sms_report(system_id,page) { //this is to support pagination 2007-07
			
			//document.getElementById("quicksend_sms_report").style.display="none";	
		
			var ajax1;		
			ajax1=new Ajax.Updater('quicksend_sms_report', '../processors/load_quicksend_sms_report.php?system_id='+system_id+'&page='+page, {asynchronous:true , onComplete: new Effect.SlideDown('quicksend_sms_report'), onFailure: new showWaitWheel('quicksend_sms_report') , evalScripts:true} );
	
	}
	
	
	
	
	

//Main Pages Navigation	
//-----------------------------------------------
	function goTo(page){
			
			//document.getElementById("indicator_top").innerHTML ='<span style="background-color:#CCCCCC; color:#FFFFFF; font-size:11px; margin-right:8px; margin-top:2px;" >Loading...</span>'; 
			 
			// new Effect.Appear('indicator_top',{duration:3});
			 document.getElementById("indicator_top").style.visibility="visible";
			 window.location.href=page;	
	}	
	
	
	
	function logOut(){
			 
			 document.getElementById("indicator_top_text").innerHTML="Logging out...";
			 document.getElementById("indicator_top").style.visibility="visible";
			 window.location.href='../processors/logout_processor.php';	
	}	


  function contact_us(){  //control function for contact us by Kuowei on 2007-11-13 
 	
	//new Effect.SlideUp('contact_us_result');
	//new Effect.ScrollTo('contact_us');
	
	//new Effect.MoveBy( this.parentNode, 110, 0 , {duration: 0.3,  transition: Effect.Transitions.slowstop});
    //new Effect.MoveBy( 'contact_us', -100, 0 , {duration: 0.5});
  
	ajax1=new Ajax.Updater('contact_us','../forms/contactus_form.php', {asynchronous:true, onSuccess: new Effect.Appear('contact_us',{duration:1}), evalScripts:true  } );
  
  }
  
  function setExistsEmail(email) {   //generate email for registered user

		document.getElementById("contact_email").value= email ;
		new Effect.Highlight('contact_email');
		
	}
	
	function submit_contact_us()  {
		
      if(document.getElementById("contact_email").value == '') {
		  
          document.getElementById("contact_email").value="Please enter your email address!";
          //alert("Please enter your email address!");
          new Effect.Highlight('contact_email');
      
      }
	  else if (document.getElementById("contact_message").value == '')  {
		  
          document.getElementById("contact_message").value="Please enter your message!";
          new Effect.Highlight('contact_message');     
      }
      
      else {
        var ajax1;			
	    ajax1=new Ajax.Updater('contact_us_result','../processors/contact_us_processor.php', {asynchronous:true,  parameters: Form.serialize('contact_us_form'), onSuccess: new Effect.Appear('contact_us_result',{duration:2}), evalScripts:true  } );
		
		new Effect.Fade('contact_us');
	  }
  }
	
	function submit_contact_us_cancel(){ 
		
		new Effect.SwitchOff('contact_us');
	
	}


  function submitResetPassword() { // control function for reset password submit button by Kuowei on 2007-11-13
  
      if(document.getElementById("email").value == '')  {
		  
          document.getElementById("error").innerHTML="Please enter your email address!";
          new Effect.Highlight('email');     
      }
      
      else  {   	      
            var ajax1;			
			      ajax1=new Ajax.Updater('forgot_password_result','../processors/password_forgot_processor.php', {asynchronous:true,  parameters: Form.serialize('forgot_password_form'), onSuccess: new Effect.Appear('forgot_password_result',{duration:1}), evalScripts:true  } );
	          //document.getElementById("forgot_password_form").style.visibility="hidden";
      }
	    
}


	
//-------------------------
//Purchase






//----------------------
//Main functions
	function loadActionMenu(){  // shows actionMenu for contacts
	        
			//alert(pg);
			var ajax1;			
			ajax1=new Ajax.Updater('action_menu', '../headers/action_menu-contacts.php', {asynchronous:true, onSuccess: new Effect.Appear('action_menu')  } );
	
	}	
	
		
	function initFinalStep(){  // shows body of final campaign step        
			//alert(pg);
			 new Effect.Appear('final_step',{duration:0.5});
			
	}
	
	function finalStep(){  // shows body of final campaign step        
			//alert(pg);
			 new Effect.Appear('final_preview');
			 document.campaign4.campaign4Next.disabled=false;
			 new Effect.Highlight('final_preview',{duration:0.5});
	}
	
	function initAccount(){  // shows body of account profile
	
			 new Effect.Appear('personal_info');
			// new Effect.Appear('api_info');
			 new Effect.Appear('coy_info',{duration:3});
	}

  
	function returnAjaxError(div) {
		
		 document.getElementById(div).innerHTML='<br /><br /><span class="body_box_alert">It seems like your Internet Connection is not active. Please get online to continue using this application.</span><br /><br />';

	}
	
	function WaitWheel(div) {
		
		 document.getElementById(div).innerHTML='<img name="indicator2" id="indicator2_image" class="indicator2" src="../images/indicator2.gif"/>';
	
	}	
	
	
	function showWaitWheel(div) {
		
		 document.getElementById(div).innerHTML='<br /><br /><img name="indicator2" id="indicator2_image" class="indicator2" src="../images/indicator2.gif"/><br /><br />';
	
	}

// Functions for Account page---------------------------------------
//===================================================================

    
  
  function loadChangePassword(link,div,form) { // Kuowei 2007-11-01 to display change password form
      document.getElementById(link).style.visibility="hidden";
      
	  var ajax1;
	 ajax1=new Ajax.Updater(div,form, {asynchronous:true, onSuccess: new Effect.Appear(div,{duration:1}), evalScripts:true  } );
      
	  
  }
  
  
  
  function close_ChangePassword(password2_tab,div,password1,password2,link) {
      
      //new Effect.Appear('changePassword_link');
	  
	  document.getElementById(password2_tab).style.display="none";
	  document.getElementById(div).style.display="none";
      //new Effect.Fade('changePassword');
	  
	  document.getElementById(password1).value='';
	  document.getElementById(password2).value='';
	  
	  document.getElementById(link).style.visibility="visible";
	  
  }
  
 
  function changePasswordAgain(password1,password1_prompt,password2_tab) {  //control function for password change input field by Kuowei on 2007-11-01
  			
		if ( (document.getElementById(password1).value.length) < 4 ) {
			
				document.getElementById(password1_prompt).innerHTML='<br /><font color="#999999">6 or more characters please</font>';
			 
							
		}
		
		else if ( (document.getElementById(password1).value.length) > 4 ) {
			
				
				document.getElementById(password1_prompt).innerHTML="";
				
				
				new Effect.Appear(password2_tab);
				
	 }
}
  
 function submitChangePassword(password1,password2,div,processor,form_id,link) { // control function for password change submit button by Kuowei on 2007-11-01
  
      if(document.getElementById(password1).value == '')
      {
          alert("Both Passwords must be filled in!");
          
      
      }
      
      else if(document.getElementById(password2).value == '')
      {
          alert("Both Passwords must be filled in!");
          
      
      }
      else if ( (document.getElementById(password1).value.length) < 6 )
      {
          alert("6 or more characters please");
      }
      else if ( (document.getElementById(password2).value.length) < 6 )
      {
          alert("6 or more characters please");
      }
      
      else if ( document.getElementById(password1).value == document.getElementById(password2).value )
      {
    	
            var ajax1;			
			      ajax1=new Ajax.Updater(div,processor, {asynchronous:true,  parameters: Form.serialize(form_id), onSuccess: new Effect.Appear(div,{duration:5}),onFailure: new showWaitWheel(div), evalScripts:true  } );
	           document.getElementById(link).style.visibility="visible";
      }
	    
      else 
	    {
	          var returnval;
            alert("Your chosen passwords do not match, please try again!");
			     	//document.signup_form.password2.focus();
				
				    new Effect.Highlight(password2);
				  
				    returnval = false;
				    return returnval;
			}
			
			 
       
}
 ////////////////////////////////////Modify Ends here////////////////////////////////////////////// 

//===================================================================






	
// Functions for Contacts---------------------------------------------
//==================================================================
	
function submitAddOneContact(){
	
       $("addContact").disabled=true;
       $("indicator").style.visibility="visible";
                                          	
       if( $("email_address").value == "" && $("mobile_country_code").value == "" ){
  
              alert("Please enter country code!");
              $("addContact").disabled=false;
              $("indicator").style.visibility="hidden";
  
       }
       else if ( $("mobile_number").value == "" && $("email_address").value == "" ){
  
              alert("Please enter either a mobile number or email address!");
              $("addContact").disabled=false;
              $("indicator").style.visibility="hidden";
                                                 
       }
       else if ( $("email_address").value == "" && $("mobile_number").value.length < 6  || $("email_address").value == "" && isNaN($("mobile_number").value)){
  
              alert("Your mobile number is invalid!");
              $("addContact").disabled=false;
              $("indicator").style.visibility="hidden";
                                                 
       }                                       
       else if ( $("email_address").value != "" || $("email_address").value == "" && $("mobile_country_code").value != "" && $("mobile_number").value.length >= 6){
		  
              updater("add_contact_status","../processors/insertcontacts_processor.php?add_contact=true","add_contact_form");
                                                 
       }
        
}

                                   function submitUploadContactsGroup(){

                                          $("upload").disabled=true;
                                          $("indicator").style.visibility="visible";

                                          if ($("listId").value == "" && $("group_name").value == ""){
       
                                                 alert("Please give this Group a name!");
                                                 $("upload").disabled=false;
                                                 $("indicator").style.visibility="hidden";

                                          }
	                                   else if($("contacts_file").value==""){
       
                                                 alert("Please select a file!");       
                                                 $("upload").disabled=false;
                                                 $("indicator").style.visibility="hidden";
                                                        
                                          }
                                          else{
       
                                                 $("upload_contacts_form").submit();
                                                 
                                          }

                                   } 
	
	function editContact(contact_id){  // retreive form to add an inividual contact
	
			      		  		
			var ajax1;	
		 	ajax1=new Ajax.Updater('edit_contact_form-'+contact_id, '../forms/edit_contact_form.php?contact_id='+contact_id, {asynchronous:true, onSuccess: new Effect.Appear('edit_contact_form-'+contact_id,{duration:1}), onFailure: new showWaitWheel('edit_contact_form-'+contact_id), evalScripts:true  } );
					
	} // Appear effect for this div is redundant, need to update--------------------



	function unDoUnsub(unsubId,unsubType){
				
		var answer = confirm("Are you sure you want to undo the usub for this contact? This contact will thereafter start receiving "+unsubType+" from you")
			
		if (answer){
				
			$('undo_unsub_fn1-'+unsubId).style.display="none";
			
			new Ajax.Updater('undo_unsub-'+unsubId, '../processors/undo_unsub_processor.php?unsubType='+unsubType+'&unsubId='+unsubId, {asynchronous:true, onSuccess: new Effect.Appear('undo_unsub-'+unsubId,{duration:1}), onFailure: new showWaitWheel('undo_unsub-'+unsubId), evalScripts:true  } );
	
			updater("event_4","../processors/showUnsubscribes.php","event_4");
			
		}
			
       }


function loadGroupContacts(listId){   //load the individual contacts in a group when clicked 
	        
       $("colAEvent_1").style.display="none";
	//$("event_5").style.display="none";
	$("event_3").innerHTML="";
			
	updaterWithoutSpinner("event_2","../processors/load_menu_group_contents.php?listId="+listId,"event_2");
	updater("event_5","../processors/load_groups_contents_processor.php?listId="+listId,"event_5");
	updaterWithoutSpinner("colAEvent_2","../widgets/select_search_type.php?file=../processors/load_groups_contents_processor.php?listId="+listId,"colAEvent_2");	

}
	


	/************            Add by Kuo Wei on 12-11-2007   **********************/	
	function general_export(){   //exports  as csv
										
		window.location.href="../processors/export_as_csv_processor.php";
							
	}
	
	
	/**************************************************************************/	
	
	
	function show_exportGroup(list_id){ 
						
              $("event_3").innerHTML ='<br /><div ><img src="../images/icons/export.png" />&nbsp<img src="../images/icons/close_button.png" width="20" height="14" onClick="new Effect.SwitchOff(\'event_3\');" /><br /><a href="#" onclick="exportGroup_active('+list_id+');return false;">Export Active Contacts only</a> | <a href="#" onclick="exportGroup_all('+list_id+');return false;">Export All</a> </div>';    
				
              new Effect.SlideDown('event_3',{duration:0.2}); 
						
	}
	
	
	

	

	function exportGroup_all(list_id){   //exports the selected group as csv
										
			    window.location.href="../processors/export_csv_processor.php?list_id="+list_id;
							
	}
	
	function exportGroup_active(list_id){   //exports the selected group as csv
										
			    window.location.href="../processors/export_csv_processor.php?mode=active&list_id="+list_id;
							
	}
	
	
		
	function show_searchGroup(list_id) { //defunct
			
			var ajax1;	
			ajax1=new Ajax.Updater('event_status_more', '../forms/search_contact_form.php?list_id='+list_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status_more',{duration:1}), evalScripts:true  } );
			
			//new Effect.SlideDown('event_status_more'); 
						
	}
	
	

  
  
  function close_searchContacts(){  // Kuo Wei 5-11-2007 -
		
          initContacts('1');
          new Effect.Appear("search_name_keyword");

          if(document.getElementById("ca_search").value.length >= 1 && document.getElementById("ca_search").value !='Type to Search'){
    
              new Effect.Appear("close_name_button");
	
	        }      
	}
  
	function load_menuSearchResults() {
		
			var ajax1;	//load the blue action menu	for upload contacts page
			ajax1=new Ajax.Updater('event_status', '../processors/load_menu_search_results.php', {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:1}), evalScripts:true  } );
		
		
	}
	
	function viewUploadFileExamples() {
		
		var ajax1;	
		ajax1=new Ajax.Updater('info', '../includes/upload_formats.php', {asynchronous:true, onSuccess: new Effect.Appear('info'), onFailure: new showWaitWheel('info'), evalScripts:true  } );
			
		//document.getElementById("info").innerHTML="<b>Cellphone Sample Upload Format</b><br />981727726<br />97655726<p /><b>Email Sample Upload Format</b><br />joe@company.com<br />smith@cg.com <br/><br/>(Each record is seperated by a new line)";	
		//new Effect.Highlight('info');
	}
	
       function showAddContactLink(listId){
       
              $('event_3').innerHTML = '<div id="addContactOptions" style="display:none;">'+
                                                 '<br />'+
                                                 '<img src="../images/icons/upload.png" />'+
                                                 '<img src="../images/icons/close_button.png" style="cursor:pointer;margin-left:10px;" width="20" height="14" onClick="new Effect.SwitchOff(\'addContactOptions\');return false;" />'+
                                                 '<br />'+
                                                 '<a href="#" onclick="updater(\'addContactsForm\',\'../forms/add_contact_form.php?list_id='+listId+'\',\'addContactsForm\');return false;">Add Contacts Manually</a> | '+ 
                                                 '<a href="#" onclick="updater(\'addContactsForm\',\'../forms/upload_contacts_form.php?mode=in_group&listId='+listId+'\',\'addContactsForm\');return false;">Upload Contacts to this Group</a>'+      
                                                 '<br />'+
                                                 '<div id="addContactsForm" style="display:none;"></div>'+
                                       '</div>';
              $('event_3').style.display ="";                        
              new Effect.SlideDown('addContactOptions',{duration:0.2});                                            
              
       }	

       function showExportLink(listId){	
	
              $('event_3').innerHTML = '<div id="exportContactOptions" style="display:none;">'+
                                                 '<br />'+
                                                 '<img src="../images/icons/export.png" />'+
                                                 '<img src="../images/icons/close_button.png" style="cursor:pointer;margin-left:10px;" width="20" height="14" onClick="new Effect.SwitchOff(\'exportContactOptions\');" />'+
                                                 '<br />'+
                                                 '<a href="#" onclick="window.location.href=\'../processors/export_csv_processor.php?mode=active&list_id='+listId+'\';return false;">Export Active Contacts only</a> | '+ 
                                                 '<a href="#" onclick="window.location.href=\'../processors/export_csv_processor.php?list_id='+listId+'\';return false;">Export All</a>'+ 
                                       '</div>'; 
              $('event_3').style.display ="";
              new Effect.SlideDown('exportContactOptions',{duration:0.2}); 
              	
	}
	
	function loadGroupSort(){ 
	
				$("event_3").innerHTML ='<br /><div ><img src="../images/icons/sort.png" />&nbsp<img src="../images/icons/close_button.png" width="20" height="14" style = "cursor:pointer;" onClick="new Effect.SwitchOff(\'event_3\');" /><br /><a href="#" onclick="ContactsGroupSortByName();return false;"> Sort By Name </a> | <a href="#" onclick="ContactsGroupSortByLastModified();return false;"> Sort By Last Modified</a></div>';    
				
				new Effect.SlideDown('event_3',{duration:0.2}); 
						
	}



//---Pagination functions--------------------------
//==================================================
		
	function loadNextPage_contacts(list_id,page) { //this is to support pagination 2007-07
			
		//document.getElementById("contacts").style.display="none";	
		
		var ajax1;		
		ajax1=new Ajax.Updater('event_5', '../processors/load_groups_contents_processor.php?list_id='+list_id+'&page='+page, {asynchronous:true , onComplete: new Effect.Appear('event_5') , onFailure: new showWaitWheel('event_5') ,evalScripts:true} );
	
	}
	
	
	function loadNextPage_reports(system_id,page) { //this is to support pagination 2007-07
			
			document.getElementById("reports_list").style.display="none";	
		
			var ajax1;		
			ajax1=new Ajax.Updater('reports_list', '../processors/load_reports_list_processor.php?system_id='+system_id+'&page='+page, {asynchronous:true , onComplete: new Effect.SlideDown('reports_list'), onFailure: new showWaitWheel('reports_list') , evalScripts:true} );
	
	}
	
	

	
	
	
	
//Reports Section-------------------------------------------------
//================================================================
	
	function initReportsList(system_id){  // shows Reports List on body onload     
	
			document.getElementById("reports_list").style.display="none";
			document.getElementById("report_details").style.display="none";
			document.getElementById("report_logs").style.display="none";
			
			document.getElementById("event_status").style.display="none";
	
			var ajax1;			
			ajax1=new Ajax.Updater('reports_summary', '../processors/load_reports_summary_processor.php?system_id='+system_id, {asynchronous:true, onSuccess: new Effect.Appear('reports_summary',{duration:2}),onFailure: new showWaitWheel('reports_summary')  } );			
				
	}
	
	
	
	function initCustomReportsList(system_id){  // shows Custom Reports List on body onload     
	
			document.getElementById("reports_list").style.display="none";
			document.getElementById("report_details").style.display="none";
			document.getElementById("report_logs").style.display="none";
			
			document.getElementById("event_status").style.display="none";
	
			var ajax1;			
			ajax1=new Ajax.Updater('custom_reports_summary', '../processors/load_custom_reports_summary_processor.php?system_id='+system_id, {asynchronous:true, onSuccess: new Effect.Appear('custom_reports_summary',{duration:1}),onFailure: new showWaitWheel('custom_reports_summary')  } );			
				
	}
	
	//+++++++++++++++++++++++++++++++++++++++++++++++++
	
	function initReportsList_Email(system_id){  // shows Reports List on body onload     
	
			var ajax1;			
			ajax1=new Ajax.Updater('reports_list', '../processors/load_reports_list_processor.php?system_id='+system_id+'&type=Email', {asynchronous:true, onSuccess: new Effect.Appear('reports_list',{duration:1}), onFailure: new showWaitWheel('reports_list')   } );			
			
			
			var ajax2;	//load the blue action menu
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?&type=Email', {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
			document.getElementById("reports_summary").style.display="none"; 
			document.getElementById("custom_reports_summary").style.display="none";
				
	}
	
		

	
	
	//+++++++++++++++++++++++++++++++++++++++++++++++++
	
	function initReportsList_Custom(system_id,type){  //type1= Custom Campaign, type2= HTTP API    
	
			var ajax1;			
			ajax1=new Ajax.Updater('reports_list', '../processors/load_custom_reports_list_processor.php?system_id='+system_id+'&type='+type, {asynchronous:true, onSuccess: new Effect.Appear('reports_list',{duration:1}), onFailure: new showWaitWheel('reports_list')   } );			
			
			
			var ajax2;	//load the blue action menu
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php', {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
			document.getElementById("reports_summary").style.display="none"; 
			document.getElementById("custom_reports_summary").style.display="none";
			
	}

	
	//+++++++++++++++++++++++++++++++++++++++++++++++++	
	

	
		

	
	
	//+++++++++++++++++++++++++++++++++++++++++++++++++!
	
	function loadReportDetails_CustomCampaign(cr_map_id){  
	
			document.getElementById("reports_list").style.display="none";	
			
			var ajax1;		
			ajax1=new Ajax.Updater('report_details', '../processors/load_custom_report_details_processor.php?cr_map_id='+cr_map_id, {asynchronous:true , onComplete: new Effect.Appear('report_details'), onFailure: new showWaitWheel('report_details'), evalScripts:true} );
				
			var ajax2;	//load the blue action menu
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?cr_map_id='+cr_map_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}),evalScripts:true  } );
		
	}
	
	
	//+++++++++++++++++++++++++++++++++++++++++++++++++
	
	
	
	function viewOpenedReport(ec_id){   //load the log details within a Campaign Report
		
			var ajax1;		
			ajax1=new Ajax.Updater('report_logs', '../processors/load_report_opens.php?ec_id='+ec_id, {asynchronous:true , onComplete: new Effect.Appear('report_logs'), onFailure: new showWaitWheel('report_logs') ,evalScripts:true} );	
					
			new Effect.ScrollTo('report_logs');
								
	}	
	
	
	function viewLinksClickedReport(ec_id){   //load the log details within a Campaign Report
		
			var ajax1;		
			ajax1=new Ajax.Updater('report_logs', '../processors/load_report_link_tracking.php?ec_id='+ec_id, {asynchronous:true , onComplete: new Effect.Appear('report_logs'), onFailure: new showWaitWheel('report_logs') ,evalScripts:true} );	
					
			new Effect.ScrollTo('report_logs');
								
	}
	
	
	function viewLinksClickedReport_details(link_id,ec_id){   //load the log details within a Campaign Report
		
			var ajax1;		
			ajax1=new Ajax.Updater('edit_function-'+link_id, '../processors/load_report_link_tracking_details.php?ec_id='+ec_id+'&link_id='+link_id, {asynchronous:true , onComplete: new Effect.Appear('edit_function-'+link_id), onFailure: new showWaitWheel('edit_function-'+link_id) ,evalScripts:true} );	
					
			new Effect.ScrollTo('edit_function-'+link_id);
								
	}
	
	
	
	function viewUnsubReport(ec_id){   //load the log details within a Campaign Report
	        		
				var ajax1;		
			ajax1=new Ajax.Updater('report_logs', '../processors/load_report_unsub.php?ec_id='+ec_id, {asynchronous:true , onComplete: new Effect.Appear('report_logs'), onFailure: new showWaitWheel('report_logs'), evalScripts:true} );
			
					
			new Effect.ScrollTo('report_logs');
								
	}
	
	
	function viewBounceReport(ec_id){   //load the log details within a Campaign Report
	        		
		var ajax1;		
			ajax1=new Ajax.Updater('report_logs', '../processors/load_report_bounces.php?ec_id='+ec_id, {asynchronous:true , onComplete: new Effect.Appear('report_logs'),onFailure: new showWaitWheel('report_logs'), evalScripts:true} );
			
					
			new Effect.ScrollTo('report_logs');
								
	}
	
	
	
	function view_SMS_SentReport(ca_id){   //load the SMS sent log details within a SMS Campaign Report
	
			//new Effect.ScrollTo('menu_blue');
	        					
			var ajax1;		
			//changed from report_logs to report_details
			ajax1=new Ajax.Updater('report_details', '../processors/load_report_sms_sent.php?ca_id='+ca_id, {asynchronous:true , onComplete: new Effect.Appear('report_details') , onFailure: new showWaitWheel('report_details'), evalScripts:true} );
			
			
			
			var ajax2;	//load the blue action menu 			
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?type=LogsSMS&ca_id='+ca_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
						
	}
	
	
	
	function view_SMS_UnsentReport(ca_id){   //load the SMS unsent log details within a SMS Campaign Report
	
			//new Effect.ScrollTo('menu_blue');
	        					
			var ajax1;		
			//changed from report_logs to report_details
			ajax1=new Ajax.Updater('report_details', '../processors/load_report_sms_unsent.php?ca_id='+ca_id, {asynchronous:true , onComplete: new Effect.Appear('report_details') , onFailure: new showWaitWheel('report_details'), evalScripts:true} );
			
			
			
			var ajax2;	//load the blue action menu 			
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?type=LogsSMS&ca_id='+ca_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
						
	}
	
	
	function view_SMS_ReceivedReport(ca_id){   //load the SMS RECEIVED log details within a SMS Campaign Report
	
			//new Effect.ScrollTo('menu_blue');
	        					
			var ajax1;		
			//changed from report_logs to report_details
			ajax1=new Ajax.Updater('report_details', '../processors/load_report_sms_received.php?ca_id='+ca_id, {asynchronous:true , onComplete: new Effect.Appear('report_details') , onFailure: new showWaitWheel('report_details'), evalScripts:true} );
			
		
			
			var ajax2;	//load the blue action menu , no change from "sent" type			
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?type=LogsSMS&ca_id='+ca_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
						
	}
	
	
	
	
	function view_SMS_SentReport_unsub(ca_id){   //load the master SMS unsub Report (not possible to load on per campaign basis
	        					
			var ajax1;		
			//changed from report_logs to report_details
			ajax1=new Ajax.Updater('report_details', '../processors/load_report_sms_unsub.php?ab_id='+ca_id, {asynchronous:true , onComplete: new Effect.Appear('report_details') , onFailure: new showWaitWheel('report_details'), evalScripts:true} );
			
			//new Effect.ScrollTo('report_logs');
			
			var ajax2;	//load the blue action menu ***incomplete***		
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?type=UnsubSMS&ca_id='+ca_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
						
	}
	
	
	
	function view_SMS_VoteMultipleRespondents(ca_id){  
		        					
			var ajax1;		
			//changed from report_logs to report_details
			ajax1=new Ajax.Updater('report_details', '../processors/load_report_vote_respondents.php?ca_id='+ca_id, {asynchronous:true , onComplete: new Effect.Appear('report_details') , onFailure: new showWaitWheel('report_details'), evalScripts:true} );
			
		
			
			var ajax2;	//load the blue action menu , no change from "sent" type			
			ajax2=new Ajax.Updater('event_status', '../processors/load_menu_reports.php?type=LogsSMS&ca_id='+ca_id, {asynchronous:true, onSuccess: new Effect.Appear('event_status',{duration:3}), evalScripts:true  } );
			
						
	}
	
	
	
	
		
	function viewMMGReport(ext_app_id,type){   //load the MMG SMS sent log details within a SMS Campaign Report
	        					
			var ajax1;		
			ajax1=new Ajax.Updater('report_logs', '../processors/load_mmg_report.php?ext_app_id='+ext_app_id+'&type='+type, {asynchronous:true , onComplete: new Effect.Appear('report_logs') , onFailure: new showWaitWheel('report_logs'), evalScripts:true} );
			
			new Effect.ScrollTo('report_logs');
										
	}
	
	
	

	
	
	
	function exportCustomReport(cr_map_campaign_id){  //*** 2007-10-31. this needs to be improved to make it generic, current only exports messages received
										
			    window.location.href="../processors/export_reports_csv_processor.php?cr_map_campaign_id="+cr_map_campaign_id;
							
	}
	
	
	
	//++++++++++++++++++++++++++++++++++++++++++++
		
	function deleteCampaignReport(campaign_id){   //delete the selected campaign when clicked 
	
			var answer = confirm("Are you sure you want to delete this Campaign and its data?")
			if (answer){
						
				//document.getElementById("indicator2_text").innerHTML ='Please wait... <br /><br />';    
				//new Effect.Appear('indicator2');
					
				document.getElementById('report_fn1_'+campaign_id).style.display="none";
				document.getElementById('report_fn2_'+campaign_id).style.display="none";
			
				var ajax1;			
				ajax1=new Ajax.Updater('report_'+campaign_id, '../processors/delete_campaign_processor.php?campaign_id='+campaign_id, {asynchronous:true, onSuccess: new Effect.Appear('report_'+campaign_id,{duration:1}), onFailure: new showWaitWheel('report_'+campaign_id), evalScripts:true  } );
	
			}
			
			else{
				//answer=false;       
				//return answer;		
			}
	}
	
	
		
		
	function deleteCampaignReport_SMS(campaign_id){   //delete the selected campaign when clicked 
	
			var answer = confirm("Are you sure you want to delete this Campaign and its data?")
			if (answer){
						
				//document.getElementById("indicator2_text").innerHTML ='Please wait... <br /><br />';    
				//new Effect.Appear('indicator2');
				
				document.getElementById('report_fn1_'+campaign_id).style.display="none";
				document.getElementById('report_fn2_'+campaign_id).style.display="none";
			
				var ajax1;			
				ajax1=new Ajax.Updater('report_'+campaign_id, '../processors/delete_campaign_processor.php?type=SMS&campaign_id='+campaign_id, {asynchronous:true, onComplete: new Effect.Appear('report_'+campaign_id,{duration:1}),onFailure: new showWaitWheel('report_'+campaign_id), evalScripts:true  } );
				
	
			}
			
			else{
				//answer=false;       
				//return answer;		
			}
	}
	
	
	function abortCampaign(ca_id) { //remove from Campaigns main page (does not delete data)
		
		var answer = confirm("Are you sure you want to abort this SMS Campaign? Pending messages will not be sent. ")
			
		if (answer){
						
				
				//document.getElementById('campaigns_'+ca_id).style.display="none";
			
				var ajax1;			
				ajax1=new Ajax.Updater('campaign_detail_1_'+ca_id, '../processors/abort_campaign_processor.php?ca_id='+ca_id, {asynchronous:true, onComplete: new Effect.Highlight('campaign_detail_1_'+ca_id,{duration:1}),onFailure: new showWaitWheel('campaign_detail_1_'+ca_id), evalScripts:true  } );
				
	
			}
			
			else{
				//answer=false;       
				//return answer;		
			}
	}
	
	
	
	function removeActiveCampaign(ca_id) { //remove from Campaigns main page (does not delete data)
		
		var answer = confirm("This SMS Campaign will no longer be monitored on this page, report data can still be found on the Reports page. Continue?")
			
		if (answer){
						
				
				//document.getElementById('campaigns_'+ca_id).style.display="none";
			
				var ajax1;			
				ajax1=new Ajax.Updater('campaigns_'+ca_id, '../processors/remove_active_campaign_processor.php?ca_id='+ca_id, {asynchronous:true, onComplete: new Effect.Highlight('campaigns_'+ca_id,{duration:1}),onFailure: new showWaitWheel('campaigns_'+ca_id), evalScripts:true  } );
				
	
			}
			
			else{
				//answer=false;       
				//return answer;		
			}
	}
	
	
	
	
	
// Hiding functions--------------------------------------------
//=============================================================

	function hideIndicator2(){ //use this in processer returns to fade indicator2 whenever results load
    	
		new Effect.Fade("indicator2");
	
	}
	
	function hideContactsIndividual(){ //use this in processer returns to fade contacts_individual whenever results load
    	
		new Effect.BlindUp("contacts_individual");
		new Effect.BlindUp("add_contact");
		new Effect.BlindUp("upload_contacts");
    new Effect.Appear("search_name_keyword");

        if(document.getElementById("ca_search").value.length >= 1 && document.getElementById("ca_search").value !='Type to Search'){
    
              new Effect.Appear("close_name_button");
	
	      }

  }
	
	function hideUploadContacts(){ //use this in processer returns to fade contacts_individual whenever results load
    	
		document.getElementById("info").style.display="none";
		new Effect.BlindUp("upload_contacts");
		
		//document.getElementById("upload_contacts").style.display="none";	
	}
	
	
	function hideReportDetails(){ //use this in processer returns to fade contacts_individual whenever results load
    	
		//new Effect.BlindUp("report_details");
		document.getElementById("report_details").style.display="none"; //hide this again in case of back nav		
		document.getElementById("report_logs").style.display="none"; //hide this again in case of back nav
		new Effect.Appear("search_name_keyword");
		
		if(document.getElementById("ca_search").value.length >= 1 && document.getElementById("ca_search").value !='Type to Search'){
    
            new Effect.Appear("close_name_button");
    
    }

	}
	
	//-----------------------------------------------------------
	
	function clearAll(){  // set for body onload. deprecated by ajax form submit implementation
		document.campaign_step.NextStep.disabled=false;
		document.getElementById("indicator").style.visibility="hidden";		
	}
	
	function show_resetPassword(){ 
		document.getElementById('forgot_password').innerHTML="Reset Password";
	}
	
	
	

//--Submit Buttons-----------------------------------------------------------------------
//======================================================================================
	
	
		
	function submitButton_signup(){ 
	
		document.signup_form.register.disabled=true;
		document.signup_form.register.value='Please wait. . .';
		//document.getElementById("indicator").style.visibility="visible";
		
		if (validateSignup()==true) {
		
				var ajax1;			
				ajax1=new Ajax.Updater('signup_process_status','../signup/65279e1ecf00d0d1177a5b3b458fd187a1d6135e.php', {asynchronous:true,  parameters: Form.serialize('signup_form'), onSuccess: new Effect.Appear('signup_process_status',{duration:1}),onFailure: new showWaitWheel('signup_process_status'), evalScripts:true  } );
									
		}
		
		else {
			resetSignup();
			//document.signup_form.email.focus();
		}
	
	}
	
	
	function resetSignup() {
			
			document.signup_form.register.disabled=false;			
			document.signup_form.register.value='Proceed';
			
		
	}
	
	
	function submitVerification_signup() {
		
		   	document.getElementById("continue").disabled=true;
		
			if (verifyCode()==true) {
			
					var ajax1;			
					ajax1=new Ajax.Updater('signup_verification_status','../signup/108be1ed80981e647b61c22993e9a42d9aca7fdc.php', {asynchronous:true,  parameters: Form.serialize('verifyCode'), onSuccess: new Effect.Appear('signup_verification_status',{duration:1}),onFailure: new showWaitWheel('signup_verification_status'), evalScripts:true  } );		
			
			}
			
			else {
				document.getElementById("continue").disabled=false;
				//document.login.NextStep.value='Login';
				
			}		
		
	}
	
	//++++++++++++++++++++++++
	
	
	function submitButton(){ //for all normal pages
		document.campaign_step.NextStep.disabled=true;
		document.getElementById("indicator").style.visibility="visible";
		document.campaign_step.submit();		
	}
	
		
function submitButton_saveContact(contact_id){ 
	
	if((document.getElementById("contact_mobile_cc").value=='' ) && (document.getElementById("contact_mobile").value!='')){
  
      alert('Please enter mobile number country code!');
  
  }
  else if((document.getElementById("contact_mobile").value=='' )&&(document.getElementById("contact_email").value=='' )){
  
      alert('Please enter a mobile number or email address!');
  
  }
  else if((isNaN(document.getElementById("contact_mobile_cc").value)) ){
  
      alert('Your country code is invalid!');
  
  }
  else if ( (document.getElementById("contact_mobile").value.length<8 || (isNaN(document.getElementById("contact_mobile").value)) ) && (document.getElementById("contact_email").value=='' ) ) {
  
      alert('Your mobile number is invalid!');
  
  }
  else if ( (document.getElementById("contact_mobile_cc").value != '' && document.getElementById("contact_mobile").value.length >= 6) || (document.getElementById("contact_email").value!='') ){
	
	
		//document.'edit_contact_form-'+contact_id.NextStep.disabled=true;
		//document.getElementById("indicator_edit_contact").style.visibility="visible";
		//new Effect.Fade('edit_contact_form-'+contact_id,{duration:3});
		//document.getElementById('edit_contact_form-'+contact_id).innerHTML='<img name="indicator" src="../images/indicator3.gif" />';
		var ajax1;			
		ajax1=new Ajax.Updater('edit_contact-'+contact_id,'../processors/update_contact_processor.php?contact_id='+contact_id, {asynchronous:true,  parameters: Form.serialize('edit_contact_form-'+contact_id), onSuccess: new Effect.Appear('edit_contact-'+contact_id,{duration:3}), evalScripts:true  } );
		new Effect.ScrollTo('edit_contact-'+contact_id);
	}	
	
}
	
function submitSearchContact(){
                                   
       if($("search_name").value == "" && $("search_email").value == "" && $("search_mobile").value == "" && $("filter").options[0].selected == true) {
          
              alert("Please enter at least 1 field!");
      
       }
       else{
			 
              $("searchSubmitButton").disabled = true;
              $("searchSubmitButton").value = "Searching...";
              $("indicator").style.visibility = "visible";
		
              $("event_2").innerHTML="<a href=\'#\' onclick=\'go_Contacts_2_level(\"../processors/load_menu_group_contents.php\",\"../forms/search_contact_form.php\");return false;\'>&#171; Search Again</a>";
              updater("event_6","../processors/searchcontacts_processor.php","search_contact_form");

	}                                   
                                                                      
}
	
	


	
	//------------------------------
	
	function submitLogin(){ //for login page
		document.login.NextStep.disabled=true;
		document.getElementById("indicator").style.visibility="visible";
		document.login.NextStep.value='Verifying...';
			
		if (checkForm()==true) {
		 	//document.login.submit();	
			//alert('True!');
			
			//document.getElementById("event_status").style.visibility="hidden";	
				
			var ajax1;			
			ajax1=new Ajax.Updater('event_status', '../processors/login_processor-x.php', {asynchronous:true, parameters: Form.serialize('login'), onSuccess: new Effect.Appear('event_status'), evalScripts:true  } ); 

			//new Effect.Shake("event_status"); //necessary especially for repeated attempts
	
		}
		else {
			document.login.NextStep.disabled=false;
			document.getElementById("indicator").style.visibility="hidden";	
			document.login.NextStep.value='Login';
		}
	}
	
	
	function clearLogin(){			
			document.login.NextStep.disabled=false;
			document.getElementById("indicator").style.visibility="hidden";
			document.login.NextStep.value='Login';
	}
	
	
	//--------------------------------------------------------------------------------------
	
	function showError() {
		
			//document.getElementById("event_status").innerHTML = error ;
			new Effect.Appear("event_status"); 
			
	}

	
	
	
	
//CAMPAIGN MANAGEMENT========================================================================================
//---------------------------------------------------------------------------------------


	function setSMSCampaignName_Date(datetime) {   //sets current date/time for SMS campaign name

		document.campaign_sms.ca_sms_name.value= datetime ;
		new Effect.Highlight('ca_sms_name');
		
	}
	
	
	function setCampaignName_Date(datetime) {   //sets current date/time for Email campaign name

		document.campaign.ca_name.value= datetime ;
		new Effect.Highlight('ca_name');
		
	}
	
	
	function checkEmailSyntax(){
		var x = document.campaign2.ca_from_email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {	
			document.campaign2.ca_reply_to.value=document.campaign2.ca_from_email.value;
			new Effect.Highlight('reply_to');		
		}
		else {
			alert('The From email address you entered seems to be of incorrect format. Please try again!');
			document.campaign2.ca_from_email.focus();			
		}
	}
	
		
	function checkEmailSyntax_2(){
		var x = document.campaign2.ca_reply_to.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {	
		
			return true;
		
		}
		else {
			alert('The Reply-to email address you entered seems to be of incorrect format. Please try again!');
			document.campaign2.ca_reply_to.focus();		
			return false;
		}
	}



	
	//-------------------------------------------------
	
	function submitCampaign(){ //submits campaign step 1
	
		document.campaign.campaignNext.disabled=true;
		document.getElementById("indicator").style.visibility="visible";
		document.campaign.campaignNext.value=='Please wait...';
		
		var campaignName=document.campaign.ca_name.value;
		//alert(campaignName);	
			
		if (checkCampaign1()==true) {
			//alert('True!');
			new Effect.SlideUp('campaign')
			
			var ajax1;			
			ajax1=new Ajax.Updater('campaign2', '../processors/campaign_processor?step=1', {asynchronous:true, parameters: Form.serialize('campaign'), onComplete: new Effect.Appear('campaign2'),onFailure: new showWaitWheel('campaign2'), evalScripts:true  } ); 
			
			//new Effect.Highlight("event_status");		

		}
		else {
			document.campaign.campaignNext.disabled=false;
			document.getElementById("indicator").style.visibility="hidden";	
			document.campaign.campaignNext.value='Next';
		}
	}
	
	
	
	//------------------------
	
	
	function submitCampaign2(){ //submits campaign step 2
	
	
		document.campaign2.campaign2Next.disabled=true;
		document.getElementById("indicator_c2").style.visibility="visible";
		document.campaign2.campaign2Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		if (checkCampaign2()==true) {
			//alert('True!');
			new Effect.SlideUp('campaign2')
			
			var ajax1;			
			ajax1=new Ajax.Updater('campaign3', '../forms/campaign_upload_form.php', {asynchronous:true, parameters: Form.serialize('campaign2'), onComplete: new Effect.Appear('campaign3'), onFailure: new showWaitWheel('campaign3'),evalScripts:true  } ); 			
			//new Effect.Highlight("event_status");		

		}
		
		else {
			document.campaign2.campaign2Next.disabled=false;
			document.getElementById("indicator_c2").style.visibility="hidden";	
			document.campaign2.campaign2Next.value='Next';
		}
	}
	
	
	
	function submitCampaign3(){ //submits campaign step 3
	
		document.campaign3.campaign3Next.disabled=true;
		document.getElementById("indicator_c3").style.visibility="visible";
		document.campaign3.campaign3Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		if (checkCampaign3()==true) {
			//alert('True!');		
			//document.getElementById("indicator2").style.visibility="visible";//doesn't work?
			document.campaign3.submit();	
		}
		
		else {
			document.campaign3.campaign3Next.disabled=false;
			document.getElementById("indicator_c3").style.visibility="hidden";	
			document.campaign3.campaign3Next.value='Next';
			
		}
	}
	
	
	function submitCampaign4(){ //submits campaign step 4, final step
	
			document.campaign4.campaign4Next.disabled=true;
			document.getElementById("indicator_c4").style.visibility="visible";
			document.campaign4.campaign4Next.value=='Please wait...';
		
			if (checkCampaign4()==true) {
				//alert('True!');
				new Effect.SlideUp('final_step')
				
				var ajax1;			
				ajax1=new Ajax.Updater('campaign4_result', '../processors/campaign_processor?step=final', {asynchronous:true, parameters: Form.serialize('campaign4'), onComplete: new Effect.Appear('campaign4_result'), onFailure: new showWaitWheel('campaign4_result'),evalScripts:true  } ); 
				
			}
			
			else {
				document.campaign4.campaign4Next.disabled=false;
				document.getElementById("indicator_c4").style.visibility="hidden";	
				document.campaign4.campaign4Next.value='Next';
			}
			
			
	}
	

/*############################## KW 20071102    Modify Start From Here                #################################################*/

	/* PENDING ACTIVATION ----------------
	
	function submitCampaign(){ //submits campaign step 1
	
		document.campaign.campaignNext.disabled=true;
		document.getElementById("indicator").style.visibility="visible";
		document.campaign.campaignNext.value=='Please wait...';
		
		var campaignName=document.campaign.ca_name.value;
		//alert(campaignName);	
			
		if (checkCampaign1()==true) {
			//alert('True!');
			new Effect.SlideUp('campaign')
			
			var ajax1;			
			ajax1=new Ajax.Updater('campaign2', '../processors/campaign_processor.php?step=1', {asynchronous:true, parameters: Form.serialize('campaign'), onComplete: new Effect.Appear('campaign2'),onFailure: new showWaitWheel('campaign2'), evalScripts:true  } ); 
			
			//new Effect.Highlight("event_status");		

		}
		else {
			document.campaign.campaignNext.disabled=false;
			document.getElementById("indicator").style.visibility="hidden";	
			document.campaign.campaignNext.value='Next';
		}
	}
	//---
	function submitCampaign2(){ //submits campaign step 2(select upload html file or edit the file)
	
	  document.campaign2.campaign2Next.disabled=true;
		document.getElementById("indicator_c2").style.visibility="visible";
		document.campaign2.campaign2Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		if (checkCampaign2()==true) {
			//alert('True!');
			new Effect.SlideUp('campaign2')
			
			var ajax1;			
			ajax1=new Ajax.Updater('campaign3', '../processors/campaign_processor.php?step=2', {asynchronous:true, parameters: Form.serialize('campaign2'), onComplete: new Effect.Appear('campaign3'), onFailure: new showWaitWheel('campaign3'),evalScripts:true  } ); 			
			//new Effect.Highlight("event_status");		

		}
		
		else {
			document.campaign2.campaign2Next.disabled=false;
			document.getElementById("indicator_c2").style.visibility="hidden";	
			document.campaign2.campaign2Next.value='Next';
		}
	}
	
	//------------------------
	
	
	function submitCampaign3(){ //submits campaign step 3
	
	
		document.campaign3.campaign3Next.disabled=true;
		document.getElementById("indicator_c3").style.visibility="visible";
		document.campaign3.campaign3Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		//if (checkCampaign3()==true) {
			//alert('True!');
			   new Effect.SlideUp('campaign3')
			   if(document.getElementById("upload_file").checked)
			   {
			          var ajax1;			
			          ajax1=new Ajax.Updater('campaign4', '../forms/campaign_upload_form.php', {asynchronous:true, parameters: Form.serialize('campaign3'), onComplete: new Effect.Appear('campaign4'), onFailure: new showWaitWheel('campaign4'),evalScripts:true  } ); 			
			         //new Effect.Highlight("event_status");		
         }
         if(document.getElementById("write_file").checked)
			   {
  			      
             // var ajax1;			
			 //       ajax1=new Ajax.Updater('campaign4', '../forms/htmleditor_form.php', {asynchronous:true, parameters: Form.serialize('campaign3'), onComplete: new Effect.Appear('campaign4'), onFailure: new showWaitWheel('campaign4'),evalScripts:true  } ); 			
            
            window.location.href="../app/campaign-htmleditor.php";
             
			   
        }
	//	}
		
		else {
			document.campaign3.campaign3Next.disabled=false;
			document.getElementById("indicator_c3").style.visibility="hidden";	
			document.campaign3.campaign3Next.value='Next';
		}
	}
	
	
	
	function submitCampaign4_1(){ //submits campaign step 4 (check upload file)
	
		document.campaign4.campaign4Next.disabled=true;
		document.getElementById("indicator_c4").style.visibility="visible";
		document.campaign4.campaign4Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		if (checkCampaign4_1()== true) {
			//alert('True!');		
			//document.getElementById("indicator2").style.visibility="visible";//doesn't work?
			document.campaign4.submit();	
		}
			
		else {
			document.campaign4.campaign4Next.disabled=false;
			document.getElementById("indicator_c4").style.visibility="hidden";	
			document.campaign4.campaign4Next.value='Next';
			
		}
	}
	
	function submitCampaign4_2(){ //submits campaign step 4  (check write file)
	
		document.campaign4.campaign4Next.disabled=true;
		document.getElementById("indicator_c4").style.visibility="visible";
		document.campaign4.campaign4Next.value=='Please wait...';
		
		//alert(campaignName);	
			
		if (checkCampaign4_2()== true) {
			   //alert('True!');		
			   //document.getElementById("indicator2").style.visibility="visible";//doesn't work?
			   //new Effect.SlideUp('campaign4')
			   //var ajax1;			
			   //ajax1=new Ajax.Updater('campaign5', '../app/campaign-recipients.php', {asynchronous:true, parameters: Form.serialize('campaign4'), onComplete: new Effect.Appear('campaign5'), onFailure: new showWaitWheel('campaign5'),evalScripts:true  } ); 			
			   //new Effect.Highlight("event_status");
         //document.campaign4.submit();		
         window.location.href="../app/campaign-recipients.php";
		}
		
		else {
			document.campaign4.campaign4Next.disabled=false;
			document.getElementById("indicator_c4").style.visibility="hidden";	
			document.campaign4.campaign4Next.value='Next';
			
		}
	}
	
	
	function submitCampaign5(){ //submits campaign step 5, final step
	
			document.campaign5.campaign5Next.disabled=true;
			document.getElementById("indicator_c5").style.visibility="visible";
			document.campaign5.campaign5Next.value=='Please wait...';
		
			if (checkCampaign5()==true) {
				//alert('True!');
				new Effect.SlideUp('final_step')
				
				var ajax1;			
				ajax1=new Ajax.Updater('campaign5_result', '../processors/campaign_processor.php?step=final', {asynchronous:true, parameters: Form.serialize('campaign5'), onComplete: new Effect.Appear('campaign5_result'), onFailure: new showWaitWheel('campaign5_result'),evalScripts:true  } ); 
				
			}
			
			else {
				document.campaign5.campaign5Next.disabled=false;
				document.getElementById("indicator_c5").style.visibility="hidden";	
				document.campaign5.campaign5Next.value='Next';
			}
			
			
	}
	
*/
/*##############################   KW 20071102  Modify Ends Here                #################################################*/	



   function showCampaignAdvancedOptions() {
   
   
   			new Effect.Appear('campaign_advanced_options');
   
   
   }





	function submitCampaignSMS(type){ //submits SMS campaign 
	        			
              $("campaign_SMS_submit").disabled=true;
              $("indicator").style.visibility="visible";
              $("campaign_SMS_submit").value=='Please wait...';
		
		if (checkCampaignSMS(type)==true) {

                     $("scroll_area").style.display="none";
			$("scroller").style.display="none";
				
                     updater("event_1","../processors/sms_processor.php","campaign_sms");
                     
		}
			
		else{

			$("campaign_SMS_submit").disabled=false;
			$("indicator").style.visibility="hidden";

			if($("approval_status").value == '1'){
				
				$("campaign_SMS_submit").value='Start Campaign';
		
			}	
			else if($("approval_status").value == '0'){

				$("campaign_SMS_submit").value='Start Campaign';

			}
						
	      }
	
       }		
	
	
	function loadCampaignDetails(ca_id,ca_status,mode,ca_email) {

                     var parameter = 'ca_id='+ca_id+'&ca_status='+ca_status+'&show_details1='+mode+'&ca_email='+ca_email;

                     if($('userId')) {
       
                            parameter += '&selectedUserId='+$('userId').value;
       
                     }
	
			var ajax1;			
		
			ajax1=new Ajax.Updater('campaign_detail_'+ca_id, '../processors/load_campaign_detail_processor.php?'+parameter, {asynchronous:true, onComplete: new Effect.Appear('campaign_detail_'+ca_id), evalScripts:true  } ); 
			
			//new Effect.ScrollTo('campaign_detail_1_'+ca_id);
			//overscroll problem on IE6 for this	
	
	}
	
	function hideCampaignDetails(ca_id) {
	
			new Effect.SlideUp('campaign_detail_'+ca_id); 
	
	}
	

	
	
	//-------------------------------------------------------------------------------------------
	///QUICK SEND FUNCTIONS-----------------------------------
	
	/*
	function submitQuickSendSMS(){ //submits QuickSend
	
			//new Effect.Fade('quicksend_sms_result');
	
			document.quicksend.quicksend_SMS_submit.disabled=true;
			document.getElementById("indicator").style.visibility="visible";
			document.quicksend.quicksend_SMS_submit.value=='Please wait...';
		
			if (checkQuickSend()==true) {
				//alert('True!');
			
				var ajax1;			
				ajax1=new Ajax.Updater('quicksend_sms_result', '../processors/sms_processor_quicksend.php', {asynchronous:true, parameters: Form.serialize('quicksend'), onComplete: new Effect.Appear('quicksend_sms_result'), evalScripts:true  } ); 
				
			}
			
			else {
				document.quicksend.quicksend_SMS_submit.disabled=false;
				document.getElementById("indicator").style.visibility="hidden";	
				document.quicksend.quicksend_SMS_submit.value='Send';
			}
			
			
	} */
	
	
	
    function submitQuickSendSMS(){ //submits QuickSend
	
          //new Effect.Fade('quicksend_sms_result');

          $("quicksend_SMS_submit").disabled=true;
          $("indicator").style.visibility="visible";
          $("quicksend_SMS_submit").value=='Please wait...';
		
          if ($("messageQuicksend").value == "") {
				
                 alert("Please enter a Message to be sent!");
                 $("messageQuicksend").focus();
                 $("quicksend_SMS_submit").disabled=false;
                 $("indicator").style.visibility="hidden";	
				 $("quicksend_SMS_submit").value='Send';
			    
				 return;
		
		   }
		  
           else if ($("mobile_numbers").value == ''  && $("selectedRecipients").value == '' || 
                       $("mobile_numbers").value == 'Enter Mobile Numbers' && $("selectedRecipients").value == '' || 
                       $("mobile_numbers").value == 'Enter Mobile Numbers' && $("selectedRecipients").value == '') {

	                   alert("Please enter at least 1 Mobile Number");
	                   $("mobile_numbers").focus();
	                   $("quicksend_SMS_submit").disabled=false;
	                   $("indicator").style.visibility="hidden";	
	                   $("quicksend_SMS_submit").value='Send';
				    
						return;
           }
              
		   if ($("mobile_numbers").value != 'Enter Mobile Numbers' && $("mobile_numbers").value != '' && !validateQuickSendMsisdn())  {
			
                    alert("Your Mobile Numbers entered should contain only numbers, each number should be in a newline. Please try again!");
					$("mobile_numbers").focus();
					$("quicksend_SMS_submit").disabled=false;
					$("indicator").style.visibility="hidden";	
					$("quicksend_SMS_submit").value='Send';
						    
					return;
			
		   }
						
           else {
                    var ajax1;			
					updater('event_1','../processors/sms_processor_quicksend.php','quicksend');
           }
						
	}
	
	
	
	function resetQuickSendSMS(){
	
              new Effect.ScrollTo('event_1');
              
              $("quicksend_SMS_submit").disabled=false;
              $("indicator").style.visibility="hidden";	
              $("quicksend_SMS_submit").value='Send Again';	
				
              $("mobile_numbers").value ='';
              $("messageQuicksend").value ='';
				
              if($('select_sms_list').value != 'NONE'){

                     display_recipients('NONE');
              				
              }
          			
              $('select_sms_list').value='NONE';
              $("mobile_numbers").value = 'Enter Mobile Numbers';
        
	}
	
	
	
	function initQuickSend(list_id){  // shows sms_recipients_group pull-down menu for selection on body onload
	    
      		//new Effect.Appear('quicksend_sms_recipients_group'); 
      	
			var ajax1;			
			ajax1=new Ajax.Updater('quicksend_sms_recipients_group', '../processors/load_quicksend_groups_processor.php?list_id='+list_id, {asynchronous:true, method:'POST', onSuccess: new Effect.Appear('quicksend_sms_recipients_group',{duration:1}),onFailure: new showWaitWheel('quicksend_sms_recipients_group'), evalScripts:true  } );
	
	}
	
	/*
	function loadQuicksendSmsRecipients(list_id){   //by KuoWei: load the individual numbers into the left list for selection 
	   
	   		//new Effect.Appear('quicksend_sms_recipients_contents'); 
			//new Effect.Appear('recipients');
		 	
		 	var ajax1;
			ajax1=new Ajax.Updater('quicksend_sms_recipients_contents', '../processors/load_quicksend_groups_contents_processor.php?list_id='+list_id, {asynchronous:true, onFailure: new showWaitWheel('quicksend_sms_recipients_contents'), evalScripts:true} );
	
	} */

	function loadQuicksendSmsRecipients(){   //load the individual contacts in a group when clicked 
	    //new Effect.Appear('quicksend_sms_recipients_group'); 
			new Effect.Appear('quicksend_sms_recipients_contents'); //new
			new Effect.Appear('recipients');
			
			
			//Add by Kuo Wei on 2-1-2008 start
			var selected_option=document.getElementById("select_sms_list").selectedIndex;
			var list_id=document.getElementById("select_sms_list").options[selected_option].value;
			//Add by Kuo Wei on 2-1-2008end
		  var ajax1;		
			
			ajax1=new Ajax.Updater('quicksend_sms_recipients_contents', '../processors/load_quicksend_groups_contents_processor.php?list_id='+list_id, {asynchronous:true, onFailure: new showWaitWheel('quicksend_sms_recipients_contents'), evalScripts:true} );
	
	}
			

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

	
	
	function nextPage(){ //for campaign step 4, insert validated contacts
		document.getElementById("NextStep").disabled=true;
		document.getElementById("indicator").style.visibility="visible";
		document.getElementById("indicator2_text").innerHTML ='Please wait while we finalize your campaign setup ...<br /><br />';    
		//document.getElementById("indicator2").style.visibility="visible"; 
		new Effect.Appear('indicator2');
			
		new Effect.Fade(document.getElementById('contacts_result'));

		//location.href="campaign-step5.php";	
	}
	
	
	function loadProgressBarImages(){ //need to subsume/consolidate this
		document.getElementById("upload_images").style.visibility="hidden";
		document.getElementById("indicator2").style.visibility="visible";		
	}	
	
	
	function loadProgressBar(){
		
		new Effect.Appear('indicator2');
		
	}	
	
	
	function loadProgressBarContacts(){
	    //document.getElementById("indicator2_image").style.visibility="visible";
		//new Effect.Appear(document.getElementById('indicator2_image'));
		
		document.getElementById("indicator2_text").innerHTML ='Please wait while we check your list...<br />'; 
		//document.getElementById("indicator2").style.visibility="visible";
		new Effect.Appear('indicator2');
		//new Effect.BlindDown(document.getElementById('indicator2'));
		
		//document.getElementById("upload_contacts").style.visibility="hidden";
		//new Effect.Fade(document.getElementById('contacts_result'));
		
	}	

	
	
//------------------------------------------
var AjaxReq;

	function showContactsUploadResults(){
		//document.getElementById("upload_contacts").style.visibility="hidden";
		//document.getElementById("indicator2").style.visibility="hidden";
		//document.getElementById("continue_upload").style.visibility="visible";
		
		 if (typeof window.ActiveXObject != 'undefined' )  {
				AjaxReq = new ActiveXObject("Microsoft.XMLHTTP");
				AjaxReq.onreadystatechange = getResults;
		  }
		  
		  else {
			AjaxReq = new XMLHttpRequest();			
		    AjaxReq.onload = getResults;
		  }
		  
		  try { 
			AjaxReq.open( 'GET', '../processors/show_contacts_result.php', true );
		  } 
		  
		  catch( e ) {
			alert( e );
		  }
		  AjaxReq.send("");
	}	
	
	function getResults() {
	
	  if ( AjaxReq.readyState == 4 && AjaxReq.status == 200 ) {
	  
		var rows = eval('('+AjaxReq.responseText+')' );
		
		//alert('There are '+rows.contacts_result.length+' results!');

		var html = "<br /><b>The following email addresses has problems</b><br /><br /><table width='100%'><tr bgcolor='#D8D8D8'><td>Email Address</td></tr>";
		

		var r= rows.contacts_result.length;	
		for(var i=0; i<rows.contacts_result.length; i++) {
			 
			html += "<tr>";
			html += "<td>"+rows.contacts_result[i].email+"</td>";
			//html += "<td>"+rows.contacts_result[i].desc+"</td>";
			html += "</tr>";
		}
		html += "</table>";
		html += "<br /><p> These email address will not be uploaded, the rest will be created as members of a new Contact Group. </p>";
		html += '<div align="right"><br /><input  id="NextStep"  name="Next" type="button"  value="Next" onClick="nextPage()"/><div id="indicator" style="visibility:hidden"><img name="indicator" src="../images/indicator3.gif" /></div></div>';
	
		document.getElementById( "contacts_result" ).innerHTML = html;
		
	  }
	}
	
//------------------------------------------


	function insertContacts() {
	
	  if ( AjaxReq.readyState == 4 && AjaxReq.status == 200 ) {
	  
		var rows = eval('('+AjaxReq.responseText+')' );
		
		//alert('There are '+rows.contacts_result.length+' results!');

		var html = "<br /><b>The following email addresses has problems</b><br /><br /><table width='100%'><tr bgcolor='#D8D8D8'><td>Email Address</td></tr>";
		

		var r= rows.contacts_result.length;	
		for(var i=0; i<rows.contacts_result.length; i++) {
			 
			html += "<tr>";
			html += "<td>"+rows.contacts_result[i].email+"</td>";
			//html += "<td>"+rows.contacts_result[i].desc+"</td>";
			html += "</tr>";
		}
		html += "</table>";
		html += "<br /><p> These email address will not be uploaded, the rest will be created as members of a new Contact Group. </p>";
		html += '<div align="right"><br /> <form><input  id="NextStep"  name="Next" type="button"  value="Next" onClick="nextPage()"/><div id="indicator" style="visibility:hidden"><img name="indicator" src="../images/indicator3.gif" /></div></form></div>';
	
		document.getElementById( "contacts_result" ).innerHTML = html;
		
	  }
	}


//-----------------------
function initReportsPie(){ 
			 
			//new Effect.Appear('dash_col-A');
	
			var ajax1;			
			ajax1=new Ajax.Updater('flashcontent', '../processors/get_piegraph_processor.php', {asynchronous:true, onSuccess: new Effect.Appear('flashcontent',{duration:1}),onFailure: new showWaitWheel('flashcontent'),evalScripts:true } );
			
			
	}
	

///-----Side Scroller-------------
  
function MoveLeft() {
	
       var page=$("Page").value;	
       var maxPage=$("MaxPage").value;
	
       if(page > 1){

              new Effect.MoveBy('scroll_area', 0, 450, {duration: 0.4, transition: Effect.Transitions.sinoidal, queue: 'end'});
              $("Page").value--;  
              
              if($('campaign_type_code').value == 5 && $("Page").value == 2){
              
                     new Effect.SlideDown("broadcast_options");
                     
              }
              else if($('campaign_type_code').value == 5 && $("Page").value == 1){
              
                     new Effect.Fade("broadcast_options", {duration:0.2})
              
              }
                                                  
       }    
  
}

function MoveRight() {

       var page=$("Page").value;	
       var maxPage=$("MaxPage").value;
	
       if(page < maxPage){

              if($('campaign_type_code').value == 4 && $("Page").value == 2){
              
                     if($('keyword').value == '')alert('Please fill in the keyword!');
                     
                     else if($('keyword').value != '' && $('keyword_uniqueness').value == 'false')alert('Note that the keyword '+ $('keyword').value +' is not available, do choose something else!');                                   
              
                     else {
                     
                            new Effect.MoveBy('scroll_area', 0, -450, {duration: 0.4, transition: Effect.Transitions.sinoidal, queue: 'end'});
                            $("Page").value++;                     
                     
                     }
                     
              }
              else{

                     new Effect.MoveBy('scroll_area', 0, -450, {duration: 0.4, transition: Effect.Transitions.sinoidal, queue: 'end'});
                     $("Page").value++;   
              
                     if($('campaign_type_code').value == 5 && $("Page").value == 2){
              
                            new Effect.SlideDown("broadcast_options");
                     
                     }
                     else if($('campaign_type_code').value == 5 && $("Page").value == 3){
              
                            new Effect.Fade("broadcast_options", {duration:0.2})
              
                     }
                                  
              }                
       
       }       	
  
}
//---------------------------------


function togglePullCampaign() { //sets broadcast related pages to not appear, set keyword page to appear
   
   
	if (document.getElementById("PullCampaign").value=="false") { //initially not set
			
			//alert("Creating Pull Campaign");
			document.getElementById("PullCampaign").value="true";
			document.getElementById("campaign_sms_main_message").style.display="none";
			document.getElementById("campaign_sms_recepients").style.display="none";
			
			//set broadcast_required to 1
			document.getElementById("ca_bcast_required").value="0"; 
			
			//set keyword page display to display
			//document.getElementById("campaign_keyword").style.display="";
						
			var maxPage=document.getElementById("MaxPage");
			maxPage.value=maxPage.value-2;
	}
	
	else if (document.getElementById("PullCampaign").value=="true")	{ //toggle back to Push Campaign , 
			
			//alert("Creating Push Campaign");
			document.getElementById("PullCampaign").value="false";
			document.getElementById("campaign_sms_main_message").style.display="";
			document.getElementById("campaign_sms_recepients").style.display="";
			
			//set broadcast_required to 0
			document.getElementById("ca_bcast_required").value="1"; 
			//alert (document.getElementById("ca_bcast_required").value);
						
			var maxPage=document.getElementById("MaxPage");
			maxPage.value=maxPage.value+1; //!!max page value has a problem here!
	}
}

function togglePullCampaignContest() { //for contest only, due to its keyword nature
   
   
	if (document.getElementById("PullCampaign").value=="false") { //initially not set
			
			//alert("Creating Pull Contest Campaign");
			document.getElementById("PullCampaign").value="true";
			document.getElementById("campaign_sms_main_message").style.display="none";
			document.getElementById("campaign_sms_recepients").style.display="none";
			
			//set broadcast_required to 1
			document.getElementById("ca_bcast_required").value="1"; 
			
			//set keyword page display to display
			document.getElementById("campaign_keyword").style.display="";
						
			var maxPage=document.getElementById("MaxPage");
			maxPage.value=maxPage.value-1;
	}
	
	else if (document.getElementById("PullCampaign").value=="true")	{ //toggle back to Push Campaign , 
			
			//alert("Creating Push Campaign");
			document.getElementById("PullCampaign").value="false";
			document.getElementById("campaign_sms_main_message").style.display="";
			document.getElementById("campaign_sms_recepients").style.display="";
			
			//set broadcast_required to 0
			document.getElementById("ca_bcast_required").value="0"; 
			
			//set keyword page display to none
			document.getElementById("campaign_keyword").style.display="none";
			
						
			var maxPage=document.getElementById("MaxPage");
			maxPage.value=maxPage.value+1; //!!max page value has a problem here!
	}
}



//---------------------------------
//Contest Campaign

function  setContestSubtype() {

		var maxPage=document.getElementById("MaxPage");
			    
		var subtype=document.getElementById("contest_type").selectedIndex;
		//alert ("Subtype is"+subtype);
		
		switch (subtype) {
		
			case 1: //
				showallContestSubtype();
				//document.getElementById("campaign_contest_options2").style.display="none";
				document.getElementById("campaign_contest_options3").style.display="none";
				document.getElementById("campaign_auto_respond_2").style.display="none";
				
			    maxPage.value=maxPage.value-2;
				
				break;
				
			case 2:
				showallContestSubtype();
				document.getElementById("campaign_contest_options3").style.display="none";
				document.getElementById("campaign_auto_respond_3").style.display="none";
				
			    maxPage.value=maxPage.value-2;
							    
			    break;
				
			case 3:
			    showallContestSubtype();
				//document.getElementById("campaign_contest_options2").style.display="none";
				document.getElementById("campaign_auto_respond_2").style.display="none";
				
				maxPage.value=maxPage.value-1;
				
				
				break;
				
			case 4:
				//do nothing! All options in!
				showallContestSubtype();
				break;
		
		}


}


function  showallContestSubtype() {

			document.getElementById("campaign_contest_options2").style.display="";
			document.getElementById("campaign_contest_options3").style.display="";
			document.getElementById("campaign_auto_respond_2").style.display="";
			document.getElementById("campaign_auto_respond_3").style.display="";
			
}

function  addContestAnswer() {

		var contest_correct_answers_qty=document.getElementById("contest_correct_answers_qty");	
		
		
		if  (document.getElementById("contest_correct_answer2").style.display=="none") {
				document.getElementById("contest_correct_answer2").style.display="";
				
				var val = parseInt(contest_correct_answers_qty.value) + 1;
    			contest_correct_answers_qty.value = val;
    			
				return;
		}
		
		else if  (document.getElementById("contest_correct_answer3").style.display=="none"){
				document.getElementById("contest_correct_answer3").style.display="";
				
				var val = parseInt(contest_correct_answers_qty.value) + 1;
    			contest_correct_answers_qty.value = val;
    			
				return;
		}
		else if  (document.getElementById("contest_correct_answer4").style.display=="none"){
				document.getElementById("contest_correct_answer4").style.display="";
				
				var val = parseInt(contest_correct_answers_qty.value) + 1;
    			contest_correct_answers_qty.value = val;
    			
				return;
		}
		else if  (document.getElementById("contest_correct_answer5").style.display=="none"){
				document.getElementById("contest_correct_answer5").style.display="";
				
				var val = parseInt(contest_correct_answers_qty.value) + 1;
    			contest_correct_answers_qty.value = val;
    			
				return;
		}
		
			
}

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

//Vote Campaign

function  addVoteChoice() { //vote_choice_qty

		var vote_choice_qty=document.getElementById("vote_choice_qty");	
		
		
		if  (document.getElementById("choiceB").style.display=="none") {
				document.getElementById("choiceB").style.display="";
				
				var val = parseInt(vote_choice_qty.value) + 1;
    			vote_choice_qty.value = val;
    			
				return;
		}
		
		else if  (document.getElementById("choiceC").style.display=="none"){
				document.getElementById("choiceC").style.display="";
				
				var val = parseInt(vote_choice_qty.value) + 1;
    			vote_choice_qty.value = val;
    		
				return;
		}
		else if  (document.getElementById("choiceD").style.display=="none"){
				document.getElementById("choiceD").style.display="";
								
				var val = parseInt(vote_choice_qty.value) + 1;
    			vote_choice_qty.value = val;
    			
				return;
		}
		else if  (document.getElementById("choiceE").style.display=="none"){
				document.getElementById("choiceE").style.display="";
				
				var val = parseInt(vote_choice_qty.value) + 1;
    			vote_choice_qty.value = val;
    			
				return;
		}
		
			
}

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

//Survey Campaign

function  addSurveyQuestion() {

		var survey_questions_qty=document.getElementById("survey_questions_qty");	
		
		
		if  (document.getElementById("SurveyQuestion2").style.display=="none") {
				document.getElementById("SurveyQuestion2").style.display="";
				
				var val = parseInt(survey_questions_qty.value) + 1;
    			survey_questions_qty.value = val;
    			//alert(quiz_questions_qty.value);
				
				return;
		}
		
		else if  (document.getElementById("SurveyQuestion3").style.display=="none"){
				document.getElementById("SurveyQuestion3").style.display="";
				
				var val = parseInt(survey_questions_qty.value) + 1;
    			survey_questions_qty.value = val;
			
				
				return;
		}
		else if  (document.getElementById("SurveyQuestion4").style.display=="none"){
				document.getElementById("SurveyQuestion4").style.display="";
				
				var val = parseInt(survey_questions_qty.value) + 1;
    			survey_questions_qty.value = val;
				
				return;
		}
		else if  (document.getElementById("SurveyQuestion5").style.display=="none"){
				document.getElementById("SurveyQuestion5").style.display="";
				
				var val = parseInt(survey_questions_qty.value) + 1;
    			survey_questions_qty.value = val;
				//alert(quiz_questions_qty.value);
				
				return;
		}
		
}

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

//Quiz Campaign

function  addQuizQuestion() {

		var quiz_questions_qty=document.getElementById("quiz_questions_qty");	
		
		
		if  (document.getElementById("QuizQuestion2").style.display=="none") {
				document.getElementById("QuizQuestion2").style.display="";
				
				var val = parseInt(quiz_questions_qty.value) + 1;
    			quiz_questions_qty.value = val;
    			//alert(quiz_questions_qty.value);
				
				return;
		}
		
		else if  (document.getElementById("QuizQuestion3").style.display=="none"){
				document.getElementById("QuizQuestion3").style.display="";
				
				var val = parseInt(quiz_questions_qty.value) + 1;
    			quiz_questions_qty.value = val;
			
				
				return;
		}
		else if  (document.getElementById("QuizQuestion4").style.display=="none"){
				document.getElementById("QuizQuestion4").style.display="";
				
				var val = parseInt(quiz_questions_qty.value) + 1;
    			quiz_questions_qty.value = val;
				
				return;
		}
		else if  (document.getElementById("QuizQuestion5").style.display=="none"){
				document.getElementById("QuizQuestion5").style.display="";
				
				var val = parseInt(quiz_questions_qty.value) + 1;
    			quiz_questions_qty.value = val;
				//alert(quiz_questions_qty.value);
				
				return;
		}
		
}


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

function 	prefill_messageContent(){ //

		
		var keyword=document.campaign_sms.keyword.value;
		var message_body="";

		if (document.campaign_sms.campaign_type.value=="contest") { 
				
				var winnerQty=document.campaign_sms.winner_qty.value;
				var contest_duration=document.campaign_sms.contest_duration.value;

				
				switch (document.campaign_sms.contest_type.value) {
				
				
						case "0":	
								message_body="This is a SMS Contest! Be the first "+winnerQty+ " to reply with ["+keyword+"] to win";
								break;
							
						case "1":
								message_body="This is a SMS Contest! Be the first "+winnerQty+ " to reply with ["+keyword+"] within "+contest_duration+" hours to win";
								break;
							
						case "2":
								message_body="This is a SMS Contest! {Place your Question here} Be the first "+winnerQty+ " to reply with ["+keyword+"] <Answer>] to win";
								break;
							
						case "3":
								message_body="This is a SMS Contest! {Place your Question here} Be the first "+winnerQty+ " to reply with ["+keyword+" <Answer>] within "+contest_duration+" hours to win";
								break;
				
				}
				
				//Be the first 11 to reply with 'wwww {Your Answer}' within {h} hours to win
				
				//alert("Contest!");
				document.campaign_sms.ca_sms_messagebody.value=message_body;
		
		}
		
		else if (document.campaign_sms.campaign_type.value=="quiz") {
				
				//alert("Quiz!");
				document.campaign_sms.ca_sms_messagebody.value="This is a SMS Quiz! \nReply ["+keyword+"] to begin the quiz";
		
		}
		
		else if (document.campaign_sms.campaign_type.value=="vote") {
				
				//alert("Vote!");
				
				var choiceA=document.campaign_sms.choiceA.value;
				var choiceB=document.campaign_sms.choiceB.value;
				var choiceC=document.campaign_sms.choiceC.value;
				var choiceD=document.campaign_sms.choiceD.value;
				var choiceE=document.campaign_sms.choiceE.value;
				
				switch (document.campaign_sms.vote_choice_qty.value) {
				
							
						case "1":
								message_body="To vote: reply ["+keyword+" a] for "+choiceA;
								break;
							
						case "2":
								message_body="To vote: reply ["+keyword+" a] for "+choiceA+" , ["+keyword+" b] for "+choiceB  ;
								break;
							
						case "3":
								message_body="To vote: reply ["+keyword+" a] for "+choiceA+" , ["+keyword+" b] for "+choiceB+" , ["+keyword+" c] for "+choiceC;
								break;
								
						case "4":
								message_body="To vote: reply ["+keyword+" a] for "+choiceA+" , ["+keyword+" b] for "+choiceB+" , ["+keyword+" c] for "+choiceC+" , ["+keyword+" d] for "+choiceD;
								break;
								
						case "5":
								message_body="To vote: reply ["+keyword+" a] for "+choiceA+" , ["+keyword+" b] for "+choiceB+" , ["+keyword+" c] for "+choiceC+" , ["+keyword+" d] for "+choiceD+" , ["+keyword+" e] for "+choiceE;								
								
								break;
				
				}
				
				
				document.campaign_sms.ca_sms_messagebody.value=message_body;
		
		}


		else if (document.campaign_sms.campaign_type.value=="survey") {
				
				//alert("Contest!");
				document.campaign_sms.ca_sms_messagebody.value="This is a SMS Survey! \nReply ["+keyword+"] to begin the survey";
		
		}
		
		
		textCounter(document.campaign_sms.ca_sms_optout,document.campaign_sms.ca_sms_messagebody, document.campaign_sms.charcount,document.campaign_sms.maxcharcount.value);

}

function submitButton_queryall(){

	var msisdn=document.getElementById("msisdn").value;
	
	
	var theone
	for (i=0;i<document.queryall.gateway.length;i++){
		
		if (document.queryall.gateway[i].checked==true){
			theone=i
			break //exist for loop, as target acquired.
		}
		
	}
	
	var gateway=document.queryall.gateway[theone].value;
	//alert("Selection is"+gateway);
	//var gateway="gw3";
	
		
	updater("queryall", "queryall_processor.php?msisdn="+msisdn+"&gateway="+gateway, "queryall");
	
}
