// Digital Lines Ltd - Jscript Tool Pack V1.00

//  My Account - Login Functions.
//  CommPHP_Routed(url, parameters,PostCalledFunction)

//  Check Login Status
function MyAccLogin(OutputId,FormUser,FormPass)
 {
  var UserName = document.getElementById(FormUser).value;
  var UserPass = document.getElementById(FormPass).value;
  PopPage(OutputId,'innerHTML','');	   
  if (UserName!='' && UserPass!='') {

        try
          {
		  document.getElementById(OutputId).innerHTML = "Logging in, please wait ...";	  
		  var PostCalledFunction = 'CommPHPCheckWPCLogin("'+OutputId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/login?username='+UserName+'&password='+UserPass,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(OutputId).innerHTML = "Sorry, there has been an error logging in, please try again.";
		  return;
          };
    }
    else
    { document.getElementById(OutputId).innerHTML = "Please enter both your username and password?" ; };
	
	
 };
 

 
//  Check Login Status
// CommPHP_Routed FunctionRouter for redirecting From Login Check function Above
   function CommPHPCheckWPCLogin(OutputID,TXResponse) {
	 TXResponse = unescape(TXResponse);

	 if (   TXResponse == "INVALID" ) {
		 PopPage(OutputID,'innerHTML','Sorry, Invalid Username or Password, please try again?');
		 return};
	 
     if (   TXResponse.length >= 10 && TXResponse.substr(TXResponse.length-1,1) == "]"  ) {
	  TXResponse = TXResponse.replace("[", "");
	  TXResponse = TXResponse.replace("]", "");										
      PopPage(OutputID,'innerHTML','Login Ok: Opening the Prank Control Panel, Please wait ...');
      setCookie("wsid",TXResponse,30);
      setCookie("menver","www",30);
	  window.open('/my-account/my-acc-control-panel.php','_self'); }	  
	 else {
      PopPage(OutputID,'innerHTML','Sorry, there has been an unknown error, please try again?'); 
	 };
   };
  
 
 
 
//  New User SignUp
function MyAccSignup(OutputId,FormNewUser,FormNewPass,FormNewEmail,FormNewFbee)
 {
  var NewUserName  = document.getElementById(FormNewUser).value;
  var NewUserPass  = document.getElementById(FormNewPass).value;
  var NewUserEmail = document.getElementById(FormNewEmail).value;
  var NewUserFBee = document.getElementById(FormNewFbee).value;
  
  PopPage(OutputId,'innerHTML','');	   
  if (NewUserName!='' && NewUserPass!='' && NewUserEmail!='' && CheckEmail(NewUserEmail)) {

        try
          {
		  var PostCalledFunction = 'CommPHPCheckWPCSignup("'+OutputId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/pb_/wacky/myaccount/signup_check?uname='+NewUserName+'&upass='+NewUserPass+'&uemail='+NewUserEmail+'&fbee='+NewUserFBee,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(OutputId).innerHTML = "Sorry, there has been an error with your signup, please try again."
          };
    }
    else
    { 
      if (NewUserEmail!="" || !CheckEmail(NewUserEmail)) {document.getElementById(OutputId).innerHTML = "Please enter a valid email address?";  return;};
	  var ErrResp = "Please enter your";
	  if (NewUserName =='') { ErrResp+=", Username" ; };
	  if (NewUserPass =='') { ErrResp+=", Password" ; };
	  if (NewUserEmail=='') { ErrResp+=", Email Address" ; };
	  ErrResp+=".";
	  document.getElementById(OutputId).innerHTML = ErrResp;
	};
 };
 
 
//  Check SignUpStatus Status
// CommPHP_Routed FunctionRouter for redirecting From SignUp Check function Above
   function CommPHPCheckWPCSignup(OutputId,TXResponse) {
	 TXResponse = unescape(TXResponse);
	 
     if (TXResponse.length == 15 ) {
      
	  setCookie("wsid",TXResponse,30);
      setCookie("menver","www",30);
	  window.open('/my-account/my-acc-topup-new.php?wsid='+TXResponse,'_self');
	  return; }
	 
	 if (TXResponse == "1" ) {
	  PopPage(OutputId,'innerHTML','Sorry, this Username has been taken, please try another?'); }
	 else {
      PopPage(OutputId,'innerHTML','Sorry, there was an error with your SignUp, please try again?'); 
	 };
   };
 
 
 
 
 
//  Control panel - Add Prank to Schedule

