function setPaymentMethod()
{
	var pms = $('paymethod').elements['paymethod'];
	for(var i = 0; i < pms.length; i++)
	{
		if(pms[i].checked)
		{
			if(pms[i].value == 'express')
			{
				$('lightbox').style.margin = '-133px 0pt 0pt -225px';
				$('lightbox').style.width = '450px';
				$('containerlb').style.width = '450px';
				//lbDeactivate();
				buildExpressForm();
				return;
			}
			var myAjax = new Ajax.Request(baseURL + 'payment/setmethod/',
			{
				onComplete: function(r)
				{
					if(r.status == 200)
					{
						if(pms[i].value == 'check')
						{
							$('lightbox').style.margin = '-97px 0pt 0pt -260px';
							$('lightbox').style.width = '520px';
							$('containerlb').style.width = '520px';
						}
						if(pms[i].value == 'card')
						{
							$('lightbox').style.margin = '-280px 0pt 0pt -210px';
							$('lightbox').style.width = '420px';
							$('containerlb').style.width = '420px';
						}
						$('lbContent').innerHTML = r.responseText;
					}
					else
					{
						alert('An error occurred during processing your payment.');
					}
				},
				parameters: 'paymethod=' + pms[i].value
			});
			return;
		}
	}
	alert('Select payment method, please.');
}

function buildExpressForm()
{
	//window.open(baseURL + 'payment/expresscheckout', 'Payment');
	
	$('lbContent').innerHTML = '';
	$('lightbox').style.margin = '-137px 0 0 -200px';
	$('lightbox').style.width = '430px';
	//var close = new Element('input', { 'type': 'button', 'style': 'float:right;','value': 'Close', 'onclick': 'lbDeactivate()', 'class':'btn2', 'id':'closebutton'});
	//close.onclick = lbDeactivate;
	var iframe = new Element('iframe', { 'frameborder': 'no', 'src': baseURL + 'payment/expresscheckout', 'id': 'payframe', 'width': 400, 'height': 225});
//	close.style.width = '600px';
//	close.style.height = '400px';
	//$('lbContent').appendChild(close);
	$('lbContent').appendChild(iframe);
}

function buyMix(mixid)
{
	if(mixid > 0)
	{
		window.open(baseURL + 'medias/buymix/' + mixid, 'Payment');
	}
}

function doDirectPayment()
{
	var captAjax = new Ajax.Request(baseURL + 'payment/check_captcha/',
			{
				parameters: {keystring: $('captcha_string').value},
				onComplete: function(r)
				{
					if(r.status == 200)
					{
						if (r.responseText != '1'){
							$('captcha_string').value = "";
							$('captcha_img').src = $('captcha_img').src + '#';
							alert('You entered wrong text from image!');
						}else{
							var valid = new Validation('directform',{stopOnFirst:true});
							if(!valid.validate()){
								$('captcha_string').value = "";
								$('captcha_img').src = $('captcha_img').src + '#';
								return;
							}
							showProcess();
							var myAjax = new Ajax.Request(baseURL + 'payment/dodirectpayment/',
							{
								onComplete: function(r)
								{
									if(r.status == 200)
									{
										$('lbContent').innerHTML = '';
						                var message = new Element('div', { 'id': 'errormessage'});
										if(r.responseText.indexOf('forjavascripterror') != -1)
										{
											$('lightbox').style.margin = '-64px 0pt 0pt -200px';
											$('lightbox').style.width = '400px';
											$('containerlb').style.width = '756px';
						                    message.setStyle({'width':'400px'});
										}
										else
										{
											$('lightbox').style.margin = '-64px 0pt 0pt -116px';
											$('lightbox').style.width = '300px';
											$('containerlb').style.width = '300px';
										}
										//var close = new Element('input', { 'type': 'button', 'style': 'float:right;','value': 'Close', 'onclick': 'lbDeactivate()', 'class':'btn2', 'id':'closebutton'});
										//$('lbContent').appendChild(close);
										$('lbContent').appendChild(message);
										message.innerHTML = r.responseText;
						                $('lightbox').style.marginTop = '-' + (message.getHeight() / 2) + 'px';
									}
									else
									{
										alert('An error occurred during processing your payment.');
									}
								},
								parameters: $('directform').serialize(),
								asynchronous: false
							});
							hideProcess();	
						}
					}
					else
					{
						alert('An error occurred during processing your payment.');
					}
				}
			})
}

function reload_captcha(){
	$('captcha_img').src = $('captcha_img').src + '#';
}

function spay(){
	quotebox = new lightbox($('lpayment'));
	quotebox.activate();
}

function show_pay(){
	setTimeout(spay,'1000');
}