// prefect float number
function rdec(number){
	var newnumber = new Number(number+'').toFixed(parseInt(2));
	return parseFloat(newnumber);
}
// page moving link

function move_to_prod_page(url){
	location.href=url;
}

// check the login function
function checkLogin()  {
	if(document.getElementById('username').value=='') {
		document.getElementById('errmessage').style.display="block";
		document.getElementById('errmessage1').style.display="none";
		return false;
	} else if(document.getElementById('password').value=='') {
		document.getElementById('errmessage1').style.display="block";
		document.getElementById('errmessage').style.display="none";
		return false;
	} else {
		document.getElementById('errmessage1').style.display="none";
		document.getElementById('errmessage').style.display="none";
		return true;
	}
}

// menu tab
function menuTabLogin(clickedId) {
	if(clickedId == 'bidded') {		
		$('#' + clickedId).removeClass('banner-left-but').addClass('banner-left-but-index2');
		$('#login').removeClass('banner-left-but-index2').addClass('banner-left-but');
		$('#banner-right').hide();
		$('.bidhistory').show();
		$('#lastbid').show();
		$('#loginBox').hide();
	} else {
		$('#' + clickedId).removeClass('banner-left-but').addClass('banner-left-but-index2');
		$('#bidded').removeClass('banner-left-but-index2').addClass('banner-left-but');
		$('#banner-right').show();
		$('.bidhistory').hide();
		$('#lastbid').hide();
		$('#loginBox').show();
	}
}

function menuTab(clickedId) {
	if(clickedId == 'pinned') {
		$('#' + clickedId).removeClass('banner-left-but').addClass('banner-left-but-index2');
		$('#bidded').removeClass('banner-left-but-index2').addClass('banner-left-but');
		$('#banner-right-index1').hide();
		$('#votingprod').hide();
		$('#votetoplist').show();
		setCookie( 'myTab', 'pinned', '1', '/', '', '' );
		getPinnedListResults(PINNED_LOADER_URL);
	} else if(clickedId == 'bidded') {
		$('#' + clickedId).removeClass('banner-left-but').addClass('banner-left-but-index2');
		$('#pinned').removeClass('banner-left-but-index2').addClass('banner-left-but');
		$('#banner-right-index1').show();
		$('#votetoplist').hide();
		$('#votingprod').hide();
		setCookie( 'myTab', 'bidded', '1', '/', '', '' );
	} else {
		$('#banner-right-index1').hide();
		$('#votetoplist').hide();
		$('#votingprod').show();
	}
}

function changeMouseOver(opt){
	if(opt==1)
		document.getElementById("LeftSideBidButton").className =  "bidbuttonview";
	else
		document.getElementById("LeftSideBidButton").className =  "bidbuttonoutview";
}

function getMyPageInfo(url,type) {
	
	var pid = $("#pid").val();
	if(type==1){
		$('#pagiOne').addClass('active');
		$('#pagiTwo').removeClass('active');
		$('#pagiThree').removeClass('active');
	} else if(type==2){
		$('#pagiTwo').addClass('active');
		$('#pagiOne').removeClass('active');
		$('#pagiThree').removeClass('active');
	} else if(type==3){
		$('#pagiThree').addClass('active');
		$('#pagiOne').removeClass('active');
		$('#pagiTwo').removeClass('active');
	}

	$("#allData").html("<center><img vspace='60' src='" + FRONT_IMAGE_PATH + "ajax-loader.gif' title='Loading' alt='Loading' /></center>");
	
	// ajax query code for replaceing the div content to the product details page
	$.ajax({
		url: url,
		type: "POST",
		data: "&productId=" + pid + "&type=" + type,
		success: function(response)	{
			document.getElementById('allData').innerHTML = response;
			$("#allData").html(response);
		}
	});
}

// my hammer products in my account poage
function myajaxhidproduct1(url,auctionId,divId) {
	menuTab('bidded');
	$('#AHidId').val(auctionId);

	document.getElementById('messagedetails').innerHTML = '';
	$.ajax({url: url,
		type: "POST",
		success: function(response) {				
			var result	= eval('(' + response + ')');				
			$(".CAuctHid").removeAttr('src');
			$(".CAuctHid").attr('src', FRONT_IMAGE_PATH + 'AuctionHammer.jpg');
			$("#aucthis_"+auctionId).attr('src', FRONT_IMAGE_PATH + 'AuctionHammer-selected.jpg');
		}
	});
}
// unpinned auctions for myaccont page 

// buttonb=n change script in store page
function changebuybutton(opt,myprodid){
 	var butid = "mybutt_"+myprodid;
 	if(opt==1){
		document.getElementById(butid).className="buybutt";
	}
	else{
		document.getElementById(butid).className="buybuttchg";
	}
 }

// product details page made offer vaildation functions 1 
function getEPPrices() {
	
	var epnumber = parseFloat(document.getElementById('order_ep').value);
	var rt 		 = parseFloat(document.getElementById('retail').value);
	var epoints_user = parseFloat(document.getElementById('epoints_user').value);
	var remnumber = parseFloat(epnumber / 100);
	remnumber = Math.floor(remnumber*100)/100
	var number = rt - remnumber;
	number = Math.floor(number);
	
	if(epnumber != ""){
		if(isNaN(epnumber)==false) {
			if( epnumber > epoints_user ) {
				alert("Enter less than electronic points..");
				document.getElementById('epnumberdisp').innerHTML	=	"Enter Number Less Retail";
				document.getElementById('order_ep').value			= 	'';
				document.getElementById('order_user_price').value	=	'';
				document.getElementById('epnumberdisp').innerHTML	=	"Cost Cutting Amount Is 0 $";
				document.getElementById('order_ep_value').value		=	'';
				return false
			}
			document.getElementById('epnumberdisp').innerHTML="Cost Cutting Amount Is "+number+" $ ";
			document.getElementById('order_ep_value').value=number;
		} else{
			alert("Enter Number")
			document.getElementById('order_ep_value').value="";
			document.getElementById('order_ep').value='';
			return false;
		}
	}
}