function CPanelAddToSched(MsgOutputId,CPSchedRowId,CPSchedWCodeId,CPSchedVictId,CPSchedDateId,CPSchedVNameId,CPSchedVGendId)
 {
  var CPSchedWCode  = document.getElementById(CPSchedWCodeId).value;
  var CPSchedVictim = document.getElementById(CPSchedVictId).value;
  var CPSchedVName  = document.getElementById(CPSchedVNameId).value;
  var CPSchedVGend  = document.getElementById(CPSchedVGendId).value;
  var CPSchedDateTimeString = document.getElementById(CPSchedDateId).value;
  
  if (CPSchedWCode!='' && CPSchedVictim!='' && CPSchedDateTimeString!='') {

       // Test for valid phone number
		if (CPSchedVictim.length <=9 || CPSchedVictim != parseFloat(CPSchedVictim)) {
			PopPage(MsgOutputId,'innerHTML','Invalid phone number.')
			return;};
			
		// Test for valid Date Time	
	    var CPSchedDateTimeArr = new Array();
		CPSchedDateTimeArr = CPSchedDateTimeString.split(" ",2);
		var CPSchedDate = CPSchedDateTimeArr[0];
		var CPSchedTime = CPSchedDateTimeArr[1]; 
			
	    var CPSchedDateArr = new Array();			
		CPSchedDateArr = CPSchedDate.split("-",3);
		var CPSchedDay = CPSchedDateArr[0];
		var CPSchedMon = CPSchedDateArr[1];
		var CPSchedYr = CPSchedDateArr[2];
			
	    var CPSchedTimeArr = new Array();
		CPSchedTimeArr = CPSchedTime.split(":",2);
		var CPSchedHrs = CPSchedTimeArr[0];
		var CPSchedMin = CPSchedTimeArr[1];			
 
		//var CPSchedTSMilli = Date.parse("May 27 2008 09:12");
		var CPSchedTSMilli = Date.parse( CPSchedMon+" "+CPSchedDay+", "+CPSchedYr+" "+CPSchedHrs+":"+CPSchedMin );
		var CurrentTSMilli = Date.parse( Date() );

		if ( CPSchedTSMilli <= CurrentTSMilli )
		{	
			PopPage(MsgOutputId,'innerHTML','The Date &amp; time needs to be at least 1 minute in the future.' )
			return;};	
		
        try
          {
		  PopPage(MsgOutputId,'innerHTML','Adding prank to the Schedule ...');	  
		  var PostCalledFunction = 'CPanelAddToSchedResponse("'+MsgOutputId+'","'+CPSchedRowId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/&$'+WSessionId+'&$/myaccount/my-acc-cpanel-sched-add?wcode='+CPSchedWCode+'&ip='+YourIPAddr+'&wvict='+CPSchedVictim+'&wdate='+CPSchedDateTimeString+'&wname='+CPSchedVName+'&wgend='+CPSchedVGend,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been a problem, please try again."
          };
		  
    }
    else
    { 
      if (CPSchedVictim=="" ) {document.getElementById(MsgOutputId).innerHTML = "Please enter your 'Victims' phone number!";  return;};
      if (CPSchedDateTime=="" ) {document.getElementById(MsgOutputId).innerHTML = "Please enter the Date &amp; Time to play the prank?";  return;};	  
	};
 };
 



// Check Response from CPanelAddToSched
// CommPHP_Routed FunctionRouter for redirecting From Login Check function Above
   function CPanelAddToSchedResponse(OutputId,CPSchedRowId,TXResponse) {
	 TXResponse = unescape(TXResponse);
	 
     if (TXResponse == 'GOOD' ) {
      //PopPage(CPSchedRowId,'innerHTML','');
	  CPanelRefreshSched('cpanel_sched_msg','cpanel_schedule_output');
	  PopPage(OutputId,'innerHTML','Prank Call has been added to the Schedule.');
	  return;
	  }
	  else {
	  PopPage(OutputId,'innerHTML',TXResponse);
	 };
   };
   


