// JavaScript Document
/******************* home slider *************************/
$(document).ready(function(){	
		$("#slider").easySlider({
			auto: true, 
			continuous: true
		});
		$("#slider2").easySlider({ 
				auto: true, 
				prevId:'prevBtn2',
				nextId:'nextBtn2',	
				speed: 	1000,
				pause:	3000,
				continuous: true
		});
		
		$("#slider_related").easySlider({
			auto: false, 
			continuous: true
		});
	});	



//****************** home bottom code *******/
/*function setAllProductDetailDiv()
{

var prd_detail = document.getElementsByClassName("title_listing");
var height=0;
for(var i=0;i<prd_detail.length;i++){
if(parseInt(height) < parseInt(prd_detail[i].clientHeight)) {
height = prd_detail[i].clientHeight;

}
}
for(i=0;i<prd_detail.length;i++){

prd_detail[i].style.height=height+"px";
}
}


function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(setAllProductDetailDiv);

*/



function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}
function checkStrLen(txtObj,minLength,MaxLength,msgDisplay)
{
var strData;
strData=txtObj.value;
//alert(strData.length);
if(strData.length < Number(minLength))
{
    alert("Please Enter Valid Value In The Following Field : " + msgDisplay);
    txtObj.focus();
    return false;
}
if(strData.length > Number(MaxLength))
{
    alert("Please Enter Value Lesser Than " + MaxLength +" In The Following Field : " + msgDisplay);
    txtObj.focus();
    return false;

}
}

/************************* Newsletter Submit ************************/

function resetForm(id) {
	$('#'+id).each(function(){
        this.reset();
	});
	
}

var edit_profile_con = {
        target:        '#newsletter',   // target element to update
        beforeSubmit:  showRequestEP,  // pre-submit callback
        success:       showResponseEP_con  // post-submit callback
    };
	
var testimonial_con = {
        target:        '#testimonial_cnt_id',   // target element to update
        beforeSubmit:  showRequestEP,  // pre-submit callback
        success:       showResponseTS_con  // post-submit callback
    };
	
var comment_con = {
        target:        '#comment_form_id',   // target element to update
        beforeSubmit:  showRequestEP,  // pre-submit callback
        success:       showResponseCM_con  // post-submit callback
    };
		
	
function fEditProfile_con() {
	$("form#newsletter_form").ajaxSubmit(edit_profile_con);
	return false;
}

function fTestimoniale_con() {
	$("form#testimonial_form").ajaxSubmit(testimonial_con);
	return false;
}

function fComment_con() {
	$("form#comment_form").ajaxSubmit(comment_con);
	return false;
}


// pre-submit callback 
function showRequestEP(formData, jqForm, options) { 
    return true; 
} 

function showResponseEP_con(responseText, statusText)  { 
	resetForm('newsletter_form');
	$("#lbl_contus").fadeOut(30000);
	
}

function showResponseTS_con(responseText, statusText)  { 
	resetForm('testimonial_form');
	$("#lbl_contus").fadeOut(30000);
}

function showResponseCM_con(responseText, statusText)  { 
	resetForm('comment_form');
	$("#lbl_contus").fadeOut(30000);
}





/**********************  check *******/

function check_stock_value(id){
	if($('#'+id).val()==''){
		alert("Please Enter Quantity of Product.");
		return false;
	}
	if(isNumeric($('#'+id).val())==false){
		alert("Please Enter Numeric Value.");	
		return false;
	}
	return true;
}

function isNumeric(value) {
  if (value != null && !value.toString().match(/[0-9]/)){
   	return false;
  }
  return true;
}