// product details page made offer vaildation functions 2
function getEPValue() {
	
	var myNum =  document.getElementById('order_ep_value').value;
	
	var nnum = myNum.split(".");
	if(nnum[1]>=99){
		document.getElementById('order_ep_value').value='';
		document.getElementById('order_ep').value='';
		alert("Number After Decimal upto 2 digits allowed")
		return false;
	}
	
	
	var epnumber = (document.getElementById('order_ep_value').value);
	var rt = parseFloat(document.getElementById('retail').value);
	var remainamount = rt - epnumber;
	
	remainamount = Math.floor(remainamount);
	
	var number = remainamount * 100;
	
	if(epnumber != "") {
	 if(isNaN(epnumber)==false) {
		 	epnumber = parseFloat(epnumber);

			if(epnumber > rt) {
				alert("Enter Less Than Retail Value");
				document.getElementById('epnumberdisp').innerHTML = "Enter number less retail ";
				document.getElementById('order_ep').value='';				
				document.getElementById('order_user_price').value='';
				document.getElementById('epnumberdisp').innerHTML = "Cost Cutting Amount Is 0 $ ";
				document.getElementById('order_ep_value').value=0;
				return false;
			}
			//document.getElementById('order_ep_value').value=number;
			document.getElementById('epnumberdisp').innerHTML = "Cost Cutting Amount Is " + number + " $ ";
			if(number != 'NaN')
				document.getElementById('order_ep').value=number;
	} else {
		alert("Enter the number");
		document.getElementById('order_ep_value').value="";
		document.getElementById('order_ep').value='';
		return false;
	}
	}
}

function Countrystates(url,cid,state) {

	$(document).ready(function() {
	 
		  if(cid){
			var country=cid;
		  }else{
			var country=$("#country").val();
		  }
		  
		  if(state){
			var urlpath=url+country+'/'+state;
		  }else{
			var urlpath=url+country;
		  }

		  $.ajax({
				url    :urlpath,
				method :'post',
				success:function(data) {
					  $("tr#states").show();
					  $("#state1").hide();
					   if(data=="nodata"){
						 $("#state").hide();
						 $("#state1").show();
					   } else{
						 $("#state").show();
						 $("#state").html(data);
					   }
					   $('#errMessage').hide();
				  }
			});
		});
   	}
   
	function loginOverEffect(id) {
		if(document.getElementById(id).innerHTML=='Bid') {
			document.getElementById(id).innerHTML="Login";
			document.getElementById(id).className="font4";	
		} else {
			document.getElementById(id).innerHTML="Bid";
			document.getElementById(id).className="font3";			
		}
	}
	/* function to redirect to payment page */
	function dopaymentneedpay(pri,typ,id,name,winner_id,offerid,orgamt) {
		
		document.getElementById('orgamt').value  	= orgamt;	
		document.getElementById('amount').value  	= pri;
		document.getElementById('type').value  	 	= typ;
		document.getElementById('pid').value  	 	= id;
		document.getElementById('winner_id').value  = winner_id;
		document.getElementById('pname').value  	= name;
		document.getElementById('offerid').value    = offerid;
		document.paynow.submit(true);
	}
	/* function to redirect to payment page */
	function dopayment(pri,typ,id,name,winner_id,offerid) {
		document.getElementById('amount').value  	= pri;
		document.getElementById('type').value  	 	= typ;
		document.getElementById('pid').value  	 	= id;
		document.getElementById('winner_id').value  = winner_id;
		document.getElementById('pname').value  	= name;
		document.getElementById('offerid').value    = offerid;
		
		document.paynow.submit(true);
	}


function CheckRegisterValidate(urlpath) {
	$("#signupForm1").validate({
			rules: {
			rusername:"required",
			zipcode:'number',
			city: "required",
			email: "required",
			
			rusername: {
				required: true,
				minlength: 5,
				maxlength: 60,
				usernameCheck: true
			},
			email: {
				required: true,
				minlength: 2,
				maxlength: 60,
				email:true
			},	
			
			country: {
              selectNone: true
			},	
			 security_code: {
				required: true,
				captchaCheck:true
			},
			rpassword: {
				required: true,
				minlength: 5
				
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#rpassword"
			}		
		},
		messages: {
			rusername: {
				required: "Please enter your User Name",
				minlength: "Your User Name must be minimum of 5 characters",
				maxlength: "Your User Name must be 60 characters only",
				usernameCheck: "This User Name is already in use."
			},
			
			email: {
			 required: "Please enter a valid Email Address",
			 minlength: "Your Username must consist of at least 2 characters",
			 maxlength: "Your Username must be 60 characters only"
			},	
				
			rpassword: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long"
			},
			
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				equalTo: "Please enter the same password as above"
			},
			
			city: {
				required: "Please enter your City",
				maxlength: "Your City Name must be 50 characters only"
			},
			
			security_code: {
				required: "Please enter Word Verification",
				captchaCheck:"involid secure code"
			},
			
			zipcode: {
				required: "Please enter your valid Zip Code",
				maxlength: "Your Postal Code must be 10 digits only"
			},

			country: {
				selectNone: "Please  select your Country"
			}				
		}
		
	});
}

// refresh captcha
function refreshcaptcha() {
	document.getElementById('captcha_secure').src = HTTP_URL+"/member/captcha/"+Math.random();
}

function DrawCaptcha() {
	var a = Math.ceil(Math.random() * 10)+ '';
	var b = Math.ceil(Math.random() * 10)+ '';       
	var c = Math.ceil(Math.random() * 10)+ '';  
	var d = Math.ceil(Math.random() * 10)+ '';  
	var e = Math.ceil(Math.random() * 10)+ '';  
	var f = Math.ceil(Math.random() * 10)+ '';  
	var g = Math.ceil(Math.random() * 10)+ '';  
	var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
	document.getElementById("txtCaptcha").value = code
}

function checkEmail(val) {
   if(val!="") {
	   $("#uerrmessage").hide();
   }
}
 
function checkPassword(val) {
	if(val!="") {
	   $("#errmessage1").hide();
	}
}

