/*
 * @version 1.0
 * function of developer
 */
// Store Locator page
// Store Locator page
var is_authenticated = false;
function checkforms(formid)
{
	var vsize = parseInt($("#selectss_2").val())
	if (vsize <=0 || vsize=="" || $('#codehethangroi').length <=0)
	{
		$("#selectss_2").addClass("error");
		alert("Please select a size");							
		//$('#selectss_2').jAlert('Please select a size', "warning");
		return false;
	}
	return true;
}
function ratinginit(tem_score,readonly)
{
	is_authenticated =  DISQUS.jsonData.request.is_authenticated;
	if (!is_authenticated) readonly = false;	
	$('#productvote').html("");	
	$('#productvote').raty({
		start: tem_score,
		readOnly:readonly,
		path: 'js/rating/',
		starOn: 'star-on.png',
		starOff: 'star-off.png',
		disabled: !is_authenticated?true:false,
		click: function (score) {							
			if (!is_authenticated)
			{
				ratinginit(tem_score, readonly);				
				DISQUS.dtpl.actions.fire('auth.login');										
			}
			else
			{
				$.post(siteUrl + "do_ajax", { "op": "ajax","act": "product_vote", "score": score, "productid": $("#products_id").val(),"is_authenticated":is_authenticated }, function (result) {
					readonly = false;																																														
					if (result>=1){	
						readonly = true;
						var new_score = parseInt($("#rvalue").val())+parseInt(score);
						var new_vote =  parseInt($("#vvote").val())+1;
						var tem_score = Math.round(new_score/new_vote);
						$(".totalvote").html(new_vote<=0?"":"(Based on "+new_vote+" "+(new_vote>=2?"votes)":"vote)"));																																															
					}
					ratinginit(tem_score, readonly);																																									
				});
			}			
		}
	});
}
function rating(sscore) {	
	var readonly = false;	
	$('#productvote').html("");
	is_authenticated =  DISQUS.jsonData.request.is_authenticated;
	if (!is_authenticated) readonly = false;	
	else if ($('#productvote').hasClass("readonly")) readonly = true;		
	$('#productvote').raty({
		start: sscore,
		readOnly:readonly,
		path: 'js/rating/',
		starOn: 'star-on.png',
		starOff: 'star-off.png',
		disabled: !is_authenticated?true:false,
		click: function (score) {							
			if (!is_authenticated)
			{				
				ratinginit(sscore, readonly);			
				DISQUS.dtpl.actions.fire('auth.login');					
				
			}
			else
			{
				$.post(siteUrl + "do_ajax", { "op": "ajax","act": "product_vote", "score": score, "productid": $("#products_id").val(),"is_authenticated":is_authenticated }, function (result) {
					readonly = false;																																														
					if (result>=1){	
						readonly = true;
						var new_score = parseInt($("#rvalue").val())+parseInt(score);
						var new_vote =  parseInt($("#vvote").val())+1;
						var tem_score = Math.round(new_score/new_vote);
						$(".totalvote").html(new_vote<=0?"":"(Based on "+new_vote+" "+(new_vote>=2?"votes)":"vote)"));						
						if (tem_score<=0)
							tem_score = sscore;																																					
					}
					ratinginit(tem_score, readonly);
				});
			}			
		}
	});
}
function changeprices()
{
	var colorid = $('input[name=id[3]]:checked').val();
	var sizeid =  $('#selectss_2').val();
	var products_id = $('#products_id').val();
	if (sizeid >0 && colorid >0)
	{
		$('#btnBuy').attr("disabled","disabled");
		$('#btnSoldOut').attr("disabled","disabled");
		$('#selectss_2').removeClass("error");
		$.post(siteUrl+"do_ajax", { act: "changeprice", op: "ajax", "sizeid":sizeid,"colorid":colorid, "products_id":products_id},
		function(data){						
				var obj = JSON.parse(data);
				if (obj.price!="")
				{
					$("#newspricess").html(obj.price);
				}
				if (obj.price_old!="")
				{
					$("#oldPrice").html(obj.price_old);
				}
				if ($('#codehethangroi').length){ 		
					$("#codehethangroi").val(obj.soldOutPrice);
				}
				else
				{
					$('body').append('<input type="hidden" id="codehethangroi" name="codehethangroi" value="'+obj.soldOutPrice+'" />');
				}
				if (obj.soldOutPrice==1 || $("#codehethangroi").val()==1 || $("#codehethangroi").val()=="1")
				{					
					$('#btnSoldOut').attr("disabled","");
					$("#btnBuy").hide();
					$("#btnSoldOut").show();
				}
				else
				{
					$('#btnBuy').attr("disabled","");
					$("#btnSoldOut").hide();
					$("#btnBuy").show();
				}
		});	
	}
}
function ClickProducts(id, flag)
	{
		$(".subcategory"+flag).hide();
		$(".categroym"+flag).removeClass("active");
		$("#category_"+id).show();	
		$("#categroym_"+id).addClass("active");
	}
