// JavaScript Document
var vartotalPrice = 75;
var finalPriceWithOptions = 0;
var finalPrice = 75;
var numberOfPages =  1;
function selectPlanPrice(val)
{
	if (val == 'pro'){
		document.getElementById('totalPriceID').innerHTML = 'Total: $149';
		document.getElementById('secondFinalTotalID').innerHTML = 'Total: $149';
		document.getElementById('totalPriceHidden').value = '149';
		document.getElementById('finalAmtValID').value = '149';
		finalPriceWithOptions = 0;
		finalPrice = 149;
		vartotalPrice = 149;
		changeTotalPrice(document.getElementById('howManyPagesID'),document.getElementById('howManyPagesID').value);
		uncheckAll();	
	}else if (val == 'standard'){
		document.getElementById('totalPriceID').innerHTML = 'Total: $75';
		document.getElementById('secondFinalTotalID').innerHTML = 'Total: $75';
		document.getElementById('totalPriceHidden').value = '75';
		document.getElementById('finalAmtValID').value = '75';
		finalPriceWithOptions = 0;
		vartotalPrice = 75;
		finalPrice = 75;
		changeTotalPrice(document.getElementById('howManyPagesID'),document.getElementById('howManyPagesID').value);
		uncheckAll();
	} else if (val == 'high'){
		document.getElementById('totalPriceID').innerHTML = 'Total: $249';
		document.getElementById('secondFinalTotalID').innerHTML = 'Total: $249';
		document.getElementById('totalPriceHidden').value = '249';
		finalPriceWithOptions = 0;
		document.getElementById('finalAmtValID').value = '249';
		vartotalPrice = 249;
		finalPrice = 249;
		changeTotalPrice(document.getElementById('howManyPagesID'),document.getElementById('howManyPagesID').value);
		uncheckAll();
	}
}

function changeTotalPrice(elem,val){  
	var numericExpression = /^[0-9]+$/;
	var totalValue =  parseInt(vartotalPrice);
	if(elem.value > 15){
		alert('If you have more than 15 pages or you are in hurry. Please contact us directly');
		
		}
	if(elem.value.match(numericExpression) && elem.value >=1){
		numberOfPages =  val;	
	}else{
		elem.value = '';
		numberOfPages =  1;	
		elem.focus();
	}
	var halfValue = totalValue / 2; 
	finalPrice = totalValue + ( halfValue * (numberOfPages-1)) + finalPriceWithOptions;
	document.getElementById('totalPriceHidden').value = finalPrice;
	document.getElementById('totalPriceID').innerHTML = 'Total: $' + finalPrice;
	document.getElementById('secondFinalTotalID').innerHTML = 'Total: $' + finalPrice;
	document.getElementById('finalAmtValID').value = finalPrice;

}

function optionsAddedToFinal(val, n, price){
var totalValue =  parseInt(document.getElementById('totalPriceHidden').value);
	var fieldVal = parseInt(price);
	if (!val.checked){  
		finalPriceWithOptions = finalPriceWithOptions - fieldVal;					
		finalPrice = finalPrice - fieldVal;
	} else {   
		finalPriceWithOptions = finalPriceWithOptions + fieldVal;
		finalPrice = finalPrice + fieldVal;
	}
	
	document.getElementById('totalPriceHidden').value = finalPrice;
	document.getElementById('totalPriceID').innerHTML = 'Total: $' + finalPrice;
	document.getElementById('secondFinalTotalID').innerHTML = 'Total: $' + finalPrice;
	document.getElementById('finalAmtValID').value = finalPrice;

}

function uncheckAll()
{ 
	$('input[name=options[]]').attr('checked',false);	
}

function validateForm()
{	
	var email = document.getElementById('frmEmailPaymentID').value;
	var frmNamePayment = document.getElementById('frmNamePayment').value;
	var comment = document.getElementById('comments').value;
	if (frmNamePayment == ''){
		jQuery('#frmNamePayment').fadeOut().fadeIn().fadeOut().fadeIn();
		document.getElementById('frmNamePayment').focus();
		return false;
	}
	if(email == ""){
		jQuery('#frmEmailPaymentID').fadeOut().fadeIn().fadeOut().fadeIn();
		document.getElementById('frmEmailPaymentID').focus();
		return false;
	}
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(! filter.test(email)){
		jQuery('#frmEmailPaymentID').fadeOut().fadeIn().fadeOut().fadeIn();
		document.getElementById('frmEmailPaymentID').focus();
		return false;
	}
	if (comment == ''){
		jQuery('#comments').fadeOut().fadeIn().fadeOut().fadeIn();
		document.getElementById('comments').focus();
		return false;
	}
	return true;
}