$(document).ready(function()
{
	$.extend({
	  getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
		  hash = hashes[i].split('=');
		  vars.push(hash[0]);
		  vars[hash[0]] = hash[1];
		}
		return vars;
	  },
	  getUrlVar: function(sal){
		return $.getUrlVars()[sal];
	  }
	});
	var salurl = $.getUrlVar('sal');
	var filTxtBox=$('#SalTxt').val(salurl);
	txtBoxVal();
	if(salurl){
		$('.calBut').trigger('click');
	}
});

function txtBoxVal()
{
	$('#SalTxt').bind('keydown',function(e)
		{
			var keyCode=e.which;
			var isStandard=(keyCode >47 && keyCode <58);
			var isExtended=(keyCode >95 && keyCode<106);
			var validKeyCodes=',8,23,24,37,38,39,40,46,36,35,';
			var enterKey=',13,'
			var isOther=(validKeyCodes.indexOf(',' + keyCode + ',')!=-1);
			if (isStandard || isExtended || isOther)
			{
				return true;
			}

			else {
					return false;
			}
			
			

		}).bind('blur', function()
		{
			var pattern=new RegExp('[^0-9]+', 'g');
			var $input = $(this);
			var value= $input.val();
			value=value.replace(pattern, '');
			$input.val(value)
		});
	$('.calBut').click(function()
		{	
			budgetCaldulator()
		});
}

	

