/* IE6 flicker fix */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}
/* Make a working ie6 detection for jquery */
jQuery.browser.msie6 = jQuery.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

jQuery(document).ready(function() {
				 jQuery("div.banner_right").mouseover(function() {					 
					 jQuery(this).find("span img").attr('src', 'https://www.minicredit.co.uk/img/example5.jpg');
					}).mouseout(function(){ 					 
					 jQuery(this).find("span img").attr('src', 'https://www.minicredit.co.uk/img/example2.jpg');  
				 });
});

/* Tooltip actions. */
function showTooltip(ref,txt,opt){
	jQuery('body').append('<div id="tooltip"><div id="tooltip-ending"></div><div id="tooltip-inner">' + txt + '</div></div>');
	if(opt){ helper = opt; } else { helper = ref; }
	fit = jQuery(document).width() - jQuery(helper).offset().left - jQuery('#tooltip').width();
	jQuery('#tooltip')[0].style.top = jQuery(helper).offset().top + jQuery(helper).height() + 'px';
	if( fit < 0 ){
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + fit + 'px';	
		jQuery('#tooltip-ending')[0].style.backgroundPosition = fit - fit - (jQuery(document).width() - jQuery(ref).offset().left) + 'px 0';
	} else {
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + 'px';
	}
	jQuery(ref).bind('mouseout',function() {
		jQuery('#tooltip').unbind('mouseout');
		jQuery('#tooltip').remove();
	});
}

/* Tooltip actions. */
function showTooltip2(ref,txt,opt){
  sl = jQuery('#slider').offset().left + 33;	
	jQuery('body').append('<div id="tooltip"><div id="tooltip-ending"></div><div id="tooltip-inner" style="color:green;">' + txt + '</div></div>');
	if(opt){ helper = opt; } else { helper = ref; }
	fit = jQuery(document).width() - jQuery(helper).offset().left - jQuery('#tooltip').width();
	jQuery('#tooltip')[0].style.top = jQuery(helper).offset().top + 20 + 'px'; //+ jQuery(helper).height()
	if( fit < 0 ){
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + fit + 'px';	
		jQuery('#tooltip-ending')[0].style.backgroundPosition = fit - fit - (jQuery(document).width() - jQuery(ref).offset().left) + 'px 0';
	} else {
		//jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + 192 + 'px';
		jQuery('#tooltip')[0].style.left = sl + 'px';
	}
	jQuery(ref).bind('mouseout',function() {
		jQuery('#tooltip').unbind('mouseout');
		jQuery('#tooltip').remove();
	});
}

/* Tooltip actions. */
function showTooltip3(ref,txt,opt){
	jQuery('body').append('<div id="tooltip"><div id="tooltip-ending"></div><div id="tooltip-inner" style="color:green;">' + txt + '</div></div>');
	if(opt){ helper = opt; } else { helper = ref; }
	fit = jQuery(document).width() - jQuery(helper).offset().left - jQuery('#tooltip').width();
	jQuery('#tooltip')[0].style.top = jQuery(helper).offset().top + jQuery(helper).height() + 'px';
	if( fit < 0 ){
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + fit + 'px';	
		jQuery('#tooltip-ending')[0].style.backgroundPosition = fit - fit - (jQuery(document).width() - jQuery(ref).offset().left) + 'px 0';
	} else {
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + 'px';
	}
	jQuery(ref).bind('mouseout',function() {
		jQuery('#tooltip').unbind('mouseout');
		jQuery('#tooltip').remove();
	});
}

/* Tooltip actions. */
function showTooltip4(ref,txt,opt){
	jQuery('body').append('<div id="tooltip" style="width:500px;"><div id="tooltip-ending" style="width:523px;"></div><div id="tooltip-inner" style="color:green;width:500px;">' + txt + '</div></div>');
	if(opt){ helper = opt; } else { helper = ref; }
	fit = jQuery(document).width() - jQuery(helper).offset().left - jQuery('#tooltip').width();
	jQuery('#tooltip')[0].style.top = jQuery(helper).offset().top + jQuery(helper).height() + 'px';
	if( fit < 0 ){
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + fit + 'px';	
		jQuery('#tooltip-ending')[0].style.backgroundPosition = fit - fit - (jQuery(document).width() - jQuery(ref).offset().left) + 'px 0';
	} else {
		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + 'px';
	}
	jQuery(ref).bind('mouseout',function() {
		jQuery('#tooltip').unbind('mouseout');
		jQuery('#tooltip').remove();
	});
}

