function addoption()
{
	var av =parseFloat($("#price_product").val());
	
$(".Dropdown option:selected").each(function(x){
	av=av+parseFloat($(this).attr('price'));
	});
	
}
function validate_checkout()
{
	var pmethod = $("input[name='pmethod']:checked").val();

	if($("#bfname").val()=='')
	{
		alert("Please enter your billing first name");	
		return false;
	}
	if($("#blname").val()=='')
	{
		alert("Please enter your billing last name");	
		return false;
	}
	if($("#baddress").val()=='')
	{
		alert("Please enter your billing address");	
		return false;
	}
	if($("#bcity").val()=='')
	{
		alert("Please enter your billing city");	
		return false;
	}
	if($("#bstate").val()=='')
	{
		alert("Please enter your billing state");	
		return false;
	}
	if($("#bcountry").val()=='')
	{
		alert("Please enter your billing country");	
		return false;
	}
	if($("#bzip").val()=='')
	{
		alert("Please enter your billing post code");	
		return false;
	}
	if($("#email").val()=='')
	{
		alert("Please enter your email address");	
		return false;
	}
	if (echeck($("#email").val())==false){
		
		return false
	}
	if($("#sfname").val()=='')
	{
		alert("Please enter your shipping first name");	
		return false;
	}
	if($("#slname").val()=='')
	{
		alert("Please enter your shipping last name");	
		return false;
	}
	if($("#saddress").val()=='')
	{
		alert("Please enter your shipping address");	
		return false;
	}
	if($("#scity").val()=='')
	{
		alert("Please enter your shipping city");	
		return false;
	}
	if($("#sstate").val()=='')
	{
		alert("Please enter your shipping state");	
		return false;
	}
	if($("#scountry").val()=='')
	{
		alert("Please enter your shipping country");	
		return false;
	}
	if($("#szip").val()=='')
	{
		alert("Please enter your shipping post code");	
		return false;
	}	

	if($("#createacc").is(':checked'))
	{
		
		if($("#npass").val()=='')
		{
			alert("Please enter your password")	;
			return false;
		}
		if($("#cpass").val()!=$("#npass").val())
		{
			alert("Confirm password is not matching")	;
			return false;
		}

		if(pmethod=='ccard')
		{
			

			if($("#ccname").val()=='')
			{
				alert("Please enter your name");
				return false;
			}
			if($("#ccnumber").val()=='')
			{
				alert("Please enter your Credit Card Number");
				return false;
			}
			if($("#month").val()=='')
			{
				alert("Please select expiry month");
				return false;
			}
					
		}
	}	
	if(pmethod=='ccard')
		{
			if($("#ccname").val()=='')
			{
				alert("Please enter your name");
				return false;
			}
			if($("#ccnumber").val()=='')
			{
				alert("Please enter your Credit Card Number");
				return false;
			}
			if($("#month").val()=='')
			{
				alert("Please select expiry month");
				return false;
			}
					
		}
	
	return true;
	
}

function showcreateaccbox()
{
	if( $("#createacc").is(':checked') )
	$("#createaccbox").show();
	else
	$("#createaccbox").hide();


}

function showshipbox()
{
	if( $("#diffship").is(':checked') )
	$("#shipbox").show();
	else
	$("#shipbox").hide();


}

function attribute_price()
{

	var av =parseFloat($("#price_product").val());
	
$(".Dropdown option:selected").each(function(x){
	av=av+parseFloat($(this).attr('price'));
	});

	$(".Radio:checked").each(function(x){
	
	av=av+parseFloat($(this).attr("price"));
	
	});
	
	
	$(".Checkbox:checked").each(function(x){
	
	av=av+parseFloat($(this).attr("price"));
	});
	
	$("#price").text(number_format(av,2));
	//$("#price2").text(number_format(av,2));
	
//	$("#paymentAmount").val(  number_format(av,2) );
//	$("#item_price_1").val( number_format(av,2) );
}
function number_format(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}

function bl_show()
{
$("#builder_login").show();
$("#customer-login").hide();
}

function cm_show()
{
$("#builder_login").hide();
$("#customer-login").show();
}

function ho_show(){
$("#ho").fadeIn("");
$("#bu").fadeOut("");
$("#sb").fadeOut("");
$("#fc").fadeOut("");
$("#flash-nav ul li.home-owners").addClass("l-selected")
$("#flash-nav ul li.builders").removeClass("selected")
$("#flash-nav ul li.small-business").removeClass("selected")
$("#flash-nav ul li.for-customers").removeClass("r-selected")
}
function pt_show(){
$("#ho").fadeIn("");
$("#bu").fadeOut("");
$("#sb").fadeOut("");
$("#fc").fadeOut("");
$("#flash-nav ul li.home-owners").addClass("l-selected")
$("#flash-nav ul li.builders").removeClass("selected")
$("#flash-nav ul li.small-business").removeClass("selected")
$("#flash-nav ul li.for-customers").removeClass("r-selected")
}
function bu_show(){
$("#ho").fadeOut("");
$("#bu").fadeIn("");
$("#sb").fadeOut("");
$("#fc").fadeOut("");
$("#flash-nav ul li.home-owners").removeClass("l-selected")
$("#flash-nav ul li.builders").addClass("selected")
$("#flash-nav ul li.small-business").removeClass("selected")
$("#flash-nav ul li.for-customers").removeClass("r-selected")
}

