var time;
var Extime;
var nTimer1 ;
var strCurrentDate;
var strEndDate;
var strStopDate;
var d = document;
time = 0;
Extime = 0;
nTimer1 = 998;


function PopUpNewWindow(TheURL) {
window.open(TheURL,"gotoremote","width=600,height=400,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0");
}

function alertMsg(field,msg) {
alert(msg);
field.focus();
field.select();
}

function validDigit(ch) {
if ((ch != ".") && (ch != " ") && (ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
return false;
else
return true;
}

function digit(string) {
var i;
var chr;
for (i = 0; i < string.length; i++) {
chr = string.substring(i, i+1);
if (!validDigit(chr))
return false;
}
return true;
}

function empty(string) {
if(string.length==0)
return true;
else {
for(i=0;i< string.length;i++) {
ch=string.substring(i,i+1);
if (ch != " ")
return false;
}
return true;
}
}

function check_empty(field,alert_msg) {
if(empty(field.value)) {
alertMsg(field, alert_msg);
return false;
}
return true;
}

var nNextBidPrice ;
var nBidIncreamental ;

function validate() {
var nFactor;
var nRecalculate;
with (document.IBid)
{
if(!check_empty(StartBidAt, "Bid Price cannot be blank !"))
 return false;
if(!digit(StartBidAt.value)) {
 alertMsg(StartBidAt, "Invalid number !");
  return false;
 }
 if(StartBidAt.value*1 < nNextBidPrice*1) {
  alertMsg(StartBidAt, "The Lowest You May Bid Is :" + nNextBidPrice);
  return false;
 }
 if(!empty(BidAmount.value)) {
  if(!digit(BidAmount.value)) {
   alertMsg(BidAmount, "Invalid number !");
   return false;
  }
  if(BidAmount.value*1 < StartBidAt.value*1) {
   alertMsg(BidAmount, "Your AutoBid cannot be less than Start Bid Price");
   return false;
  }
 }
}
return true;
}

function validateDutch() {
var nFactor;
var nRecalculate;
with (document.IBid) {
	if(!check_empty(BidQuantity, "Quantity cannot be blank !"))
		return false;
	if(!digit(BidQuantity.value)) {
		alertMsg(BidQuantity, "Invalid number !");
		return false;
	}
	if(BidQuantity.value*1 <= 0) {
		alertMsg(BidQuantity, "Invalid number !");
		return false;
	}
	if(BidQuantity.value*1 > nMaxQuantity) {
		alertMsg(BidQuantity, "Maximum quantity you can placed is only : " + nMaxQuantity + " !");
		return false;
	}
	if(!check_empty(StartBidAt, "Bid Price cannot be blank !"))
		return false;
	if(!digit(StartBidAt.value)) {
		alertMsg(StartBidAt, "Invalid number !");
		return false;
	}
	if(StartBidAt.value*1 < nNextBidPrice*1) {
		alertMsg(StartBidAt, "The Lowest You May Bid Is :" + nNextBidPrice);
		return false;
	}
}
return true;
}

function validatePDown() {
var nFactor;
var nRecalculate;
with (document.IBid)
{
	if(!check_empty(BidQuantity, "Quantity cannot be blank !"))
		return false;
	if(!digit(BidQuantity.value)) {
		alertMsg(BidQuantity, "Invalid number !");
		return false;
	}
	if(BidQuantity.value*1 <= 0) {
		alertMsg(BidQuantity, "Invalid number !");
		return false;
	}
}
return true;
}

function InitTimer(s1,s2,s3) {
	strCurrentDate = s1;
	strEndDate = s2;
	strStopDate = s3;
}

function CalculateTotalSeconds() {
	setTimeout( "CountDown()", nTimer1 );
	iStopDate = Date.parse( strStopDate );
	iEndDate = Date.parse(  strEndDate );
	iCurrentDate = Date.parse(  strCurrentDate );
	time = (iEndDate - iCurrentDate)/1000;
	Extime = (iStopDate - iEndDate)/1000;
}

function CountDown() {
setTimeout( "CountDown()", nTimer1 );
if (time>0) {
	time = time -1;
	d.forms.letime.elements["days"].value = Math.floor(time/86400);
	d.forms.letime.elements["hrs"].value =Math.floor(time/3600)%24;
	d.forms.letime.elements["mins"].value = Math.floor(time/60)%60;
	d.forms.letime.elements["secs"].value = (time%60);
}
}

