
billing = function(){
$('document').ready(function(){
//$('.billingns').center();
$('.bill').hide();
$('.billingns').show();
$('.bill').fadeIn();
});
}

var required = new Array('fName', 'sName','card','city', 'address', 'country', 'mail', 'cvv', 'month', 'year', 'method', 'code', 'state' );
var required_show = new Array('your name', 'your second name', 'your card number', 'your city', 'your address', 'your country', 'your e-mail', 'your CVV2/CVC2', 'expiration month', 'expiration year', 'payment method', 'your zip/postal code', 'your state');
function sendform () 
{
  var i, j;
  for(j=0; j<required.length; j++) {
    for (i=0; i<document.forms.bill.length; i++) {
      if (document.forms.bill.elements[i].name == required[j] && document.forms.bill.elements[i].value == '' ) {
        alert('Please fill ' + required_show[j]);
        document.forms.bill.elements[i].focus();
        return false;
      }
    }
  }
  return true;
}





createLink = function(){
$.ajax({
		type : 'POST',
		url : 'index.php',
		dataType : 'html',
		data: {
			ord_id: $('.orderid').val()		
		},
		success : function(data){
		data = data.replace(/\"/g, '');
		$('.proceed a').attr('href','/?download='+data);
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			//$('body').append('error');
		}
	});
}


getSuccess = function(){
$.ajax({
		type : 'POST',
		url : 'index.php',
		dataType : 'html',
		data: {
					
		},
		success : function(data){
		
		$('.successBill').hide();
		$('.billingns2').show();
		$('.successBill').fadeIn();

		billing = function(){
	$('document').ready(function(){
	$('.successBill').hide();
	$('.billingns2').show();
	$('.successBill').fadeIn();
	});
	}

		//createLink();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			//$('body').append('error');
		}
	});
}

function orderSuccess() 
{
  $('#addnumber').show(); setTimeout(function() {$('#addnumber').fadeOut('slow'); }, 2000);
}
function orderFail() 
{
  $('#errornumber').show(); setTimeout(function() {$('#errornumber').fadeOut('slow'); }, 5000);
}
getStates = function(){
$.ajax({
		type : 'POST',
		url : 'index.php',
		dataType : 'json',
		data: {
			cCode: jQuery('#country').val()		
		},
		success : function(data){
		$('.noregion').remove();
		$('.srInput').show();
		var q;
		if( $('.srInput').text()!='Choose region') $('.srInput').text('');
		$('.srList ul li').remove();
		for(q=0;q<data['name'].length;q++)
		{
		$('.srList ul').append('<li title='+data['code'][q]+'>'+data['name'][q]+'</li>');	
		}
		jQuery('.srList ul li').click(function(){ jQuery('.srInput').text( jQuery(this).text() ); jQuery('#region').val( jQuery(this).attr('title') );
if($(this).parent().parent().parent().next().attr('class')=='alert') $(this).parent().parent().parent().next().remove(); 
jQuery('.srList').hide(); } );	
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			if( $('.srInput').text()!='Choose region') $('.srInput').text('');
			$('.srList ul li').remove();
			$('.noregion').remove();
			$('.srInput').hide();
			$('.sRegion').append('<div class="noregion">There is no region for selected country</div>');
		}
	});
}

send = function(){


	$.ajax({
		type : 'POST',
		url : 'index.php',
		dataType : 'json',
		data: {
			fName: jQuery('#fName').val(),
			sName: jQuery('#sName').val(),
			card: jQuery('#card').val(),
			city: jQuery('#city').val(),
			address: jQuery('#address').val(),
			country: jQuery('#country').val(),
			mail: jQuery('#mail').val(),
			cvv: jQuery('#cvv').val(),
			month: jQuery('#month').val(),
			year: jQuery('#year').val(),
			state: jQuery('#region').val(),
			method: jQuery('#method').val(),
			code: jQuery('#code').val(),
			noajax: 0

		},
		success : function(data){
			if(data[1] == 'success')
			{
			//$('.shade').hide();
			$('.billingns').hide();
			//$('.billingns2').center();
			//$('#addnumber').center();
			$('.mainResponse span').html(data[0]);
			$('.orderid').val(data[2]);
			getSuccess();
			//orderSuccess();
			}
			else
			{
			var error = data['err'];
			var j;
			$('.alert').remove();
			$('.dvisa').remove();
			$('.dmaster').remove();
			$('.damex').remove();
			if(data['card']) 
			switch (data['card']) {
			case 'master':
			$('.card').append('<div class="dmaster"></div>');
			break;
			case 'amex':
			$('.card').append('<div class="damex"></div>');
			break;
			case 'visa':
			$('.card').append('<div class="dvisa"></div>');
			break;
			}
			for(j = 0; j<error.length; j++)
			{
			switch (error[j]) {
			case 'email':
			$('.mail').append('<div class="alert"><div>Enter valid e-mail<br/>For example: myMail@mail.com</div></div>');
			break;
			case 'cc_firstname':
			$('.fName').append('<div class="alert"><div>Please enter your first name</div></div>');
			break;
			case 'cc_lastname':
			$('.sName').append('<div class="alert"><div>Please enter your last name</div></div>');
			break;
			case 'cc_number':
			$('.card').append('<div class="alert"><div>You enter an invalid card number.<br/>Please correct it.</div></div>');
			break;
			case 'cc_exp':
			$('.date').append('<div class="alert"><div>Your card has expired.<br/> Please enter valid expiration date.</div></div>');
			break;
			case 'cc_cvv':
			$('.cvv').append('<div class="alert"><div>Please enter valid CVV2/CVC2.</div></div>');
			break;
			case 'bill_country_code':
			$('.country').append('<div class="alert"><div>Please select a country.</div></div>');
			break;
			case 'bill_region_code':
			$('.state').append('<div class="alert"><div>Please select a valid region for a chosen country.</div></div>');
			break;
			case 'bill_city':
			$('.city').append('<div class="alert"><div>Please enter your city.</div></div>');
			break;
			case 'bill_address':
			$('.address').append('<div class="alert"><div>Please enter your address.</div></div>');
			break;
			case 'bill_zip':
			$('.code').append('<div class="alert"><div>Please enter your zip code.</div></div>');
			break;			
}
					
			}
			
			//$('#errornumber').center();
			//$('#errornumber').html('Please enter a valid data in<br/>'+data);
			//orderFail();
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			
			$('body').append('error');
		}
	});
}


jQuery.fn.center = function () {
     this.css('position','fixed');
	var cTop;
	var cLeft;
	cLeft =  ($(window).width() - this.outerWidth() )/2 + jQuery(window).scrollLeft();
	cTop = ($(window).height() - this.outerHeight() )/2;
	if(cTop < 10) cTop = 10;
	if(cLeft < 10) cLeft = 10;
    this.css('top',  cTop + 'px');
    this.css('left', cLeft + 'px');
   
    return this;
}

$('document').ready(function(){
//$('.terms a').removeAttr('href');


$('a[href="/?terms=1"]').unbind('click').click(function(){
var host = location.hostname;
$('.shade').show();
$('html, body').scrollTop('0');
$('#terms').html("<form action='/' method='POST' name='clForm' id='clForm'><input onclick='return closeBill();' class='ifClose' name='ifClose' value='Close' type='submit'/></form><div class='tHead'>Terms of use</div><p><b>Terms</b><br/>By accessing this web site, you are agreeing to be bound by these web site Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this web site are protected by applicable copyright and trade mark law.</p><p><b>Services</b><br/>The information on this website is presented for entertainment purposes.</p><p><b>Links</b><br/><span>"+host+"</span> has not reviewed all of the sites linked to its Internet web site and is not responsible for the contents of any such linked site. The inclusion of any link does not imply endorsement by <span>"+host+"</span> of the site. Use of any such linked web site is at the user's own risk.</p><p><b>Site Terms of Use Modifications</b><br/><span>"+host+"</span> may revise these terms of use for its web site at any time without notice. By using this web site you are agreeing to be bound by the then current version of these Terms and Conditions of Use.</p>");

$('#terms').fadeIn();
return false;
});

$('a[href="/?privacy=1"]').unbind('click').click(function(){
var host = location.hostname;
$('.shade').show();
$('html, body').scrollTop('0');
$('#privacy').html("<form action='/' method='POST' name='clForm' id='clForm'><input onclick='return closeBill();' class='ifClose' name='ifClose' value='Close' type='submit'/></form><div class='tHead'>Privacy Policy</div><p><p><b>Our refund policies</b><br/>If you are not satisfied with our product(s) or service(s), please contact us at support@"+host+" with your comment and we will get back to you within 12 hours and we will do everything to help you.<br/> Refunds will be given at the discretion of "+host+" Management.</p><p><b>Our Internet Privacy Statement</b><br/>We use advanced security technologies to protect your privacy. The personal information you submit on our website is gathered and processed without sharing with third parties. We understand that it’s very important for you to feel safe and comfortable when you are using our services. We are always protecting your personal data and follow the privacy policies thoroughly. <br/>Please carefully read the statement below to find out about our privacy practices.</p><p><b>I. COLLECTION OF INFORMATION</b><br/>We gather the information you submit to process your payment successfully. We do not store your payment details and guarantee the security of the transactions.</p><p><b>II. USE OF INFORMATION</b><br/>The information we collect from you may be used for processing transactions<br/>Your information, whether public or private, will not be sold, exchanged, transferred, or given to any other company for any reason whatsoever, without your consent, other than for the express purpose of delivering the purchased product or service requested.<br/>We implement a variety of security measures to maintain the safety of your personal information when you place an order<br/>We offer the use of a secure server. All supplied sensitive/credit information is transmitted via Secure Socket Layer (SSL) technology and then encrypted into our Payment gateway providers database only to be accessible by those authorized with special access rights to such systems, and are required to?keep the information confidential.</p><p><b>III. USE OF IP ADDRESSES</b><br/>Your IP Address can be used to help monitor problems with our server, to manage our web site, and to keep statistics.</p><p><b>IV. USE OF COOKIES</b><br/>When you view our web site or advertisements, we might store some information on your computer. This information will be in the form of a 'cookie' or similar file. Cookies are small pieces of information stored on your hard drive to facilitate your current and future visits to our site. We use cookies to deliver content specific to your interests so you won't have to enter it each time you visit the site, and for other purposes. You can set your web browser to notify you when you are sent a cookie, giving you the opportunity to decide whether or not to accept the cookie.<br/><p><b>V. USE OF E-MAIL ADDRESS</b><br/>We will never share the e-mail address you submit to receive our services with any third party. All e-mails from us, including the special offers will be sent to you exclusively by "+host+".</p><p><b>VI. SECURITY</b><br/>We follow the most strict industry standard technical and procedural measures to protect your personal information from anauthorized access.</p><p><b>VII. CONTACTING US</b><br/>If you have any questions about this privacy statement, the practices of this site, or your dealings with this web site, you can contact us at support@"+host+"</p>");

$('#privacy').fadeIn();
return false;
});


//$('.billingns').center();
$('.srInput').hide();
$('.sRegion').append('<div class="noregion">Please select a country</div>');

jQuery('.smInput').click(function(){ jQuery('.smList').slideToggle('fast'); });
jQuery('.smList ul li').click(function(){ jQuery('.smInput').text( jQuery(this).text() ); jQuery('#month').val( jQuery(this).attr('title') ); 
if($(this).parent().parent().parent().next().next().attr('class')=='alert') $(this).parent().parent().parent().next().next().remove();
jQuery('.smList').hide(); } );

jQuery('.syInput').click(function(){ jQuery('.syList').slideToggle('fast'); });
jQuery('.syList ul li').click(function(){ jQuery('.syInput').text( jQuery(this).text() ); jQuery('#year').val( jQuery(this).attr('title') ); 
if($(this).parent().parent().parent().next().attr('class')=='alert') $(this).parent().parent().parent().next().remove();
jQuery('.syList').hide(); } );

jQuery('.scInput').click(function(){ jQuery('.scList').slideToggle('fast'); });
jQuery('.scList ul li').click(function(){ jQuery('.scInput').text( jQuery(this).text() ); jQuery('#country').val( jQuery(this).attr('title') ); 
if($(this).parent().parent().parent().next().attr('class')=='alert') $(this).parent().parent().parent().next().remove();
jQuery('.scList').hide();
getStates(); } );

jQuery('.srInput').click(function(){ jQuery('.srList').slideToggle('fast'); });
jQuery('.srList ul li').click(function(){ jQuery('.srInput').text( jQuery(this).text() ); jQuery('#region').val( jQuery(this).attr('title') );
if($(this).parent().parent().parent().next().attr('class')=='alert') $(this).parent().parent().parent().next().remove();
jQuery('.srList').hide(); } );


jQuery('.sMonth, .sYear, .sCountry, .sRegion').mouseleave(function(){
if($(this).children('.cs').next().css('display')=='block') $(this).children('.cs').next().slideUp('fast');
});


$('.fPayMethod img').click(function(){
$('.fPayMethod img').css('border','0');
$(this).css('border', '1px solid #5a6970');
jQuery('#method').val( jQuery(this).attr('alt') ); 
});

$('.input input').blur(function(){
if($(this).next().attr('class')=='alert' && $(this).val()!='') $(this).next().remove();
});

$('.fClose').click(function(){
$('.billingns').fadeOut('slow');
});

closeBill = function()
{
$('.shade').hide();
$('.billingns').hide();
$('.billingns2').hide();
$('.siteInfo').hide();
return false;
}

sendPay = function()
{
send();
return false;
}




});