function checkMail(val) {
	if(val!="") {
	   $("#errmessage").hide();
	} else {
	  document.getElementById('errmessage').display="block";
	}
}

function checkLoginEmpty() {
	if(document.getElementById('username').value=='') {
		document.getElementById('errmessage').style.display="block";
		return false;
	} else {
		document.getElementById('errmessage').style.display="none";		
	}

	if(document.getElementById('password').value=='') {
		document.getElementById('errmessage1').style.display="block";
		return false;
	} else {
		document.getElementById('errmessage1').style.display="none";		
	}
	return true;
}

function ValidateNumberKeyPress(field, evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
   var keychar = String.fromCharCode(charCode);
   if ((charCode > 32) && (charCode != 118) && (charCode != 86) && (charCode < 48 || charCode > 57) && (charCode!=58) && keychar != "."  && keychar != "-" )  {
	   alert("Enter Numbers Only");
	   return false;
   }

   if (keychar == "." && field.value.indexOf(".") != -1)  {
	   return false;
   }
	   
   if(keychar == "-") {
	   if (field.value.indexOf("-") != -1 /* || field.value[0] == "-" */)  {
		   return false;
	   }  else  {
		   var caretPos = getCaretPosition(field);
		   if(caretPos != 0) {
			   return false;
		   }
	   }
   }
   return true;
}

function registrationValidate() {
	$("#signupForm1").validate({
		rules: {
			//email:"required",
			email: {
				required: true,
				email:true
			},
		   rpassword: {
				required: true,
				minlength: 5
	
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#rpassword"
			},
			agree: {
				required: true
			}
		},
		messages: {
		   email:{
			  required:"Please enter your Email"
		   }
		}
	})
}


function biddingbid(auctionId,prodId,btype) {
	
	if(btype == 'slider') {
		var curtime 	= $("#js_dtimer" + auctionId + "_digits").text();
		var aprice 		= $("#jsbid_" + auctionId + "_price").val();
	} else if(btype == 'lview') {
		var curtime 	= $("#laCH_dtimer_digits").text();
		var aprice 		= $("#lbid_price").val();
		var auctionId	= $("#LastAuctionId").val();
	} else {
		var curtime 	= $("#CH_dtimer" + auctionId + "_digits").text();
		var aprice 		= $("#bid_" + auctionId + "_price").val();
		var rprice 		= $("#auction_product_price").val();
		if(rprice==undefined) { rprice = 0; }
	}
	
	if(curtime != 'Going') {
	 var url	      		= HTTP_URL + "loader/biddingAuction";
	 $.ajax({
		url: url,
		type: "POST",
		data: "&curtime=" + curtime + "&auctionId=" + auctionId + "&productId=" + prodId + "&aprice=" +aprice+"&rprice=" + rprice,
		success: function(response) {
			var result	= eval('(' + response + ')');
			if(result.error == 1) {
				if(result.highestbid != 1)
					alert(result.message);
			} else {
				
					if(result.endstatus==1) {
						$('#bidbutbuy'+auctionId).css("display", "none");
						$('#bidbutsold'+auctionId).css("display", "block");
					}
					
				/* begin - Jsbidding */
					$('#jsbiddername' + auctionId).text(result.biddername);
					$('#jsbid_' + auctionId + '_price').val(result.historyprice);
					$('#jsbidprice' + auctionId).text('$'+result.historyprice).css('backgroundColor', '#b6d6d7');
					$('#jslhist' + auctionId).val(result.historyId);
					$('#jsbidst' + auctionId).val('1');
				/* end - Jsbidding */
				
				/* begin - center */
					$('#biddername' + auctionId).text(result.biddername);
					$('#bid_' + auctionId + '_price').val(result.historyprice);
					$('#bidprice' + auctionId).text('$'+result.historyprice).css('backgroundColor', '#b6d6d7');
					$('#lhist' + auctionId).val(result.historyId);					
					$('#bidst' + auctionId).val('1');
					
					$('#sidelhist').val(result.historyId);					
					$('#sidebidst').val('1');
					
					$('#epointId').text(result.epoints);
					$('#epennyId').text(result.epenny);
					
					$('#auct_prd_disp').text(result.retail);
					$('#totalauctionprice').text(result.retail);
					$('#auction_product_price').val(result.retail);
					$('#bidsuserdmyauction').text(result.noofbids);
				/* end - center */
					
				/* begin - leftside bar */						
					if(result.productimage != 0 && result.productimage != '') {
						var imageUrl = HTTP_URL + "uploads/thumb_images/" + result.productimage;
					} else {
						var imageUrl = HTTP_URL + "themes/admin/images/no-image-available.gif";
					}
					
					if(auctionId != 0 && auctionId != '') {
						var linkUrl = HTTP_URL + "index/auctiondet/" + auctionId;
					} else {
						var linkUrl = "#";
					}
					
					$('#bidLeftLink').removeAttr("href").attr("href", linkUrl);
					$("#bidLeftImages").removeAttr("src").attr("src", imageUrl);
					$('#bidLeftPrice').text('$'+result.historyprice).css('backgroundColor', '#b6d6d7');
					$('#bidLeftName').html(result.biddername);
					
					// $("#bidLeftPrice").text('$'+result.historyprice);
					$("#bidLeftTitle").text(result.productname.substr(0,10));
					$('#LastAuctionId').val(result.auctionId);
					$('#lbid_price').val(result.historyprice);
					
				/* result button status */
					var ltimer = result.timer.split(':');
					if(result.endstatus == 1) {
						$('#LeftSideBidButton').hide();
						$('#LeftSideSoldButton').show();
						$('#laCH_dtimer_digits').text('Ended');
						jsonObjectL.data.days  = '0';
						jsonObjectL.data.hours = '00';
						jsonObjectL.data.mins  = '00';
						jsonObjectL.data.secs  = '00';
					} else {
						jsonObjectL.data.estatus = 0;
						$('#LeftSideSoldButton').hide();
						$('#LeftSideBidButton').show();
						jsonObjectL.data.days  	 = ltimer[0];
						jsonObjectL.data.hours	 = ltimer[1];
						jsonObjectL.data.mins	 = ltimer[2];
						jsonObjectL.data.secs	 = ltimer[3];
					}
				/* result button status */
		 	}
	   	  }
     	});
	 }
}