// Change Country code input

   function CPanelCountrySelect(OutputId,CPSchedRowId,TXResponse) {

			/*
				echo '<div id="cpanel_tnum_uk_ccode">';	
				echo '<input name="vic_num'.$PCount.'" type="text" class="recordings" id="vic_num'.$PCount.'" size="18" maxlength="16"/>';
				echo '</div>';	
				echo '<div style="display:none" id="cpanel_tnum_int_ccode">';	
				echo '<input name="vic_num'.$PCount.'" type="text" class="recordings" id="vic_num'.$PCount.'" size="4" maxlength="3"/>';
				echo '<input name="vic_num'.$PCount.'" type="text" class="recordings" id="vic_num'.$PCount.'" size="14" maxlength="16"/>';	
				echo '</div>';		
			*/
			
			var CCodeCurrStatus = document.getElementById('cpanel_tnum_ccode_status').value;
			
			if (CCodeCurrStatus=="uk") {
				document.getElementById('cpanel_tnum_uk_ccode').style.display = "none";
				document.getElementById('cpanel_tnum_ccode_status').value = "int";
				document.getElementById('cpanel_tnum_int_ccode').style.display="block";
			};
			
			if (CCodeCurrStatus=="int") {
				document.getElementById('cpanel_tnum_int_ccode').style.display="none";
				document.getElementById('cpanel_tnum_ccode_status').value = "uk";
				document.getElementById('cpanel_tnum_uk_ccode').style.display="block";
			};

 };



//  Control panel - Refresh Schedule data & update screen

function CPanelRefreshSched(MsgOutputId,ShedOutputId)
 {
        try
          {

		  PopPage(MsgOutputId,'innerHTML','Refreshing, Please wait ...');
		  var PostCalledFunction = 'CPanelRefreshSchedResponse("'+MsgOutputId+'","'+ShedOutputId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/my-account/my-acc-sched-refresh.php', '?r=y',PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there was a problem, please try again?"
          };
 };
 
 
 //  Check Response from CPanelAddToSched
// CommPHP_Routed Function Router for updating the screen after the scedule refresh
   function CPanelRefreshSchedResponse(OutputId,ShedOutputId,TXResponse) {
	 TXResponse = unescape(TXResponse);
     PopPage(ShedOutputId,'innerHTML',TXResponse);
	 PopPage(OutputId,'innerHTML','&nbsp;');
	 //Update Credits
	 PopPage('pcredits','innerHTML', document.getElementById('curr_cred').value );
   };
   
   

 
//  Control panel - Outbound Scheduler Actions

function CPanelSchedActions(MsgOutputId,SchedId,SchedRowId,VictTnumId,SchedRowCallStatusId,ActionCodeId)
 {
	 
//	 Get Schedule Action code
	var ActionCode = document.getElementById(ActionCodeId).value;
	 
	switch (ActionCode)
	{
	case "resched":
	   // Re-Schedule Prank Call
	   try
          {
		  document.getElementById(MsgOutputId).innerHTML = "Rescheduling prank, Please wait ...";	  
		  var PostCalledFunction = 'CPanelSchedActionsResponse("'+MsgOutputId+'","'+ActionCode+'","'+SchedRowId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/&$'+WSessionId+'&$/myaccount/my-acc-cpanel-sched-resched?schedid='+SchedId,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been a problem rescheduling, please try again."
          };
	  break;
	case "retrynow":
	   try
          {
		  document.getElementById(MsgOutputId).innerHTML = "Updating, Please wait ...";	  
		  var PostCalledFunction = 'CPanelSchedActionsResponse("'+MsgOutputId+'","'+ActionCode+'","'+SchedRowCallStatusId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/&$'+WSessionId+'&$/myaccount/my-acc-cpanel-sched-retrynow?schedid='+SchedId,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been a problem rescheduling, please try again."
          };
	  break;
	case "playnow":
	   var TnumVict = document.getElementById(VictTnumId).innerHTML;
	   window.open('/my-pranks/my-pranks-search.php?vict='+TnumVict+'&tnum='+WU,'_blank');	  
	  break;
	case "deleteprank":
	   try
          {
		  document.getElementById(MsgOutputId).innerHTML = "Deleting, Please wait ...";	  
		  var PostCalledFunction = 'CPanelSchedActionsResponse("'+MsgOutputId+'","'+ActionCode+'","'+SchedRowId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/&$'+WSessionId+'&$/myaccount/my-acc-cpanel-sched-delete?schedid='+SchedId,PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been a problem deleting, please try again."
          };
	  break;
	case "topup":
	   window.open('my-acc-topup.php','_self');
	  break;
	default:
	  document.getElementById(MsgOutputId).innerHTML = "."
	}
	 
	 
	
 };
 
 
 //  Check Response from CPanelSchedActions