var placeFocusZ = 0;
var ok_txtZ = '<img src="img/ico_ok.gif" alt="" class="ico" />';
var error_beginZ = '<p class="error">';
var error_endZ = '</p>';
var cardRes = 1;

var exprZ = new Array();
var errorZ = new Array();

exprZ[1] = /^([a-zA-Z]+){2,}$/;
errorZ[1] = 'Please enter your first name';

exprZ[2] = /^([a-zA-Z]+){2,}$/;
errorZ[2] = 'Please enter your last name';

exprZ[3] = 'select';
errorZ[3] = 'Please select card type from list';

exprZ[4] = 'card';
errorZ[4] = 'Please enter valid card number';

exprZ[5] = /^([0-9]+){3,4}$/;
errorZ[5] = 'Please enter valid card security code';

exprZ[6] = 'date';
errorZ[6] = 'Please select card expiry date';

exprZ[27] = 'pcode';
errorZ[27] = 'Please enter postcode and press "Find Address"';

exprZ[28] = 'select';
errorZ[28] = 'Please select house/flat';

exprZ[30] = /^(.+)$/;
errorZ[30] = 'Please enter street';

exprZ[31] = /^(.+)$/;
errorZ[31] = 'Please enter town';

exprZ[32] = /^(.+)$/;
errorZ[32] = 'Please enter county';

exprZ[33] = 'pcode';
errorZ[33] = 'Please enter postcode';

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

function checkCashForm()
{
  var cashNumber = jQuery('#ukash_number').val();
	var cashValue = jQuery('#ukash_value').val();
	var cashAmount = jQuery('#ukash_amount').val();
	
	if(cashNumber > 0 && cashValue > 0 && cashAmount > 0)
	{
	  cashValue = str_replace(",", ".", cashValue);
		cashAmount = str_replace(",", ".", cashAmount);
		
		cashValue = parseFloat(cashValue);
		cashAmount = parseFloat(cashAmount);
		
		if(cashAmount > cashValue)
		{
		  alert('Amount cant be more than Voucher Value!');
		}
		else
		{
  		if (confirm('Are you sure?')) {	
  		 document.cashstep1F.submit();
  		}
		}	
	}
	else
	{
	  alert('All fields required!');
	}
}

function showAllCardDetails(typ)
{
  if(typ == 1)
	{
	  jQuery('#partly1').hide();
		jQuery('#partly2').show();
		jQuery('#payMode').val('2');				
	}
	else
	{
	  jQuery('#partly1').show();
		jQuery('#partly2').hide();
		jQuery('#payMode').val('1');
	}
	
	jQuery('#input_1').val('');
	jQuery('#input_xx').val('');	
	jQuery('#input_2').val('');
	jQuery('#input_3').val('--');
	jQuery('#input_4').val('');
	jQuery('#input_5').val('');
	jQuery('#input_6').val('--');
	jQuery('#input_6b').val('--');
	jQuery('#input_7').val('');
}

function checkPostAddressLogin() {
	var pcode = $("#input_27").val();
	if (pcode && checkPostCodeLogin(pcode)) {
		$.post("index.php?act=getBackAddressPay", {postcode : pcode}, function(data){
			if (data.length>0){
				if (data == 'error') {
					alert('Enter correct postcode');
				}
				else {
					postCodePressedZ = 1;
					$("#address").html(data);
					$('#tr_29').hide();
				}
			} 
		})
	}
	else {
		alert('Enter correct postcode!');
	}
}

function checkAddressLogin(sel) {
	if (sel.value == '--') {
		clearFieldsLogin();
	}
}

function clearFieldsLogin() {
	for (i = 30; i <= 35; i++) {
		input = $('#input_'+i);
		if (input) {
			input.val('');
		}
	}			 
}

function displIssueNumber()
{
  var card = $("#input_3").val();

	if(card == 'Solo' || card == 'Maestro')
	{
	  $('#tr_7').show();
	}
	else
	{
	  $('#tr_7').hide();
	}
}

function addErrorToTRLogin(entry) {
	tr = document.getElementById('tr_' + entry);
	if (tr) {
		$("#tr_"+entry).addClass('error');
	}
}