/*
function updatePriceValue(opt_val,newurl){
	var optionval=$(opt_val).val();
	var option=$(opt_val).attr('id');
	
	alert(option);
	var prod_id=$('#txtProductsId').val();
	$.ajax({ 
		  type: "POST", 
		  url: newurl+"products/update_priceValue",
		  data: "option="+option+"&optionval="+optionval+"&prod_id="+prod_id,
		  success: function(msg){	
		  	$('div#prc_span_tag').html(msg);
		  } 
	});
}*/
function updatePriceValue(tot,newurl){
	var optionPrice=new Array();
	var optionWeight=new Array();
	for(i=1;i<=tot;i++){
		if($("#option_"+i+" option:selected").val()!=''){
			option_id=$("#option_"+i+" option:selected").val();
			optionPrice[i]=$('#optionattrpri'+option_id).val();
			optionWeight[i]=$('#optionattrwei'+option_id).val();
		}
	}
	originPrice=$("#originprice").val();
	originweight=$("#originweight").val();
	
	$.ajax({ 
		  type: "POST", 
		  url: newurl+"products/update_priceValue",
		  data: "optionPrice="+optionPrice+"&optionWeight="+optionWeight+"&prod_price="+originPrice+'&prod_weight='+originweight,
		  success: function(msg){	
		  	$('div#prc_span_tag').html(msg);
		  } 
	});
}

function provinceUpdateCode(live_url,fr_url){
	$("select#country_list_reg").change(function(){
				var selected = $(this).val();
				ajax_loading_image('label#ajax_img',fr_url);
				$.ajax({
					type: "POST",
					url:live_url ,				
					data: "ajax=true&id="+selected,						
					success: function(msg){
						$('div#product_cat').html(msg);
						ajax_remove_loading_image('label#ajax_img');
					}
				});
		})		
}


// set a loading image
function ajax_loading_image(div,fr_url) {
	$(div).html('<img src="'+fr_url+'75.gif" alt="Image Loader" title="Image Loader" />');
}

// remove loading image
function ajax_remove_loading_image(div) {
	$(div).html('');
}
// cart display 


function SubmitForm()
{
	var eleQty;
	eleQty=document.getElementById("txtQty");
	for(i=0;i<eleQty.length;i++){
		if(eleQty[i].value == ""){
			alert("Please Select Quantity.");
			eleQty[i].focus();
			return false;
		}else if(isNumeric(eleQty[i].value)==false){
			alert("Please Enter Numeric Value.");
			eleQty[i].focus();
			return false;
		}
	}
	document.cart.submit();
}

// display shipping 


function chk_selection(){
var ele;
ele=document.getElementsByName('val_sel');
var total=0;
for(i=0;i<ele.length;i++){
	if(ele[i].checked){
		total++;
	}
}
if(total<=0){
	alert("Please Select Shipping Service");
	return false;
}else{
	return true;
}
}


// order history


function confirm_del(id)
{
if(!window.confirm("Do you Really Want To Delete this Order : "+ id + " ?")){
	return false;
}else{
	return true;
}	
}



// confirm shippping address 
function default_addresschange(ad_id,ad_url){
	var selected = $(ad_id).val();
	ajax_loading_image('label#ajax_img');
	$.ajax({
			type: "POST",
			url:ad_url+'carts/update_shipping_address/',				
			data: "ajax=true&id="+selected,						
			success: function(msg){
				window.location = ad_url+'carts/display_shipping/';
				//$('div#change_shipping_add').html(msg);
				//ajax_remove_loading_image('label#ajax_img');
			}
		});

}
// distributer page validation

function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
var verification =document.getElementById("verification");
if(verification.value != "12" || verification.value == '') {
		alert("Plese Enter Valid verification Answer.");
		return false;
	}
return true;
}

function checkCombo(cmbObject,defaultValue,msgDisplay)
{
var strData;
strData=cmbObject.value;
if(strData == defaultValue)
{
    alert("Please Select Appropriate Option from the  Following Field : " + msgDisplay);
    cmbObject.focus();
    return false;
}
}

function checkcomboOption(cnt,oForm,defaultValue){
var flag=0;
    for(i=1;i<=cnt;i++){
     var opt=document.getElementById('option_'+i);
      var nameval=opt.value;
      if(nameval == defaultValue)
      {
      
       flag=1;
      }
    }
    if(flag==1){
    alert("Please Select Appropriate Option");
     return false;   
    }else{
      if($('#txtQty').val()==''){
        alert("Please Enter Quantity of Product.");
        return false;
    }
    if(isNumeric($('#txtQty').val())==false){
        alert("Please Enter Numeric Value.");    
        return false;
    }
    }
}