function chgclass(myDiv,type){
	if(type==1)
		document.getElementById(myDiv).className = "bidbutton2";
	else
		document.getElementById(myDiv).className = "bidbutton1";
}

function setCookie( name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if(expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" + escape(value) + 
	((expires)?";expires="+expires_date.toGMTString():"") + ((path)?";path="+path:"") + 
	((domain)?";domain="+domain:"")+((secure)?";secure":"");
}
	
function getCookie(check_name) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for(i = 0;i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	
	if(!b_cookie_found) {
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function checkCookie() {
	var cval=getCookie("myTab");
	if (cval==null || cval=="") {
		setCookie( 'myTab', 'bidded', '1', '/', '', '' );
	}
}



/* auction hid history */
function myajaxhidproduct(url,auctionId,divId) {
	
	$('#AHidId').val(auctionId);
	if(document.getElementById('messagedetails')!= null)
		document.getElementById('messagedetails').innerHTML = '';
	
	menuTab('bidded');
	$.ajax({
		url: url,
		type: "POST",
		success: function(response) {
			
			var result	= eval('(' + response + ')');	
			$(".CAuctHid").removeAttr('src').attr('src', FRONT_IMAGE_PATH + 'AuctionHammer.jpg');
			$("#aucthis_"+auctionId).attr('src', FRONT_IMAGE_PATH + 'AuctionHammer-selected.jpg');
			$("#aucthisx_"+auctionId).attr('src', FRONT_IMAGE_PATH + 'AuctionHammer-selected.jpg');
				
			if(result.productimage != 0 && result.productimage != '') {
				var imageUrl = HTTP_URL + "uploads/thumb_images/" + result.productimage;
			} else {
				var imageUrl = HTTP_URL + "themes/admin/images/no-image-available.gif";
			}

			$("#bidLeftImages").removeAttr("src").attr("src", imageUrl);
			$('#bidLeftPrice').text('$'+result.historyprice); // .css('backgroundColor', '#b6d6d7')
			$("#bidLeftTitle").text(result.productname.substr(0,10));
			$('#LastAuctionId').val(result.auctionId);
			$('#lbid_price').val(result.historyprice);
			
			/* result button status */
				var ltimer = result.timer.split(':');
				if(result.endstatus == 1) {
					jsonObjectL.data.estatus = 1;
					$('#LeftSideBidButton').hide();
					$('#LeftSideSoldButton').show();
					jsonObjectL.data.days  = '0';
					jsonObjectL.data.hours = '00';
					jsonObjectL.data.mins  = '00';
					jsonObjectL.data.secs  = '00';
				} else {
					jsonObjectL.data.estatus = 0;
					$('#LeftSideSoldButton').hide();
					$('#LeftSideBidButton').show();
					jsonObjectL.data.days  	 = ltimer[0];
					jsonObjectL.data.hours	 = ltimer[1];
					jsonObjectL.data.mins	 = ltimer[2];
					jsonObjectL.data.secs	 = ltimer[3];
				}
			/* result button status */					
								
			/* Begin- bid history */
				
				var bidhCount = $('#highestBidCnt').val();
				for(var j=result.bhdata.length-1; j >= 0; j--) {

					if(result.bhdata[j].statename != null) {
						var scode	= result.bhdata[j].statename;
					} else {
						var scode 	= '-';
					}
					
					$('#banner-index1-1').prepend('<li><div class="banner-index1-1-heeight1">' 
					+ result.bhdata[j].username + '</div><div class="banner-index1-2-heeight1">' 
					+ scode + '</div><div class="banner-index1-3-heeight1">' 
					+ result.bhdata[j].bid_timer + '</div><div class="banner-index1-4-heeight1">' 
					+ result.bhdata[j].bid_count + '</div><div class="banner-index1-5-heeight1">' 
					+ result.bhdata[j].timesincelast + '</div><div class="clear"></div></li>');
					// $('#banner-index1-1 li:last').remove();
				}
			/* End - bid history */	
				$('#highestBidCnt').val(result.bhdata.length);
				
				if(bidhCount > 0) {
					for(var k=0; k < bidhCount; k++) {
						$('#banner-index1-1 li:last').remove();
					}
				}
			}
	});
	
}
function myajaxpinnedproduct(url,type,pid) {
	
	if(document.getElementById('messagedetails') != null)
		document.getElementById('messagedetails').innerHTML = '';
	
	$("#votetoplist").html("<center><img vspace='60' src='"+FRONT_IMAGE_PATH+"ajax-loader.gif' title=\"Loading\" alt=\"Loading\"  /></center>");
	
	var typeval	= 'type_auct_'+pid;
	var mtype   = document.getElementById(typeval).value;
	menuTab('pinned');
	
	if(mtype == 'pinned') {
		document.getElementById(typeval).value = 'unpinned';
		$.ajax({
			 url: url,
			 type: "POST",
			 success:function(response) {
				 $("#pinnedicon_" + pid).attr('src',FRONT_IMAGE_PATH+'AuctionPin-selected.jpg');
				 $("#votetoplist").html(response);			   
			 }
		});
	} else if(mtype=='unpinned') {
		document.getElementById(typeval).value = 'pinned';
		$.ajax({
			 url : url,
			 type: "POST",
			 success:function(response) {
			   $("#pinnedicon_" + pid).attr('src', FRONT_IMAGE_PATH+'AuctionPin.jpg');
			   $("#votetoplist").html(response);
			 }
		});
	}
}
   
function linkme(url){
	window.location.href = url;
}
	
// default loader function
function getAuctionListResults(url) {
	$.ajax({
		url:url,
		type:"POST",
		success:function(response) {
			$("#auctionslist").html(response);
		}
	});
}

// default loader function
function getPinnedListResults(url) {
	$.ajax({
		url:url,
		type:"POST",
		success:function(response) {
			$("#votetoplist").html(response);
		}
	});
}

// home page - pagination link
function auctiondispaly(url) {
	$.ajax({
		url:url,
		type:"POST",
		success:function(response) {
			$("#auctionslist").html(response);
		}
	});
}
// epoints status changes by online

// jquery next button slider
function getNextVoteSlider(url,divid,thisp) {
	
	var appendid   = $("#appendid"+divid).val();
	var prependid  = $("#prependid"+divid).val();
	$.ajax({
		url:url,
		type:"POST",
		data: "&nxt=" + appendid + "&prv=" + prependid + "&divid=" +divid,
		success:function(response) {
			var result	= eval('(' + response + ')');
			var totalcnt   = $("#totalcnt"+divid).val();
			var statuscnt  = $("#statuscnt"+divid).val();		
			if(result.htm != '') {
				var old_apped_val = $("#appendid"+divid).val();
				var append_id     = result.new_append_id;
				var prepend_id    = result.new_prepend_id;
				if(old_apped_val == append_id) {
					return false;
				} else {
					statuscnt = parseInt(statuscnt) + 1;
					$("div#slider" + divid).append(result.htm);
					$("#appendid"+divid).val(append_id);
					$("#prependid"+divid).val(prepend_id);
					$("#statuscnt"+divid).val(statuscnt);
			 		$("div#slider" + divid + " div:first").css('marginLeft',"0px");
						$("div#slider" + divid + " div:first").animate({marginLeft:"-200px"}, {duration:100, complete:function() {
							$("div#slider" + divid + " div:first").remove();
						}
					});
				}
			} else {
				if(statuscnt == parseInt(totalcnt)-1) {
					statuscnt = parseInt(statuscnt) + 1;
					$("#statuscnt"+divid).val(statuscnt);
					$("div#slider" + divid + " div:first").css('marginLeft',"0px");
					$("div#slider" + divid + " div:first").animate({marginLeft:"-200px"},{duration:100, complete:function() {
						$("div#slider" + divid + " div:first").remove();
					  }
					});
				}
			}
		}
	});
}

// jquery next button slider
function getPrevVoteSlider(url,divid) {
	var appendid = $("#appendid"+divid).val();
	var prependid = $("#prependid"+divid).val();
	$.ajax({
		url:url,
		type:"POST",
		data: "&nxt=" + appendid + "&prv=" + prependid + "&divid=" +divid,
		success:function(response) {
			var result	= eval('(' + response + ')');
			var statuscnt  = $("#statuscnt"+divid).val();
			if(result.htm != '') {
				var old_prepend_val = $("#prependid"+divid).val();
				var append_id = result.new_append_id;
				var prepend_id = result.new_prepend_id;
				if(old_prepend_val == prepend_id) {
					return false;
				} else {
					statuscnt = parseInt(statuscnt) - 1;
					$("#statuscnt"+divid).val(statuscnt);
					$("div#slider" + divid).prepend(result.htm);
					$("#prependid" + divid).val(prepend_id);
					$("#appendid"  + divid).val(append_id);
					$("div#slider" + divid + " div.indexVoteInner:last").remove();
					$("div#slider" + divid + " div:first").css('marginLeft', "-200px");
					$("div#slider" + divid + " div:first").animate({marginLeft:"0px"},100);
				}
			}
		}
	});
}


function epointstatus(status) {
	var url = HTTP_URL+ "accounts/topelectronicpoints/" + status;
	$.ajax({
		url:url,
		type:"POST",
		success:function(response) {				
			if(response==1) {
				$('#myEpON').html("<img src='"+FRONT_IMAGE_PATH+"onhide.png' onClick='return epointstatus(1)' style='cursor:pointer;' />");
				$('#myEpOFF').html("<img src='"+FRONT_IMAGE_PATH+"offshow.png' onClick='javascript:void(0)' />");
			} else {
				$('#myEpON').html("<img src='"+FRONT_IMAGE_PATH+"onshow.png' onClick='javascript:void(0)' />");
				$('#myEpOFF').html("<img src='"+FRONT_IMAGE_PATH+"offhide.png' onClick='javascript:epointstatus(0)' style='cursor:pointer;' />");
			}
		}
	});
}
	
// electronic penny buy form validation //
function frmsend() {
	
	var len = document.epenny.rboxlen.value;
	alert(len)
	
	var chk=0;
	alert(chk)
	return false;
	for(var i=0;i<len;i++){
		alert(document.epenny.radio[i].checked)
		if(document.epenny.radio[i].checked==true){
			chk=1;
		}
	}
	alert(chk)
	return false;
	/*
	if(chk==0){
		alert("Select any Package Option");
		return false;
	} else {
		alert("move to files")
		return true;
	}
	*/
	
}
	
function auctionTimer() {
	var lastAid			= $("#LastAuctionId").val();
	var prodid 	    	= $("#amanagement_id").val();
	if(prodid != undefined && prodid != '' && prodid != '0') {
	var splitcomma  	= prodid.split(",");
	var commalength 	= splitcomma.length;
	
	for(var k=0; k<commalength; k++) {
		var productid	= splitcomma[k];
		
		if(lastAid == productid) {
			jsonObjectL.data.days   = jsonObject.data[productid].days;
			jsonObjectL.data.hours  = jsonObject.data[productid].hours;
			jsonObjectL.data.mins	= jsonObject.data[productid].mins;
			jsonObjectL.data.secs	= jsonObject.data[productid].secs;
		}
		
	parselimit	= jsonObject.data[productid].days*86400 + jsonObject.data[productid].hours*3600 + 
	jsonObject.data[productid].mins*60 + jsonObject.data[productid].secs*1;
	
	if(jsonObject.data[productid].days ==0 && jsonObject.data[productid].hours==00 && jsonObject.data[productid].mins==00 && jsonObject.data[productid].secs==00) {
		    if(jsonObject.data[productid].estatus == 1 || jsonObject.data[productid].estatus == 2)
				$("#CH_dtimer" + productid + "_digits").text("Ended");
			else
				$("#CH_dtimer" + productid + "_digits").text("Going");
	} else {

			parselimit -= 1;
			
			// begin - week 
				curweek	= Math.floor(parselimit/604800);
			// end - week 
			
			// begin - days 
				curday	= Math.floor((parselimit)/86400); //  - (curweek * 604800)
				//if(curday < 10) { curday = "0" + curday; }
			// end - days 
		
			// begin - hour
				curhour = Math.floor((parselimit - (curday * 86400))/3600); // - (curweek * 604800) 
				if(curhour < 10) { curhour = "0" + curhour; }
			// end - hours 
			
			// begin - minutes 
				curmin	= Math.floor((parselimit - (curday * 86400 ) - (curhour * 3600))/60) // - (curweek * 604800) 
				if(curmin < 10) { curmin = "0" + curmin; }
			// end - minutes 

			// begin - seconds 
				cursec	= Math.floor((parselimit - (curday * 86400) - (curhour *3600 ) - (curmin*60))) 
				if(cursec < 10) { cursec = "0" + cursec; }
			// end - seconds 
			//alert(curday);		
			if(curday == 0) {
				curtime 	=  curhour + ":" + curmin + ":" + cursec;
			} else {
				curtime 	=  curday + 'D ' + curhour + ":" + curmin + ":" + cursec;
			}
			
			if(parselimit <=10) {
				$("#CH_dtimer" + productid + "_digits").css('color',color);
			} else {
				$("#CH_dtimer" + productid + "_digits").css('color','');
			}
					
			if(curday==0 && curhour==00 && curmin==00 && cursec==00 || ($("#estatusid" + productid).val() == 1)) {
				if($("#estatusid" + productid).val() == 0) {
					$("#estatusid" + productid).val(1);
					jsonObject.data[productid].days  = '0';
					jsonObject.data[productid].hours = '00';
					jsonObject.data[productid].mins	 = '00';
					jsonObject.data[productid].secs  = goingTime;
				} else {
					jsonObject.data[productid].days  = curday;
					jsonObject.data[productid].hours = curhour;
					jsonObject.data[productid].mins	 = curmin;
					jsonObject.data[productid].secs  = cursec;
				}
				$("#CH_dtimer" + productid +"_digits").text("Going");
			} else {
				$("#estatusid" + productid).val(0);
				jsonObject.data[productid].days  = curday;
				jsonObject.data[productid].hours = curhour;
				jsonObject.data[productid].mins	 = curmin;
				jsonObject.data[productid].secs	 = cursec;
				if(jsonObject.data[productid].estatus == 1 || jsonObject.data[productid].estatus == 2)
					$("#CH_dtimer" + productid + "_digits").text("Ended");
				else
					$("#CH_dtimer" + productid + "_digits").text(curtime);
			}
		}
	}
	closedTimesout = setTimeout(auctionTimer, 1000);
	}
}
	
function JSliderTimer() {
	
	var prodid 	    = $("#jsaid").val();
	if(prodid != undefined && prodid != '' && prodid != '0') {
		var splitcomma  = prodid.split(",");
		var commalength = splitcomma.length;
		for(var k=0; k<commalength; k++) {
			var productid	= splitcomma[k];
			parselimit	= jsonObjectC.data[productid].days * 86400 + jsonObjectC.data[productid].hours * 3600 
			+ jsonObjectC.data[productid].mins*60 + jsonObjectC.data[productid].secs*1;

			if(jsonObjectC.data[productid].days==0 && jsonObjectC.data[productid].hours==00 
			&& jsonObjectC.data[productid].mins==00 && jsonObjectC.data[productid].secs==00) {
				if(jsonObjectC.data[productid].estatus == 1 || jsonObjectC.data[productid].estatus == 2)
					$("#js_dtimer"+productid+"_digits").text("Ended");
				else
					$("#js_dtimer"+productid+"_digits").text("Going");
			} else {
					parselimit -= 1;
					/* begin - days */
					curday	= Math.floor((parselimit)/86400);
					/* end - days */
	
					/* begin - hour */
						curhour = Math.floor((parselimit - (curday * 86400))/3600); 
						if(curhour < 10) { curhour = "0" + curhour; }
					/* end - hours */
	
					/* begin - minutes */
						curmin	= Math.floor((parselimit - (curday * 86400 ) - (curhour * 3600))/60)  
						if(curmin < 10) { curmin = "0" + curmin; }
					/* end - minutes */
	
					/* begin - seconds */
						cursec	= Math.floor((parselimit - (curday * 86400) - (curhour *3600) - (curmin*60))) 
						if(cursec < 10) { cursec = "0" + cursec; }
					/* end - seconds */
	
					// curtime 	= curday + 'D ' + curhour + ":" + curmin + ":" + cursec;

					if(parselimit <=10) {
						$("#js_dtimer" + productid + "_digits").css('color', color);
					} else {
						$("#js_dtimer" + productid + "_digits").css('color','');
					}
			
					if(curday == 0) {
						curtime 	=  curhour + ":" + curmin + ":" + cursec;
					} else {
						curtime 	=  curday + 'D ' + curhour + ":" + curmin + ":" + cursec;
					}
			
					if(curday==0 && curhour==00 && curmin==00 && cursec==00 || ($("#jsestatusid"+productid).val()==1)) {
						if($("#jsestatusid" + productid).val() == 0) {
							$("#jsestatusid" + productid).val(1);
							jsonObjectC.data[productid].days  = '0';
							jsonObjectC.data[productid].hours = '00';
							jsonObjectC.data[productid].mins  = '00';
							jsonObjectC.data[productid].secs  = goingTime;
						} else {
							jsonObjectC.data[productid].days  = curday;
							jsonObjectC.data[productid].hours = curhour;
							jsonObjectC.data[productid].mins  = curmin;
							jsonObjectC.data[productid].secs  = cursec;
						}
						
						$("#js_dtimer" + productid + "_digits").text("Going");
					} else {
						$("#jsestatusid" + productid).val(0);
						jsonObjectC.data[productid].days  	 = curday;
						jsonObjectC.data[productid].hours 	 = curhour;
						jsonObjectC.data[productid].mins	 = curmin;
						jsonObjectC.data[productid].secs	 = cursec;
						if(jsonObjectC.data[productid].estatus == 1 || jsonObjectC.data[productid].estatus == 2)
							$("#js_dtimer"+ productid +"_digits").text("Ended");
						else
							$("#js_dtimer"+ productid +"_digits").text(curtime);
					}
				}
			}
	}
	closedTimeout = setTimeout(JSliderTimer, 1000);		
}

// place the order in our site function
function submitCartPaymentValidation() {
	document.electronic1.submit();
}

// get the editable of billing address detail in review order page.
function editBillingAddress(url,divId) {
	$("#"+divId).html("<img vspace='60' src='" + FRONT_IMAGE_PATH + "ajax-loader.gif' />");
	$.ajax({
		url:url,
		type:"POST",
		success:function(response) {
			$("#"+divId).html(response);
		}
	});
}

// get the state detail function for all pages (Placed here by baskar).
function myajaxloadstate(url,statid, countryid,selected) {
	var countries = document.getElementById(countryid).value;
	var state = document.getElementById(statid).value;
	if(countries != '') {
		$.ajax({
			url: url+'/'+selected+'/'+countries+'/',
			type: "POST",
			success: function(response) {
				 $("#" + statid).html(response);
			}
		});
	} else {
		document.getElementById(statid).innerHTML = "<option value=''> Select </option>";
	}
}
	
function hasWhiteSpace(s) {
	reWhiteSpace = new RegExp(/^\s+$/);
	if(s == '') {
		return false;
	} else if(reWhiteSpace.test(s)) {
		return false;
	}
	return true;
}
	
function isValidZipCode(value) { var re = /^\d{5}([\-]\d{4})?$/; return (re.test(value)); }

function editBillingAddVal(reviewBillAddr, url) {
	
	var reg 	 	= /^\s+$/;	 
	var billaddr 	= document.reviewBillAddr.billing_address1.value
	var billaddr2 	= document.reviewBillAddr.billing_address2.value
	var fname 		= document.reviewBillAddr.fname.value
	var lname 		= document.reviewBillAddr.lname.value
	var billcomp 	= document.reviewBillAddr.billing_companyname.value
	var billcity 	= document.reviewBillAddr.billing_city.value
	var billstate 	= document.reviewBillAddr.billing_state.value
	var billcountry = document.reviewBillAddr.billing_country.value
	var billpincode = document.reviewBillAddr.billing_pincode.value
	var billphone 	= document.reviewBillAddr.billing_phonenum.value

	if(hasWhiteSpace(fname) == false) {
		alert("Enter Billing First Name");
		document.reviewBillAddr.fname.focus();
	 	return false;
	}
	if(hasWhiteSpace(lname) == false) {
		 alert("Enter Billing Last Name");
		 document.reviewBillAddr.lname.focus();
		 return false;
	}
	if(hasWhiteSpace(billaddr) == false) {
		 alert("Enter Billing Street Address");
		 document.reviewBillAddr.billing_address1.focus(); 
		 return false;
	}
	
	if(hasWhiteSpace(billcity) == false) {
		 alert("Enter Billing City");
		 document.reviewBillAddr.billing_city.focus(); 
		 return false;
	}
	
	if(hasWhiteSpace(billpincode) == false) {
		alert("Enter Billing Zip code"); 
		document.reviewBillAddr.billing_pincode.focus(); 
		return false;
	}
	
	if(hasWhiteSpace(billphone) == false) { 
		alert("Enter Billing Phone number");
		document.reviewBillAddr.billphone.focus();
		return false;
	}
	 
	if(hasWhiteSpace(billcountry) == false) {
		alert("Enter Billing Country");
		document.reviewBillAddr.billing_country.focus();
		return false;
	}
	
	if(hasWhiteSpace(billstate) == false) {
		alert("Enter Billing State"); 
		document.reviewBillAddr.billing_state.focus();  
		return false;
	}
	
	if(billcountry == 254) {
		if(isValidZipCode(billpincode) == false) {
			alert("Please Enter Valid Billing Zip Code");
			document.reviewBillAddr.billing_pincode.focus();
			return false;
		}
	}
	
	var dataString = 'bfname='+ fname + '&blname=' + lname + '&baddr1=' + billaddr + '&baddr2=' + billaddr2 + '&bphone=' + billphone + '&bpincode='+ billpincode + '&bstate=' + billstate + '&bcountry=' + billcountry + '&bcname=' + billcomp + '&bcity=' + billcity;
	
	$("#billingAdd").html("<img vspace='60' src='"+ FRONT_IMAGE_PATH +"ajax-loader.gif' />");
	$.ajax({
		url:url,
		type:"POST",
		data:dataString,
		success:function(response) {
			$("#billingAdd").html(response);
		}
	});
}

function editShippingAddVal(reviewShipAddr, url) {
	
	var reg 	 	= /^\s+$/;	
	var billaddr 	= document.reviewShipAddr.shipping_address1.value
	var billaddr2 	= document.reviewShipAddr.shipping_address2.value
	var fname 		= document.reviewShipAddr.fname.value
	var lname 		= document.reviewShipAddr.lname.value
	var billcomp 	= document.reviewShipAddr.shipping_companyname.value
	var billcity 	= document.reviewShipAddr.shipping_city.value
	var billstate 	= document.reviewShipAddr.shipping_state.value
	var billcountry = document.reviewShipAddr.shipping_country.value
	var billpincode = document.reviewShipAddr.shipping_pincode.value
	var billphone 	= document.reviewShipAddr.shipping_phonenum.value

	if(hasWhiteSpace(fname) == false) {
		alert("Enter shipping First Name");
		document.reviewShipAddr.fname.focus();
	 	return false;
	}
	
	if(hasWhiteSpace(lname) == false) {
		 alert("Enter shipping Last Name");
		 document.reviewShipAddr.lname.focus();
		 return false;
	}
	 
	if(hasWhiteSpace(billaddr) == false) {
		 alert("Enter shipping Street Address");
		 document.reviewShipAddr.shipping_address1.focus(); 
		 return false;
	}
	
	if(hasWhiteSpace(billcity) == false) {
		 alert("Enter shipping City");
		 document.reviewShipAddr.shipping_city.focus(); 
		 return false;
	}
	
	if(hasWhiteSpace(billpincode) == false) {
		alert("Enter shipping Zip code"); 
		document.reviewShipAddr.shipping_pincode.focus(); 
		return false;
	}
	
	if(hasWhiteSpace(billphone) == false) { 
		alert("Enter shipping Phone number");
		document.reviewShipAddr.billphone.focus();
		return false;
	}
	 
	if(hasWhiteSpace(billcountry) == false) {
		alert("Enter shipping Country");
		document.reviewShipAddr.shipping_country.focus();
		return false;
	}
	
	if(hasWhiteSpace(billstate) == false) {
		alert("Enter shipping State"); 
		document.reviewShipAddr.shipping_state.focus();  
		return false;
	}
	
	if(billcountry == 254) {
		if(isValidZipCode(billpincode) == false) {
			alert("Please Enter Valid shipping Zip Code");
			document.reviewShipAddr.shipping_pincode.focus();
			return false;
		}
	}
	
	var dataString = 'sfname='+ fname + '&slname=' + lname + '&saddr1=' + billaddr + '&saddr2=' + billaddr2 + '&sphone=' + billphone + '&spincode='+ billpincode + '&sstate=' + billstate + '&scountry=' + billcountry + '&scname=' + billcomp + '&scity=' + billcity;
	$("#shippingAdd").html("<img vspace='60' src='"+ FRONT_IMAGE_PATH +"ajax-loader.gif' />");
	
	alert(url);
	$.ajax({
		url:url,
		type:"POST",
		data:dataString,
		success:function(response) {
			$("#shippingAdd").html(response);
		}
	});
}

// editable format of quantity of review and order page.
function editQuantityItem(url, i, qty) {
	var dataString = 'prodid='+ i +'&qty='+ qty;
	$.ajax({
		url:url,
		type:"POST",
		data:dataString,
		success:function(response) {
			$("#changeQtItem" + i).html(response);
		}
	});
}

// update cart item
function updateCartItem(prodid, url) {
	var totQtyItem = $('#qty'  + prodid).val(); 
	var cartId	   = $('#cart' + prodid).val();
	var shipPrice  = $('#totShipPrice').val();
	var taxPrice   = $('#totTaxPrice').val();	
	var dataString = 'prodid='+ prodid + '&qty='+ totQtyItem + '&cart='+ cartId + '&shipPrice='+ shipPrice + '&taxPrice='+ taxPrice;	
	$.ajax({
		url:url,
		type:"POST",
		data:dataString,
		success:function(response) {
			var result	= eval('(' + response + ')');
			$("#changeQtItem" + prodid).html(result.htmldesign);
			$("#totItemAmt").text(CURRENCY + result.totamt);
			$("#epDiscount").text(CURRENCY + result.totepdiscount);
			$("#singleItemPrice"+ prodid).html(CURRENCY + result.sameitemamt);
			$("#amtBefTax").text(CURRENCY + result.amtBefTax);
			$("#payAmt").text(CURRENCY + result.totOrderAmt);
			$("#taxPrice").text(CURRENCY + result.totTaxAmt);
			$("#rebateAmount").text('Instant Rebate:' + CURRENCY + result.rebateamt);
		}
	});
}

// check radio options
function checkRadio(frmName, rbGroupName) {
	 var radios = document[frmName].elements[rbGroupName];
	 for(var i=0; i <radios.length; i++) {
	  if(radios[i].checked) {
		return true;
	  }
	 }
	 return false;
}

// check shipping speed
function shipSpeed() {
	 if(!checkRadio("accountsForm", "shipspeed")) {
		alert("Please select the shipping speed");
		return false;
	 } else {
		return true;
	}
}

// Promotional Code validation
function getPcodeData(url) {
	
	var pcodevar = document.getElementById('pcode').value;
	var str = $("#pcode").val(pcodevar);
	if(str==''){
		$("#messageboxdata").html("<font style='color:green'>Please enter valid promotional code</font>");
		return false;
	}
	$.ajax({
		url:url + pcodevar,
		type:"POST",
		success:function(response) {
			
			if(response!="") {
				$("#pcode").val('');
				$("#messageboxdata").html(response);
			}			
			else{
				$("#pcode").val(pcodevar);
				$("#messageboxdata").html("<font style='color:green'>Please enter valid promotional code</font>");
			}
		}
	});
}

// Promotional Code validation
function PromotionCodeValidationRegister(url,pcodevar) {
	$.ajax({
		url:url + pcodevar,
		type:"POST",
		success:function(response) {
			if(response!='') {
				$("#pcode").val('');
			}
			document.getElementById('pcodeMessage').innerHTML = response;
		}
	});
}

function logselect(){
	if(document.loginform!=null) {
		document.loginform.username.select();
		document.loginform.username.focus();
	}
}

function pinOfFromSilder(pin, url){
	var url 	= url + pin;
	var temppin = 'type_auct_' + pin;
	if(document.getElementById(temppin) != null)
		document.getElementById(temppin).value  = 'unpinned';
		
	$.ajax({
		 url: url,
		 type: "POST",
		 success:function(response) {
			$("#votetoplist").html(response);
			$("#pinnedicon_"+pin).attr('src', FRONT_IMAGE_PATH + 'AuctionPin.jpg');
		 }
	});
}

/* voting functionality in Electronic penny */
function postvalues(url,id_num) {
	var theUL = document.getElementById('unit_ul' + id_num); 
	theUL.innerHTML = '<div class="loading"></div>';
	$.ajax({
		url: url,
		type: "POST",
		success: function(response)	{
			$("#unit_ul"+id_num).html(response);
		}
	});
}