function ShowTab(clasname)
{				
	$(".guideInfo").removeClass("show");
	$(".guideInfo").addClass("hiden");
	$(".guideInfo").hide();
	$("."+clasname).show();
	$(".tabs_show").removeClass("active")
	$("#"+clasname).addClass("active");
}
function showabut_us(id)
{	
	$(".tabsclick").removeClass("active");	
	$(".contentss").hide();	
	$("#tabsclick_"+id).addClass("active");	
	$("#tabcontent_"+id).show();
	$('.tabcontent').jScrollPane();
}
function showTabsProducts(id)
{
	$(".tabsclick").removeClass("active");	
	var strhtml = $("#tabs_"+id).html();	
	$("#tabs_0").html(strhtml);
	$(".tabsclick_"+id).addClass("active");	
	$('.tabsCt-a').jScrollPane();
	
}
function preLoadEffect()
{
	$('.navSub').css({ width: getDocumentSize(0)-255});
	
	$(function()
	{
		$('.tabsCt-a').jScrollPane();
	});	
	var options = {
		zoomWidth: 360,
		zoomHeight: 360,
		xOffset: 10,
		yOffset: -13,
		position: "right"
	};
	$('.zoom').jqzoom(options);
	$('.pirobox_content').remove();
	$().piroBox({
		my_speed: 400,
		bg_alpha: 0.5,
		slideShow : false,
		slideSpeed : 4, 
		close_all : '.piro_close,.piro_overlay'	
	});
}

function changecolor(PidVid)
{
	if (PidVid.length >0)
	{		
		//$('#loading').show();
		var strListid = "";
		 $("#selectss_2 option").each(function () {
				if ($(this).val() >0)									
	                strListid += $(this).val() + ",";
         });
		$('#btnBuy').attr("disabled","disabled");
		$('#btnSoldOut').attr("disabled","disabled");
		$.post(siteUrl+"do_ajax", { act: "changecolor", op: "ajax","productid_vid":PidVid,"strListid":strListid},
		function(data){		
			var obj = JSON.parse(data);
			if (obj.status==1 && obj.MesaageString!="")
			{
				$('input:radio[name=id[3]]').attr('checked',false);				
				$("input[name='id[3]']:radio").filter( "[value='"+obj.opvid+"']" ).attr( "checked", "checked" ); 
				
				$("#productDSlider").html(obj.MesaageString);			
				$(".changecolor").removeClass("color_active");
				$("#"+PidVid).addClass("color_active");																					
				if($('#codehethangroi').length){ 		
					$("#codehethangroi").val(obj.soldOutColor);
				}
				else
				{
					$('body').append('<input type="hidden" id="codehethangroi" name="codehethangroi" value="'+obj.soldOutColor+'" />');
				}									
				$('#selectss_2').attr("disabled","");
				if ($("#codehethangroi").val()==1 || $("#codehethangroi").val()=="1")
				{				
					$('#btnSoldOut').attr("disabled","");
					$('#selectss_2').attr("disabled","disabled");
					$("#btnBuy").hide();
					$("#btnSoldOut").show();
				}
				else
				{
					changeprices();
					$("#btnSoldOut").hide();
					$('#btnBuy').attr("disabled","");
					$("#btnBuy").show();					
				}
				preLoadEffect();
			}
			//$('#loading').hide();
		});	
	}
}
function shareLink(Provider, Url)
{
	Url = encodeURIComponent(Url);
	var title = $("#cart_quantity h1.font").text();
	switch(Provider)
	{
		case 'facebook':
			window.open('http://facebook.com/share.php?u='+Url+'&t='+encodeURIComponent(title)+'');
		break;
		case 'twitter':
			window.open('http://twitter.com/share?url='+Url+'&text='+encodeURIComponent(title)+'');
		break;
		case 'delicious':
			window.open('http://del.icio.us/post?url='+Url+'&title='+encodeURIComponent(title)+'');
		break;
	}	
}
function ChangeProducts(pid)
{
	//$('#loading').show();
	if (pid=="0") return; 
	$.post(siteUrl+"do_ajax", { act: "changeProducts", op: "ajax","pid":pid},
	function(data){		
		var obj = JSON.parse(data);
		if (obj.productslist!="" && obj.products_infor!=""){
			$("#productDetail_l11").html(obj.productslist);
			$(".bg_prev").removeClass("first");
			$(".bg_next").removeClass("last");
			$("#productDInfo").html(obj.products_infor);
			Cufon.replace('.font');			
			preLoadEffect();
			$('title').text(obj.title);	
			if (!$.browser.msie ) {
				$.address.value(obj.url);
			}
			/*$.ajax({
				 type: "GET",
				 url: "http://" + disqus_shortname + ".disqus.com/embed.js",
				 dataType: "script",
				 cache: true
			});*/
			/*DISQUS.reset({
			  reload: true,
			  config: function () {  
				this.page.identifier = disqus_identifier;  
				this.page.url = disqus_url;
			  }
			});*/
		}		
		//$('#loading').hide();
	});	
}
function PostContact()
{
	if ($("#txtfirstname").val()!="" && $("#txtemail").val()!="")
	{
		//$('#loading').show();
		$.post(siteUrl+"contact", { act: "submitcontact", op: "ajax", 
				"txtfirstname":$("#txtfirstname").val(),
				"txtlastname":$("#txtlastname").val(),
				"txtemail":$("#txtemail").val(),
				"txtconfirmemail":$("#txtconfirmemail").val(),
				"txtphone":$("#txtphone").val(),
				"txtmobile":$("#txtmobile").val(),
				"selsubject":$("#selsubject :selected").text(),
				"txtOrdernumber":$("#txtOrdernumber").val(),
				"txtmessage":$("#txtmessage").val()},
		function(data){		
			var obj = JSON.parse(data);
			if (obj.status==1 && obj.MesaageString!="")
			{
				$("#msgThank").html("<h3>"+obj.MesaageString+"</h3>");
				$("#msgThank").show();
				$('#formcontact')[0].reset();

			}
			//$('#loading').hide();
		});	
	}
}