function budgetCaldulator(){
	
	var salary=$('#SalTxt').val();
			/*if(salary>=1 && salary<= 29999)
				{
					errorSalShow();
				};*/
			if(salary>=1)
				{
					$('.galCalContainer').hide();
					$('.galCalContainerDetails').css('display','block');
					$('.engRingAll').hide();
					$('.engRing').css('display','block');
					
					//Rings less then 30000
				if(salary>=1 && salary<= 39999)
						{
							$('#PriceTwo').css('display','block');
							$('#PriceTwo .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('< &#36; 1,500')
							if(salary>=1 && salary< 35000)
								{
									$('.amount').html('1,250');
								};
							if(salary>=35000 && salary<= 39999)
								{
									$('.amount').html('1,458');
								};
							priceid=167;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=167');
							//popUpDiv1();
						};
						//End of Ring B/w 30000 to 65000
					
					//Rings Btw 30000 to 64999
				if(salary>=40000 && salary< 65000)
						{
							$('#PriceTwo').css('display','block');
							$('#PriceTwo .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('&#36; 1,500 - &#36; 2,500')
							if(salary>=40000 && salary< 45000)
								{
									$('.amount').html('1,666');
								};
							if(salary>=45000 && salary< 50000)
								{
									$('.amount').html('1,875');
								};
							if(salary>=50000 && salary< 55000)
								{
									$('.amount').html('2,083');
								};
							if(salary>=55000 && salary< 60000)
								{
									$('.amount').html('2,291');
								};
							if(salary>=60000 && salary< 65000)
								{
									$('.amount').html('2,500');
								};
							priceid=168;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=168');
							//popUpDiv1();
						};
						//End of Ring B/w 30000 to 65000
						//Rings Btw 65000 to 100000
						if(salary>=65000 && salary< 100000)
						{
							$('#PriceThree').css('display','block');
							$('#PriceThree .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('&#36; 2,501 - &#36; 4,000')
							if(salary>=65000 && salary< 70000)
								{
									$('.amount').html('2,708');
								};
							if(salary>=70000 && salary< 75000)
								{
									$('.amount').html('2,916');
								};
							if(salary>=75000 && salary< 80000)
								{
									$('.amount').html('3,125');
								};
							if(salary>=80000 && salary< 85000)
								{
									$('.amount').html('3,333');
								};
							if(salary>=85000 && salary< 90000)
								{
									$('.amount').html('3,541');
								};
							if(salary>=90000 && salary< 95000)
								{
									$('.amount').html('3,750');
								};
							if(salary>=95000 && salary< 100000)
								{
									$('.amount').html('3,958');
								};
							priceid=59;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=59');
							//popUpDiv2();
						};
						//End of Ring B/w 65000 to 100000
						//Rings Btw 100000 to 145000
						if(salary>=100000 && salary< 145000)
						{
							$('#PriceFour').css('display','block');
							$('#PriceFour .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('&#36; 4,001 - &#36; 6,000')
							if(salary>=100000 && salary< 105000)
								{
									$('.amount').html('4,166');
								};
							if(salary>=105000 && salary< 110000)
								{
									$('.amount').html('4,375');
								};
							if(salary>=110000 && salary< 115000)
								{
									$('.amount').html('4,583');
								};
							if(salary>=115000 && salary< 120000)
								{
									$('.amount').html('4,791');
								};
							if(salary>=120000 && salary< 125000)
								{
									$('.amount').html('5,000');
								};
							if(salary>=125000 && salary< 130000)
								{
									$('.amount').html('5,208');
								};
							if(salary>=130000 && salary< 135000)
								{
									$('.amount').html('5,416');
								};
							if(salary>=135000 && salary< 140000)
								{
									$('.amount').html('5,625');
								};
							if(salary>=140000 && salary< 145000)
								{
									$('.amount').html('5,833');
								};
							priceid=61;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=61');
							//popUpDiv3();
						};
						//End of Ring B/w 100000 to 145000
						//Rings Btw 145000 to 185000
						if(salary>=145000 && salary<=184999)
						{
							$('#PriceFive').css('display','block');
							$('#PriceFive .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('&#36; 6,001 - &#36; 7,500')
							if(salary>=145000 && salary< 150000)
								{
									$('.amount').html('6,041');
								};
							if(salary>=150000 && salary< 155000)
								{
									$('.amount').html('6,250');
								};
							if(salary>=155000 && salary< 160000)
								{
									$('.amount').html('4,458');
								};
							if(salary>=160000 && salary< 165000)
								{
									$('.amount').html('6,666');
								};
							if(salary>=165000 && salary< 170000)
								{
									$('.amount').html('6,875');
								};
							if(salary>=170000 && salary< 175000)
								{
									$('.amount').html('7,083');
								};
							if(salary>=175000 && salary< 180000)
								{
									$('.amount').html('7,291');
								};
							if(salary>=180000 && salary<= 184999)
								{
									$('.amount').html('7,500');
								};
							priceid=62;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=62');
							//popUpDiv4();
						};
						//End of Ring B/w 145000 to 185000
						//Rings Btw 185000 to 200000
						if(salary>=185000)
						{
							$('#PriceSix').css('display','block');
							$('#PriceSix .imgScrolCont img').addClass('imgScrol');
							$('.ringRange').html('&#36; 7,500+')
							if(salary>=185000 && salary< 190000)
								{
									$('.amount').html('7,708');
								};
							if(salary>=190000 && salary< 195000)
								{
									$('.amount').html('7,916');
								};
							if(salary>=195000 && salary< 200000)
								{
									$('.amount').html('8,125');
								};
							if(salary>=200000)
								{
									$('.amount').html('8,333');
								};
							priceid=63;
							$('.viewBudgetBut').attr('href', '/en-US/design-gallery.aspx?categoryid=1&typeid=22&pricerangeid=63');
							//popUpDiv5();
						};
						
						//End of Ring B/w 185000 to 200000
						
						$('p.priceVary').show();
					//	imgScroll();
						
				};
				
			if(salary =='' || salary =='0')
				{
					errorAnnulShow();
				}

	btmGalLoad();

	$('.diffNo a').click(function()
		{
			loaddggallery();
			errorAnnulHide();
			errorSalHide();
		//	imgcntr=0;
		//	$(".leftImgContainer .nxtBudget").unbind('click');
		//	$(".leftImgContainer .prvBudget").unbind('click');
		//	$(".leftImgContainer img.prvImg").removeClass('prvImg').css('display','none');
		//	$(".leftImgContainer img.current").removeClass('current').css('display','none');
			$('.galCalContainerDetails').hide();
			$('#SalTxt').val('');
			$('.galCalContainer').show();
			$('.engRingAll').show();
			$('.engRing').css('display','none');
			$('#PriceOne, #PriceTwo, #PriceThree, #PriceFour, #PriceFive, #PriceSix').css('display','none');
			$('.imgScrolCont img.imgScrol').removeClass('imgScrol');
			$('p.priceVary').hide();
		});
	
}
/*var imgcntr=0;
function imgScroll(){
	var chkfirst=0;
	$(".imgScrolCont img.imgScrol").each(function ()
	{
		if(chkfirst == 0)
		{
			$(this).css('display','block');
			$(this).addClass('current');
			chkfirst++;
		}
	});
	if($(".imgScrolCont img.imgScrol").length > 1)
	{
		if(imgcntr == 0)
		{
			$(".leftImgContainer .nxtBudget").css('display','block');
			$(".leftImgContainer .nxtBudget").click(function ()
			{
				if((imgcntr+1) < $(".imgScrolCont img.imgScrol").length)
				{
					$(".leftImgContainer .prvBudget").css('display','block');
					$(".imgScrolCont img.current").css('display','none');
					$(".imgScrolCont img.prvImg").removeClass('prvImg');
					$(".imgScrolCont img.current").removeClass('current').addClass('prvImg');
					$(".imgScrolCont img.prvImg").next().addClass('current');
					$(".imgScrolCont img.current").fadeIn('slow');
					imgcntr++;
					if((imgcntr+1) == $(".imgScrolCont img.imgScrol").length)
					{
						$(this).css('display','none');
					}
				}
			});
			$(".leftImgContainer .prvBudget").click(function ()
			{
				if(imgcntr > 0)
				{
					$(".leftImgContainer .nxtBudget").css('display','block');
					$(".imgScrolCont img.current").css('display','none');
					$(".imgScrolCont img.prvImg").removeClass('prvImg');
					$(".imgScrolCont img.current").removeClass('current').addClass('prvImg');
					$(".imgScrolCont img.prvImg").prev().addClass('current');
					$(".imgScrolCont img.current").fadeIn('slow');
					imgcntr--;
					if(imgcntr == 0)
					{
						$(this).css('display','none');
					}
					
				}
			});
		}
	}
}

function popUpDiv1(){
	$('#secure').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#securePop').slideDown('fast');
			getid('securePop').style.left=(Number(cordinates[0])+10)+'px';
			getid('securePop').style.bottom=(Number(cordinates[1])+70)+'px';
		})
	.mouseleave(function()
		{
			$('#securePop').slideUp('fast');
		});
	
	$('#rare').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#rarePop').slideDown('fast');
			getid('rarePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('rarePop').style.bottom=(Number(cordinates[1])+15)+'px';
		})
	.mouseleave(function()
		{
			$('#rarePop').slideUp('fast');
		});
	
	$('#durable').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#durablePop').slideDown('fast');
			getid('durablePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('durablePop').style.bottom=(Number(cordinates[1])-82)+'px';
		})
	.mouseleave(function()
		{
			$('#durablePop').slideUp('fast');
		});
}

function popUpDiv2(){
	$('#secure2').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#securePop').slideDown('fast');
			getid('securePop').style.left=(Number(cordinates[0])+10)+'px';
			getid('securePop').style.bottom=(Number(cordinates[1])+206)+'px';
		})
	.mouseleave(function()
		{
			$('#securePop').slideUp('fast');
		});
	
	$('#rare2').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#rarePop').slideDown('fast');
			getid('rarePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('rarePop').style.bottom=(Number(cordinates[1])-136)+'px';
		})
	.mouseleave(function()
		{
			$('#rarePop').slideUp('fast');
		});
	
	$('#durable2').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#durablePop').slideDown('fast');
			getid('durablePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('durablePop').style.bottom=(Number(cordinates[1])+90)+'px';
		})
	.mouseleave(function()
		{
			$('#durablePop').slideUp('fast');
		});
}

function popUpDiv3(){
	$('#secure3').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#securePop').slideDown('fast');
			getid('securePop').style.left=(Number(cordinates[0])+10)+'px';
			getid('securePop').style.bottom=(Number(cordinates[1])+195)+'px';
		})
	.mouseleave(function()
		{
			$('#securePop').slideUp('fast');
		});
	
	$('#rare3').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#rarePop').slideDown('fast');
			getid('rarePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('rarePop').style.bottom=(Number(cordinates[1])-78)+'px';
		})
	.mouseleave(function()
		{
			$('#rarePop').slideUp('fast');
		});
	
	$('#durable3').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#durablePop').slideDown('fast');
			getid('durablePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('durablePop').style.bottom=(Number(cordinates[1])-85)+'px';
		})
	.mouseleave(function()
		{
			$('#durablePop').slideUp('fast');
			
		});
}

function popUpDiv4(){
	$('#secure4').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#securePop').slideDown('fast');
			getid('securePop').style.left=(Number(cordinates[0])+10)+'px';
			getid('securePop').style.bottom=(Number(cordinates[1])+145)+'px';
		})
	.mouseleave(function()
		{
			$('#securePop').slideUp('fast');
		});
	
	$('#rare4').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#rarePop').slideDown('fast');
			getid('rarePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('rarePop').style.bottom=(Number(cordinates[1])-58)+'px';
		})
	.mouseleave(function()
		{
			$('#rarePop').slideUp('fast');
		});
	
	$('#durable4').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#durablePop').slideDown('fast');
			getid('durablePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('durablePop').style.bottom=(Number(cordinates[1])-10)+'px';
		})
	.mouseleave(function()
		{
			$('#durablePop').slideUp('fast');
			
		});
}

function popUpDiv5(){
	$('#secure5').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#securePop').slideDown('fast');
			getid('securePop').style.left=(Number(cordinates[0])+10)+'px';
			getid('securePop').style.bottom=(Number(cordinates[1])+145)+'px';
		})
	.mouseleave(function()
		{
			$('#securePop').slideUp('fast');
		});
	
	$('#rare5').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#rarePop').slideDown('fast');
			getid('rarePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('rarePop').style.bottom=(Number(cordinates[1])-30)+'px';
		})
	.mouseleave(function()
		{
			$('#rarePop').slideUp('fast');
		});
	
	$('#durable5').mouseenter(function(e)
		{
			var cordinates=$(this).attr('coords').split(",");
			$('#durablePop').slideDown('fast');
			getid('durablePop').style.left=(Number(cordinates[0])+5)+'px';
			getid('durablePop').style.bottom=(Number(cordinates[1])-123)+'px';
		})
	.mouseleave(function()
		{
			$('#durablePop').slideUp('fast');
			
		});
}
*/
function errorSalShow(){
	errorAnnulHide();
	$('#SalNotMatch').css('display','block');
}

function errorSalHide(){
	$('#SalNotMatch').css('display','none');
}

function errorAnnulShow(){
	errorSalHide();
	$('#enterAnnualSal').css('display','block');
}

function errorAnnulHide(){
	$('#enterAnnualSal').css('display','none');
}

function btmGalLoad(){
	url='/'+langname+'/include/DGLoadProducts.aspx?LanguageID='+langid;
	if(postparams=='')
	{
		newcall='<item categoryid="1" typeid="22" />'
		postparams='<designGallery Result="Success" PriceRange="'+priceid+'">'+newcall+'</designGallery>';
	}
	loaddggallery();
}
