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;
	}
}