function showErrorMessageLogin(entry) {
	div = document.getElementById('error_'+entry)	
	if (div && errorZ[entry]) {
		$("#error_"+entry).html(error_beginZ + errorZ[entry] + error_endZ);
		addErrorToTRLogin(entry);
		if (placeFocusZ == 1) {
			placeFocusZ = 0;
			document.getElementById('input_' + entry).focus();
		}
	}
}

function removeErrorFromTRLogin(entry) {
	tr = document.getElementById('tr_' + entry);
	if (tr) {
		$("#tr_"+entry).removeClass('error');
	}
}

function showOkMessageLogin(entry) {
	div = document.getElementById('error_'+entry);
	if (div) {
		$("#error_"+entry).html(ok_txtZ);
		removeErrorFromTRLogin(entry);
	}
}

function controlAllFields()
{
  var err = 0;		
	
	input = document.getElementById('payMode');
	
	if(input.value == 1)
	{
	  document.step2F.submit();
	}		
	else
	{		
  	input = document.getElementById('input_1');
  	if(!exprZ[1].test(input.value))
  	{
  	  err = 1;
  		showErrorMessageLogin('1');
  	}
  	else
  	{
  	   showOkMessageLogin('1');
  	}
  	
  	
  	input = document.getElementById('input_2');
  	if(!exprZ[2].test(input.value))
  	{
  	  err = 1;
  		showErrorMessageLogin('2');
  	}
  	else
  	{
  	  showOkMessageLogin('2');
  	}
  	
  	input = document.getElementById('input_27');
  	
  	if(!checkPostCodeLogin(input.value))
  	{
  	  err = 1;
  		showErrorMessageLogin('27');
  	}
  	else
  	{	  
  		showOkMessageLogin('27');
  		
  		input = document.getElementById('input_28');				
  		if(input.value == '--')
  		{		 
  			err = 1;
  			showErrorMessageLogin('28');
  		}
  		else
  		{
  			showOkMessageLogin('28');
  		}
  		
  		input = document.getElementById('input_30');
  		if(!exprZ[30].test(input.value))
  		{
  		  err = 1;
  			showErrorMessageLogin('30');
  		}
  		else
  		{
  		  showOkMessageLogin('30');
  		}
  		
  		input = document.getElementById('input_31');
  		if(!exprZ[31].test(input.value))
  		{
  		  err = 1;
  			showErrorMessageLogin('31');
  		}
  		else
  		{
  		  showOkMessageLogin('31');
  		}
  		
  		input = document.getElementById('input_32');
  		if(!exprZ[32].test(input.value))
  		{
  		  err = 1;
  			showErrorMessageLogin('32');
  		}
  		else
  		{
  		  showOkMessageLogin('32');
  		}
  		
  		input = document.getElementById('input_33');
  		if(!checkPostCodeLogin(input.value))
  		{
  		  err = 1;
  			showErrorMessageLogin('33');
  		}
  		else
  		{
  		  showOkMessageLogin('33');
  		}
  	}
  	
  	input = document.getElementById('input_3');	
  	if(input.value == '--')
  	{
  	  err = 1;
  		showErrorMessageLogin('3');
  	}
  	else
  	{
  	  showOkMessageLogin('3');
  	}			
  	
  	input = document.getElementById('input_4');	
  	if(input.value != '')
  	{
  	  $.post("index.php?act=checkCard", {card : input.value}, function(data) {
  			if (data.length > 0 && data == 'VALID'){				
  				 showOkMessageLogin('4');
  			}
  			else {
  				err = 1;
  				showErrorMessageLogin('4');
  			}
  		});
  	}
  	else
  	{
  	  err = 1;
  		showErrorMessageLogin('4');
  	}	
  	
  	input = document.getElementById('input_5');
  	if(!exprZ[5].test(input.value))
  	{
  	  err = 1;
  		showErrorMessageLogin('5');
  	}
  	else
  	{
  	  showOkMessageLogin('5');
  	}
  	
  	if(!checkStepDateLogin())
  	{
  	  err = 1;
  		showErrorMessageLogin('6');
  	}
  	else
  	{
  	  showOkMessageLogin('6');
  	}
		
		if(err == 1)
		{
		  alert('All fields with * required!');
		}
		else
		{
		  document.step2F.submit();
		}
	}			
}

function checkStepDateLogin() 
{		
		var month = $('#input_6').val();
		var year = $('#input_6b').val();		
		
		if (month == '--' || year == '--') {
			return false;
		}
		else {
			year = parseInt(year);
			month = parseInt(month);
			var d = new Date();
			m = parseInt(d.getMonth()) + 1;
			m = month - m;
			y = parseInt(d.getFullYear());
			y = year - y;
			stamp = (y*12) + m;			
			if (stamp < 0) {
				alert('Old card, check expire date!');
				return false;
			}
		}	
	return true;
}