// CommPHP_Routed Function Router for updating the screen after the schedule actions
   function CPanelSchedActionsResponse(OutputId,ActionCode,SchedRowId,TXResponse) {
	 TXResponse = unescape(TXResponse);

	 if (TXResponse=="GOOD") {

	   
			switch (ActionCode)
			{
			case "resched":
			  // Re-Schedule Prank Call / Using Schedule refresh function
			  CPanelRefreshSched('cpanel_sched_msg','cpanel_schedule_output');
			  break;
			case "retrynow":
			  // Updating Schedule for new Prank Call
			  CPanelRefreshSched('cpanel_sched_msg','cpanel_schedule_output');
		      PopPage(SchedRowId,'innerHTML','Queued');
		      PopPage(OutputId,'innerHTML','&nbsp;');
			  
			  break;
			case "playnow":
			  // Play recorded prank - See above funtion
			  break;
			case "deleteprank":
			  // Delete Prank Call from Schedule / Using Schedule refresh function
			  CPanelRefreshSched('cpanel_sched_msg','cpanel_schedule_output');
		      PopPage(SchedRowId,'innerHTML','');
		      PopPage(OutputId,'innerHTML','&nbsp;');
			  break;
			case "topup":
			  // Redirect To Top Up pages - See above funtion
			  break;
			default:
			  PopPage(OutputId,'innerHTML','Sorry, There was an error, please try again?');
			}	   
	 }
	 else {
		 PopPage(OutputId,'innerHTML','Sorry, There was an error, please try again?');
	 };
	   

   };




//  Control panel - Begin PayPal Status Session

function PayPalCreate(MsgOutputId,FormId,ItemId,CustFeildId)
 {
		 // SetUp session request
         try
          {
		  document.getElementById(MsgOutputId).innerHTML = "Thank you, redirecting you to PayPal, Please wait ...";	  
		  var PostCalledFunction = 'PayPalCreateResponse("'+MsgOutputId+'","'+FormId+'","'+ItemId+'","'+CustFeildId+'","TX_RESPONSE_PLACEHOLDER");';
		  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/&$'+WSessionId+'&$/paypal/paypal-setup?service=wacky',PostCalledFunction );
          }
        catch(err)
          {
          document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been problem, please try again?"
          };
return;
 };
 

 //  PayPal Response 
   function PayPalCreateResponse(OutputId,FormId,ItemId,CustFeildId,TXResponse) {

	 TXResponse = unescape(TXResponse);

	 if (TXResponse.substring(0,5) == "tsid=") {
	    //PopPage(OutputId,'innerHTML','');
		var TSID = TXResponse.replace(/tsid=/,"");
		setCookie('tsid',TSID,1);
		document.getElementById(CustFeildId).value=TXResponse;   
		document.getElementById(FormId).action="https://www.paypal.com/cgi-bin/webscr";        
		document.getElementById(FormId).submit();	
		}
	 else {
		PopPage(OutputId,'innerHTML','Sorry, there was a problem, please try again?'); 
		return;
	 };

return;	 
   };
   
   
//  PWRecov

function PWRecov(MsgOutputId,FormEmailId)
 {
    // Check for valid email
	var EmailAddress  = document.getElementById(FormEmailId).value;

	if ( EmailAddress!='' && CheckEmail(EmailAddress) ) {		 
			 try
			  {
			  document.getElementById(MsgOutputId).innerHTML = "Sending, Please wait ...";	  
			  var PostCalledFunction = 'PWRecovResponse("'+MsgOutputId+'","TX_RESPONSE_PLACEHOLDER");';
			  CommPHP_Routed('/php/scripts/TPackCommCore.php', '?url=http://inet.wackyprankcalls.com:6670/pb_/wacky/pwrecov/pwrecov?rec_email='+EmailAddress,PostCalledFunction );
			  }
			catch(err)
			  {
			  document.getElementById(MsgOutputId).innerHTML = "Sorry, there has been problem, please try again?"
			  //return;
			  };
	} else {
		PopPage(MsgOutputId,'innerHTML','Invalid email, please try again?');
		return; }
 };
 

 //  Check Response from PWRecov
function PWRecovResponse(OutputId,TXResponse) {
	 TXResponse = unescape(TXResponse);

if (TXResponse=="GOOD") {
	    PopPage(OutputId,'innerHTML','Your password has been sent to you. Click <a href="../my-account.php">HERE</a> for the login page.');
		}
	 else {
		PopPage(OutputId,'innerHTML','Sorry, there was a problem, please try again?'); 
		return;
	 };

return;	 
   };
   
   
   