function quickrecharge(base_url)
{
    if($F('mobno') == '')
    {
        alert('Enter Mobile No');
    }
    else if($F('amount') == '')
    {
        alert('Please Enter Amount');
    }
    else
    {
	var opt = {
                method:'post', 
                postBody:'m=update&mobno=' + $F('mobno') + '&amt=' + $F('amount'), 
                onSuccess: function(t) { $('recharge_button').value = "Redirecting..."; handle_recharge(t, base_url)},
                onLoading: function() { $('recharge_button').value = "Processing..."; }
                }
                new Ajax.Request(base_url + 'recharge/insertSessionData/', opt);
    }
}

function handle_recharge(t,base_url)
{     
    var data = t.responseText.split("|");               
    if(data[0] == 1)
    {
        self.location = base_url + 'recharge/confirmation'  + '/';
    }
    else
    {
        /** Error Handling */       
    }
}

function confirm(base_url)
{
    if($F('name') == '')
    {
        alert('Please Enter Your Name');
    }
    else if($F('email') == '')
    {
        alert('Please Enter Your Email Address');
    }
    else if($F('passkey') == '')
    {
        alert('Please Check your Verification Key. For any issues in Verification Key, Contact us at support@cellbharat.com');
    }
    else
    {
	    var opt = {
                method:'post', 
                postBody:'m=update&pass=' + $F('passkey') + '&name=' + $F('name') + '&email=' + $F('email') + '&mob=' + $F('mobNo') + '&serviceProvider=' + $F('serviceProvider') + '&circle=' + $F('circle') + '&sp=' + $F('sp') + '&cir=' + $F('cir'), 
                onSuccess: function(t) { $('conform_button').value = "Redirecting..."; handle_confirm(t,base_url)},
                onLoading: function() { $('conform_button').value = "Confirming..."; } 
                }
                new Ajax.Request(base_url + 'recharge/verifyData/', opt);
    }
}

function bypassconfirmation(base_url)
{
    if($F('name') == '')
    {
        alert('Please Enter Your Name');
    }
    else if($F('email') == '')
    {
        alert('Please Enter Your Email Address');
    }
    else
    {
        var opt = {
                method:'post', 
                postBody:'m=update&pass=bypass' + '&name=' + $F('name') + '&email=' + $F('email') + '&mob=' + $F('mobNo') + '&serviceProvider=' + $F('serviceProvider') + '&circle=' + $F('circle') + '&sp=' + $F('sp') + '&cir=' + $F('cir'), 
                onSuccess: function(t) { $('conform_button').value = "Redirecting..."; handle_confirm(t,base_url)},
                onLoading: function() { $('conform_button').value = "Confirming..."; } 
                }
                new Ajax.Request(base_url + 'recharge/verifyData/', opt);
    }
}

function handle_confirm(t,base_url)
{
    var data = t.responseText.split("|");
    if(data[0] == "0")
    {
	$('slide_message').innerHTML = '<strong><center><font color="red">'+ data[1] + '</font></center></strong>';
        //self.location = base_url + 'recharge/addressconfirmation'  + '/';
    }
    else
    {
	    document.frmTransaction.submit();
        //$('slide_message').innerHTML = '<strong><center><font color="green">'+ data[1] + '</font></center></strong>';
    }
}

function copyValue()
{
	$('ship_name').value = $F('name');
	$('ship_address').value = $F('address');
	$('ship_city').value = $F('city');
	$('ship_state').value = $F('state');
	$('ship_postal_code').value = $F('postal_code');
	$('ship_country').value = $F('country');
}

function mobileno()
{
	entry = $F('mobno')
	strlen=entry.length;
	var check = entry.substring(0,4);
	if(strlen == 10)
	{
        $('recharge_button').disabled=false;
        $('amount').disabled=false;
		var opt = {
                method:'post', 
                postBody:'m=update&mobcheck=' + check, 
                onSuccess: function(t) {handle_mobcheck(t)},
                onLoading: function() {}
                }
                new Ajax.Request('http://www.cellbharat.com/recharge/mobileValidation/', opt); // To be Fixed with base_url 
	}
	else
	{
		$('mobno_check').innerHTML = '<strong><font color="red">Pls. Enter only your 10 digit mobile number. Dont Prefix "0" or "+91"</font></strong>';
		$('recharge_button').disabled=true;
		$('amount').disabled=true;
	}
}