function checkPostCodeLogin (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

var sliderError = 0;

function makeMinus()
{
  checkSum();
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum - 10) >= 100)
	{
	  jQuery('#sum').val(parseInt(sum - 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = parseFloat((sum * 0.01 * days));		
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function earlyRepayment(fName)
{
  var r = confirm("Are you sure you would like to repay your loan today?");
  		
  if(r)
  {
  	var uid = jQuery("#uid").val();
  	if(uid > 0)
  	{
    	jQuery.post("index.php?act=earlyRepayment", {uid : uid}, function(data){
    			if(data == 'true')
    			{					    				
						jQuery("#early_txt").html('Your early repayment request is in process.');									
    			}    			    		
    		})
  	}
	}									
}

function overdeadlineRepayment(fName)
{
  var r = confirm("Are you sure you would like to repay your loan today?");
  		
  if(r)
  {
  	var uid = $("#uid").val();
  	if(uid > 0)
  	{
    	$.post("index.php?act=overdeadlineRepayment", {uid : uid}, function(data){
    			if(data == 'true')
    			{					    				
						$("#early_txt").html('Your repayment request is in process.');
						$("#early_button").hide();									
    			}    			    		
    		})
  	}
	}										
}

function makePlus()
{
  checkSum();
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum + 10) < 410)
	{
	  jQuery('#sum').val(parseInt(sum + 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = parseFloat((sum * 0.01 * days));		
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function checkSum()
{
   var sum = parseInt(jQuery('#sum').val());	 		 	
	 
	 if(sum < 100 || sum > 400 || !sum || (sum%10) != 0)
	 {
	 	 sliderError = 1;
		 if(!sum)
		 {
		 	 jQuery('#sum').val('160');
		 }
		 else
		 {
		 	 if(sum < 100)
			 {			
			   jQuery('#sum').val('100');
			 }
			 else
			 {
  			 if(sum > 400)
  			 {			
  			   jQuery('#sum').val('400');
  			 }
				 else
				 {
				 	 var sum_str = sum.toString();
					 var first_sum = sum_str.substr(0, (sum_str.length - 1));
					 var second_sum = sum_str.substr((sum_str.length - 1), 1);
					 
					 if(second_sum > 4)
					 {
					 	 first_sum = parseInt(first_sum) + 1;
						 second_sum = 0;
					 }
					 else
					 {
					 	 second_sum = 0;
					 }
					 
					 first_sum = first_sum.toString();
					 second_sum = second_sum.toString();
					 
					 sum = parseInt(first_sum+second_sum);
					 jQuery('#sum').val(sum);
				 }
			 }	 
			 
		 }	 	 
	 }
	 else
	 {
	   sliderError = 0;
		 jQuery('#sum').val(sum);
	 }
	 
	 var sum  		= parseInt(jQuery('#sum').val());
	 var days 	  = parseInt(jQuery('#sliderValue1').val());
	 var intress = parseFloat((sum * 0.01 * days));		
	
	 jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	 
}

function makeMinusLogin()
{
  checkSum();
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum - 10) >= 100)
	{
	  jQuery('#sum').val(parseInt(sum - 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = parseFloat((sum * 0.01 * days));			
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function makePlusLogin(maxLoanSum)
{
  checkSumLogin(maxLoanSum);
	var maxLoanSum = maxLoanSum + 10;
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum + 10) < maxLoanSum)
	{
	  jQuery('#sum').val(parseInt(sum + 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = parseFloat((sum * 0.01 * days));			
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function makeMinusLoginFree()
{
  checkSum();
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum - 10) >= 100)
	{
	  jQuery('#sum').val(parseInt(sum - 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = 0;			
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function makePlusLoginFree(maxLoanSum)
{
  checkSumLogin(maxLoanSum);
	var maxLoanSum = maxLoanSum + 10;
	var sum = parseInt(jQuery('#sum').val());
	
	if((sum + 10) < maxLoanSum)
	{
	  jQuery('#sum').val(parseInt(sum + 10));
	}	
	
	var sum  		= parseInt(jQuery('#sum').val());
	var days 	  = parseInt(jQuery('#sliderValue1').val());
	var intress = 0;			
	
	jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	
}

function checkSumLogin(maxLoanSum)
{
   var sum = parseInt(jQuery('#sum').val());	 		 	
	 
	 if(sum < 100 || sum > maxLoanSum || !sum || (sum%10) != 0)
	 {
	 	 sliderError = 1;
		 if(!sum)
		 {
		 	 jQuery('#sum').val('160');
		 }
		 else
		 {
		 	 if(sum < 100)
			 {			
			   jQuery('#sum').val('100');
			 }
			 else
			 {
  			 if(sum > maxLoanSum)
  			 {			
  			   jQuery('#sum').val(maxLoanSum);
  			 }
				 else
				 {
				 	 var sum_str = sum.toString();
					 var first_sum = sum_str.substr(0, (sum_str.length - 1));
					 var second_sum = sum_str.substr((sum_str.length - 1), 1);
					 
					 if(second_sum > 4)
					 {
					 	 first_sum = parseInt(first_sum) + 1;
						 second_sum = 0;
					 }
					 else
					 {
					 	 second_sum = 0;
					 }
					 
					 first_sum = first_sum.toString();
					 second_sum = second_sum.toString();
					 
					 sum = parseInt(first_sum+second_sum);
					 jQuery('#sum').val(sum);
				 }
			 }	 
			 
		 }	 	 
	 }
	 else
	 {
	   sliderError = 0;
		 jQuery('#sum').val(sum);
	 }
	 
	 var sum  		= parseInt(jQuery('#sum').val());
	 var days 	  = parseInt(jQuery('#sliderValue1').val());
	 var intress = parseFloat((sum * 0.01 * days));			 
	 
	 jQuery('#repayamount').html('You repay £'+ number_format(parseFloat(sum + intress), 2));	 
}

function checkLoanFormLogin(maxLoanSum)
{
  if(sliderError == 0)
	{
	  document.loanForm.submit();
	}
	else
	{
	  checkSumLogin(maxLoanSum);
	}
}

function checkLoanForm()
{
  if(sliderError == 0)
	{
	  document.loanForm.submit();
	}
	else
	{
	  checkSum();
	}
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function resendPin()
{
  var number  = jQuery('#client_number').val();
	
	if (confirm('Are you sure you want to resend PIN?')) {
		 	jQuery.post("index.php?act=resendPinNumber", {number : number}, function(data) {
  	  if(data == 'error')
  		{
				alert('Something went wrong, please contact us by phone 08718903015')
  		}
  		else
  		{
  		  jQuery('#resentpin').html('Pin sent to number '+number);
  		}
  	});
	}
}

function checkContract(pid)
{
  var number  = jQuery('#client_number').val();
	var pin 	  = jQuery('#client_pin').val();
	
	if (confirm('Do you accept our agreement?')) {	
  	jQuery.post("index.php?act=checkPinNumber", {number : number, pin : pin}, function(data) {
  	  if(data != 'error')
  		{
  		  if(pid == 1)
				document.location = 'signUpOk';
				else
				document.location = 'regOk';
  		}
  		else
  		{
  		  alert("Pin number is incorrect!");
  		}
  	});
	}	
}

function checkApplying()
{
  if (confirm('Are you sure?')) {
		 document.applyForm.submit();
	}
}

function login()
{
  var user  = jQuery('#input_20').val();
	var pass 	= jQuery('#input_21').val();
		
  	jQuery.post("index.php?act=checkLogin", {user : user, pass : pass}, function(data) {
  	  if(data != 'error')
  		{
  		  document.loginForm.submit();				
  		}
  		else
  		{
				alert("Number or password is incorrect!");
  		}
  	});		
}

function loginContact()
{
  var user  = jQuery('#user').val();
	var pass 	= jQuery('#pass').val();
	
  	jQuery.post("index.php?act=checkLogin", {user : user, pass : pass}, function(data) {
  	  if(data != 'error')
  		{
  		  document.contactLogin.submit();				
  		}
  		else
  		{
				alert("Number or password is incorrect!");
  		}
  	});		
}

function showQuestions(pid)
{
  var qSubject  = jQuery('#qSubject').val();
	
	jQuery.post("index.php?act=showQuestions", {qSubject : qSubject, quest : pid}, function(data) {
  	  if(data != 'error')
  		{
  		  jQuery('#qQuestionTD').html(data);				
  		}			  		
  	});				
}

function validateEmailContact(id) 
{ 
  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/; 
  return emailPattern.test(id); 
} 

function checkNewClientF()
{  
	var captchaCode = jQuery('#captcha').val();
	var fullName  	= jQuery('#fullName').val();
	var phone  			= jQuery('#phone').val();
	var email  			= jQuery('#email').val();
	var qSubject  	= jQuery('#qSubject').val();
	var qQuestion 	= jQuery('#qQuestion').val();
	
	if(fullName != '' && phone != '' && validateEmailContact(email) && qSubject != 0 && qQuestion != 'Please select a query' && captchaCode.length == 6)
	{
	  jQuery.post("index.php?act=checkCaptcha", {captchaCode : captchaCode}, function(data) {
  	  if(data != 'error')
  		{  		  
				document.newClientF.submit();								
  		}			  		
			else
			{
			  jQuery('#error').html('Security code invalid!');
				jQuery('#error').show();
			}
  	});						
	}
	else
	{
	  jQuery('#error').html('All fields required!');
		jQuery('#error').show();
	}
}

function checkExistingClientF()
{  	
	var qSubject  	= jQuery('#qSubject').val();
	var qQuestion 	= jQuery('#qQuestion').val();
	
	if(qSubject != 0 && (qQuestion != 'Please select a query' && qQuestion != ''))
	{	   
		document.newClientF.submit();								  							
	}
	else
	{
	  jQuery('#error').html('All fields required!');
		jQuery('#error').show();
	}
}

function feedbackForm(pid)
{
  switch(pid)
	{
	  case 1:
				 	 jQuery('#newCustomerF').show();
					 jQuery('#existingCustomerF').hide();
					 jQuery('#businessCustomerF').hide();
					 jQuery('#mailsend').hide();					 
					 break;
		case 2:
				 	 jQuery('#newCustomerF').hide();
					 jQuery('#existingCustomerF').show();
					 jQuery('#businessCustomerF').hide();
					 jQuery('#mailsend').hide();
					 break;			 			 
	}
}

function sendToFriend(user_id)
{
  var name  = jQuery('#friend1').val();
	var email = jQuery('#friend2').val();
	
	var name2  = jQuery('#friend3').val();
	var email2 = jQuery('#friend4').val();
	
	var name3  = jQuery('#friend5').val();
	var email3 = jQuery('#friend6').val();
	
	var name4  = jQuery('#friend7').val();
	var email4 = jQuery('#friend8').val();
	
	var is_ok = 0;
	var is_error = 0;
	
	if(name != '' || email != '')
	{
	  if((validateEmailContact(email) && name != '' && email != ''))
		{
		  is_ok = 1;
 		}
		else
		{
		  is_error = 1;
		}
	}
	
	if(name2 != '' || email2 != '')
	{
	  if((validateEmailContact(email2) && name2 != '' && email2 != ''))
		{
		  is_ok = 1;
 		}
		else
		{
		  is_error = 1;
		}
	}
	
	if(name3 != '' || email3 != '')
	{
	  if((validateEmailContact(email3) && name3 != '' && email3 != ''))
		{
		  is_ok = 1;
 		}
		else
		{
		  is_error = 1;
		}
	}
	
	if(name4 != '' || email4 != '')
	{
	  if((validateEmailContact(email4) && name4 != '' && email4 != ''))
		{
		  is_ok = 1;
 		}
		else
		{
		  is_error = 1;
		}
	}
	
	if(is_ok == 1 && is_error == 0)
	{
		jQuery.post("index.php?act=sendFriendMail", {name : name, email : email, name2 : name2, email2 : email2, name3 : name3, email3 : email3, name4 : name4, email4 : email4, user : user_id}, function(data) {    			
				if(data != 'error')
    		{  		  
  				jQuery('#resOK').show();
  				jQuery('#resError').hide();
					jQuery('#resError2').hide();
  				jQuery('#friend1').val('');
  				jQuery('#friend2').val('');
					jQuery('#friend3').val('');
  				jQuery('#friend4').val('');
					jQuery('#friend5').val('');
  				jQuery('#friend6').val('');
					jQuery('#friend7').val('');
  				jQuery('#friend8').val('');							
    		}			  		
  			else
  			{			  
  				jQuery('#resOK').hide();
  				jQuery('#resError').hide();
					jQuery('#resError2').show();
  			}
    });
	}
	else
	{
	  jQuery('#resOK').hide();
  	jQuery('#resError').show();
	}				
}