function sb_show(){
$("#ho").fadeOut("");
$("#bu").fadeOut("");
$("#sb").fadeIn("");
$("#fc").fadeOut("");
$("#flash-nav ul li.home-owners").removeClass("l-selected")
$("#flash-nav ul li.builders").removeClass("selected")
$("#flash-nav ul li.small-business").addClass("selected")
$("#flash-nav ul li.for-customers").removeClass("r-selected")
}

function fc_show(){
$("#ho").fadeOut("");
$("#bu").fadeOut("");
$("#sb").fadeOut("");
$("#fc").fadeIn("");
$("#flash-nav ul li.home-owners").removeClass("l-selected")
$("#flash-nav ul li.builders").removeClass("selected")
$("#flash-nav ul li.small-business").removeClass("selected")
$("#flash-nav ul li.for-customers").addClass("r-selected")
}


function slideSwitch() {
    var $active = $('#ho IMG.active');

    if ( $active.length == 0 ) $active = $('#ho IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#ho IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});


function slideSwitch1() {
    var $active = $('#bu IMG.active');

    if ( $active.length == 0 ) $active = $('#bu IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#bu IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch1()", 5000 );
});


function slideSwitch2() {
    var $active = $('#sb IMG.active');

    if ( $active.length == 0 ) $active = $('#sb IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#sb IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch2()", 5000 );
});

function slideSwitch3() {
    var $active = $('#fc IMG.active');
	var $active1 = $('#fc P.active');

    if ( $active.length == 0 ) $active = $('#fc IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#fc IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
		 
	if ( $active1.length == 0 ) $active1 = $('#fc P:last');

    var $next =  $active1.next().length ? $active1.next()
        : $('#fc P:first');

    $active1.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active1.removeClass('active last-active');
        });
}


$(function() {
    setInterval( "slideSwitch3()", 5000 );
});

function slideSwitch4() {
    var $active = $('#pt P.active');

    if ( $active.length == 0 ) $active = $('#pt P:last');

    var $next =  $active.next().length ? $active.next()
        : $('#pt P:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {
    setInterval( "slideSwitch4()", 5000 );
});



function updateprice(objx,price,ta,pid)
{	
	var y =0;
	var flag =0;
	$("#price").text(0);
	for(i=1;i<=ta;i++)
	{
	
		var aname = "attribute"+i;
		var hname = "#attribute"+i;
		var attribute_name = "#attribute_name"+i;
		var atype = $(hname).attr('class');			
		
		if(atype=='Radio')
		{						
			var av_id =  $("input[name='"+aname+"']:checked").val();
			
			$.post("ajax.php",{action:"attprice",avid:av_id, pid:pid},function(data){
																			  
				var data = data.split('~');
				var av_name = data[0];
				var av_value = data[1];
				var total = data[2];
				//$("#total_price").val( parseFloat( $("#total_price").val() ) +parseFloat(av_value));
				$("#price").text( parseFloat(  $("#price").text() ) + parseFloat(av_value) );
				$("#price2").text(  $("#price").text()  );
			 });
			
		}
		else if(atype=='Dropdown')
		{	
					
			$.post("ajax.php",{action:"attprice",avid:$(hname).val(), pid:pid},function(data){
				var data = data.split('~');
				var av_name = data[0];
				var av_value = data[1];
				var total = data[2];
				//$("#total_price").val( parseFloat( $("#total_price").val() ) + parseFloat(av_value));
				$("#price").text( parseFloat(  $("#price").text() ) + parseFloat(av_value) );
				$("#price2").text(  $("#price").text()  );

			 });
		}
		if(flag==0) 
		{	
			 flag = 1;
			 var n = $("input:checked").length;
			 var totalsuba = $('input[class=Checkbox]').length;
			 //alert(n);
			 for(s=1;s<=totalsuba;s++)
			 {
		 		var subattribute = "subattribute"+s;
				var hsubattribute = "#subattribute"+s;
				
				//alert($("input:checked").val());
				
				if($('input[name='+subattribute+']').is(':checked'))
				{
					//alert(hsubattribute);
						$.post("ajax.php",{action:"attprice",avid:$(hsubattribute).val(), pid:pid},function(data){
										// alert(data);
						var data = data.split('~');
						var av_name = data[0];
						var av_value = data[1];
						var total = data[2];
						//$("#total_price").val( parseFloat( $("#total_price").val() ) + parseFloat(av_value));
						$("#price").text( parseFloat(  $("#price").text() ) + parseFloat(av_value) );
						$("#price2").text(  $("#price").text()  );
		
					 });
				}
			 }
		}
		
	}

		$("#price").text( parseFloat( $("#price").text() ) + price);	
		$("#price2").text(  $("#price").text()  );

}



function loadpage(page)
{
	$("#loader").fadeIn("fast");
	$("#pagebox").fadeOut("fast");
	$("#pagebox").empty();
	$("#pagebox").load(page,{},function(){
			$("#pagebox").fadeIn("slow");
			$("#loader").fadeOut(800);
			
	});

}

function setVisibility1() 
{
	document.getElementById('schange').style.display = "none";	
	document.getElementById('scancel').style.display = "inline";	
	document.getElementById('saddresstab').style.display = "inline";	
	document.getElementById('oad1').style.display = "none";	

}
function setVisibility2() 
{
	
	document.getElementById('scancel').style.display = "none";	
	document.getElementById('schange').style.display = "inline";	
	document.getElementById('saddresstab').style.display = "none";	
	document.getElementById('oad1').style.display = "inline";	
	
	document.getElementById('snamex1').innerHTML=document.getElementById('sfname').value;
	document.getElementById('slnamex1').innerHTML=document.getElementById('slname').value;
	document.getElementById('saddressx1').innerHTML=document.getElementById('saddress').value;
	document.getElementById('scityx1').innerHTML=document.getElementById('scity').value;
	document.getElementById('sstatex1').innerHTML=document.getElementById('sstate').value;
	document.getElementById('szipx1').innerHTML=document.getElementById('szip').value;
	document.getElementById('scountryx1').innerHTML=document.getElementById('scountry').value;
}


function setVisibility3() 
{
	document.getElementById('bchange').style.display = "none";	
	document.getElementById('bcancel').style.display = "inline";	
	document.getElementById('baddresstab').style.display = "inline";	
	document.getElementById('oad2').style.display = "none";	

}
function setVisibility4() 
{
	
	document.getElementById('bcancel').style.display = "none";	
	document.getElementById('bchange').style.display = "inline";	
	document.getElementById('baddresstab').style.display = "none";	
	document.getElementById('oad2').style.display = "inline";	
	
	document.getElementById('bnamex1').innerHTML=document.getElementById('bfname').value;
	document.getElementById('blnamex1').innerHTML=document.getElementById('blname').value;
	document.getElementById('baddressx1').innerHTML=document.getElementById('baddress').value;
	document.getElementById('bcityx1').innerHTML=document.getElementById('bcity').value;
	document.getElementById('bstatex1').innerHTML=document.getElementById('bstate').value;
	document.getElementById('bzipx1').innerHTML=document.getElementById('bzip').value;
	document.getElementById('bcountryx1').innerHTML=document.getElementById('bcountry').value;
}


function submitform(formx)
{
	var id = document.getElementById(formx);
	id.submit();
}


function submitformaction(formx,action)
{
	var id = document.getElementById(formx);
	id.action=action;
	id.submit();
}

function yearlist(mid)
{
	//$("#year_loader").fadeIn(100);
	$.post("ajax.php",{action:"yearlist",model_id:mid},function(data)
	{
		$("#year").empty();
		$("#year").append(data);
		//$("#year_loader").fadeOut(100);	
	});
}

function modellist(cid)
{
	//$("#model_loader").fadeIn(100);
	$.post("ajax.php",{action:"modellist",company_id:cid},function(data)
	{
		$("#model_id").empty();
		$("#model_id").append(data);
		//$("#model_loader").fadeOut(100);	
	
	
	});

}


function updateall(pid)
{
var type = new Array("p","m","r","w","s");
var i =0;
while(i<5)
{
	//alert(pid+"/"+type[i]);
	setprice(pid,type[i]);
	i++;
}

}

function setprice(pid,type)
{
	var wtext = "#"+type+pid;
	var div = "#div"+type+pid;
	var p = "#p"+type+pid;
	if($(wtext).val()!="")
	{
		$.post("ajax.php",{action:'updateprice', pid:pid, type:type, price:$(wtext).val() }, function(datap)
		{
		$(div).hide();
		$(p).text(datap);
		}
		);
	}
	else if($(wtext).val()=="")
	{
	$(div).hide();
	}
	
}



function gettd(pid,type)
{
	var div = "#div"+type+pid;
	var wtext = "#"+type+pid;
	$(div).show();	
	$(wtext).focus();
}
function hidediv(pid,type)
{

	var div = "#div"+type+pid;
	$(div).hide();	
	
}


function loc(url)
{
	
		window.location=url;
	
}

function del(url)
{
	if(	confirm("Are you sure you want to delete it?") )
	{
		window.location=url;
	}
}