function handle_mobcheck(t)
{
    var data = t.responseText.split("|");
    if(data[0] == "0")
    {
	    $('mobno_check').innerHTML = '<div style="color: red; padding-top: 3px; font-weight: bold;">'+ data[1] + '</div>';
	    $('recharge_button').disabled=true;
	    $('amount').disabled=true;
    }
    else if(data[0] == "1")
    {
	    $('mobno_check').innerHTML = '<div style="color: red; padding-top: 3px; font-weight: bold;">'+ data[1] + '</div>';
	    $('recharge_button').disabled=true;
	    $('amount').disabled=true;
    }
    else
    {
	    $('mobno_check').innerHTML = '';
	    $('recharge_button').disabled=false;
	    $('amount').disabled=false;
    }
}

function amountCheck(field)
{
	$amount = $F(field)
    if (isNaN($amount))
    {        
        $(field + '_check').innerHTML = '<strong><font color="red">Please Enter the amount as an Integer. (Example: 100 or 501)</font></strong>';    
        $('recharge_button').disabled=true;                                                                                  
    }
	else if($amount >= 25 && $amount <= 2000)
	{
        $('recharge_button').disabled=false; 
		$(field + '_check').innerHTML = '';
	}
	else if($amount < 25)
	{
		$(field + '_check').innerHTML = '<strong><font color="red">Minimum Recharge Should be Rs. 25</font></strong>';
        $('recharge_button').disabled=true;
	}
    else if($amount > 2000)
    {
        $(field + '_check').innerHTML = '<strong><font color="red">Sorry, You cannot recharge for more than Rs. 2000 at single Instance</font></strong>';
        $('recharge_button').disabled=true;
    }
    
}

function changeServiceProvider()
{
	$('spchange').style.display = 'none';
	$('changesp').style.display = 'block';
}

function changeCircle()
{
	$('circlechange').style.display = 'none';
	$('changecircle').style.display = 'block';
}

function rechargeStatusLogin(base_url)
{
    if($F('mobno') == '')
    {
        alert('Enter Mobile Number');
    }
    else if($F('pass') == '')
    {
	alert("Enter Pass Key");
    }
    else
    {
	var opt = {
                method:'post', 
                postBody:'m=update&mob=' + $F('mobno') + '&pass=' + $F('pass'), 
                onSuccess: function(t) { $('rechargestatuslogin_button').value = "Redirecting..."; handle_rechargestatuslogin(t,base_url)},
                onLoading: function() { $('rechargestatuslogin_button').value = "Submiting..."; }
                }
                new Ajax.Request(base_url + 'recharge/VerifyLoginStatus/', opt);
    }
}

function handle_rechargestatuslogin(t,base_url)
{
    var data = t.responseText.split("|");
    if(data[0] == "0")
    {
	$('response').innerHTML = '<strong><center><font color="red">'+ data[1] + '</font></center></strong>';
        //self.location = base_url + 'recharge/addressconfirmation'  + '/';
    }
    else
    {
	    //document.frmTransaction.submit()
        //$('response').innerHTML = '<strong><center><font color="green">'+ data[1] + '</font></center></strong>';
	self.location = base_url + 'recharge/details'  + '/';
    }
}


function forgetActivationkey(base_url)
{
    if($F('mobno') == '')
    {
        alert("Please Enter Mobile No");
        return;
    }
    else
    {
        var opt = {
            method:'post', 
            postBody:'m=recharge&mobileNo=' + $F('mobno'),
            onSuccess: function(t) { check_send_activation_key(t) },
            onLoading: function() {  }
              }
            new Ajax.Request( base_url + 'recharge/forgetActivationKey/', opt);     
    }
}

function check_send_activation_key(t)
{
    var data = t.responseText.split("|");
    if(data[0] == "0")
    {
        $('slide_message').innerHTML = '<strong><center><font color="red">' + data[1] + '</font></center></strong>';
    }
    else
    {
        $('slide_message').innerHTML = '<strong><center><font color="green">'+ data[1] + '</font></center></strong>';
    }
    
}

function emailvalidation()
{
     var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (document.frmTransaction.email.value.search(emailRegEx) == -1) 
     {
          $('email_check').innerHTML = '<strong><font color="red">Invalid EMail. Pls. Check the format</font></strong>';  
          $('conform_button').disabled=true;  
     }
     else
     {                   
          $('email_check').innerHTML = "";
          $('conform_button').disabled=false;
     }
}


