function showMap()
{
	if (document.getElementById("mapDiv").style.display=="none"){
		document.getElementById("mapDiv").style.display="inline";
	} else {
		document.getElementById("mapDiv").style.display="none";
	}
}

function showPic (curPrdID){
	curY=(screen.height/2)-275;
	curX=(screen.width/2)-275;
	attributes="width=550, height=550, top="+curY+", left="+curX+", resizable=no, location=no, menubar=no, toolsbar=no, directories=no";
	linkUrl="showPic.php?prdID="+curPrdID;
	window.open(linkUrl, 'prdPic', attributes);	
}

function openPwReminder(){
	curY=(screen.height/2)-150;
	curX=(screen.width/2)-150;
	attributes="width=300, height=300, top="+curY+", left="+curX+", resizable=no, location=no, menubar=no, toolsbar=no, directories=no";
	linkUrl="pwReminder.php";
	window.open(linkUrl, 'pwReiminder', attributes);		
}

function showForPrint (curPrdID, auctionID){
	curY=(screen.height/2)-300;
	curX=(screen.width/2)-250;
	attributes="width=600, height=500, top="+curY+", left="+curX+", location=no, menubar=no, toolsbar=no, directories=no, scrollbars=yes";
	linkUrl="showForPrint.php?prdID="+curPrdID+"&auctionID="+auctionID;
	window.open(linkUrl, 'prdPic', attributes);	
}

function showResPrint (auctionID)
{
	curY=(screen.height/2)-250;
	curX=(screen.width/2)-250;
	attributes="width=500, height=500, top="+curY+", left="+curX+", location=no, menubar=no, toolsbar=no, directories=no, scrollbars=yes";
	linkUrl="printAucResults.php?auctionID="+auctionID;
	window.open(linkUrl, 'resPage', attributes);	
}

function centerWin(){
	curY=(screen.height/2)-255;
	curX=(screen.width/2)-255;
	window.moveTo(curX, curY);
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true					
 		}
}

function subAdvSearch(){
//	if (document.advSearch.saleSelect.saleSelect[1].checked){
//		document.advSearch.search_auction.value=document.advSearch.curSaleCode.value;
//	} else if (document.advSearch.saleSelect.saleSelect[2].checked){
//		if (document.advSearch.saleSelectNum.value!=""){
//			document.advSearch.search_auction.value=document.advSearch.saleSelectNum.value;
//		} else {
//			document.advSearch.search_auction.value="allSale";	
//		}
//	} else {
//		document.advSearch.search_auction.value="allSale";
//	}
	document.advSearch.submit();
}

function refineSearch(){
	document.aucForm.action='advSearch.php';
	document.aucForm.submit();
}

function subBidForm(){
	// check for min & max bid
	if (document.bidForm.bidMaximum.value==""){
		alert (noBidMax);
		document.bidForm.bidMaximum.focus();
		document.bidForm.bidMaximum.select();
		return false;
	} else if (document.bidForm.bidCstName.value==""){
		alert (noBidName);
		document.bidForm.bidCstName.focus();
		document.bidForm.bidCstName.select();
		return false;
	} else if (document.bidForm.bidCstPhone.value==""){
		alert (noBidPhone);
		document.bidForm.bidCstPhone.focus();
		document.bidForm.bidCstPhone.select();
		return false;
	} else if (document.bidForm.bidCstEmail.value==""){
		alert (noBidEmail);
		document.bidForm.bidCstEmail.focus();
		document.bidForm.bidCstEmail.select();
		return false;
	} else if (!checkEmail(document.bidForm.bidCstEmail.value)){
		alert (emailNotValid);
		document.bidForm.bidCstEmail.focus();
		document.bidForm.bidCstEmail.select();
		return false;
	} else {
		check=confirm(confirmBid);
		if (check){
			document.bidForm.submit();
		} else {
			return false;
		}
	}
}

function subOrderForm()
{
	// check for min & max bid
	/*if (document.bidForm.bidCstName.value=="")
	{
		alert (noBidName);
		document.bidForm.bidCstName.focus();
		document.bidForm.bidCstName.select();
		return false;
	} else if (document.bidForm.bidCstPhone.value=="")
	{
		alert (noBidPhone);
		document.bidForm.bidCstPhone.focus();
		document.bidForm.bidCstPhone.select();
		return false;
	} 
	else if (document.bidForm.bidCstEmail.value=="")
	{
		alert (noBidEmail);
		document.bidForm.bidCstEmail.focus();
		document.bidForm.bidCstEmail.select();
		return false;
	} 
	else if (!checkEmail(document.bidForm.bidCstEmail.value))
	{
		alert (emailNotValid);
		document.bidForm.bidCstEmail.focus();
		document.bidForm.bidCstEmail.select();
		return false;
	} 
	else 
	{*/
		check = confirm(confirmOrder);
		if (check)
		{
			document.bidForm.submit();
		} 
		else 
		{
			return false;
		}
	/*}*/
}

function checkContactSub(){
	if (document.contactForm.contact_fullName.value=="" ||
		document.contactForm.contact_email.value==""){
			alert (contactError1);
			return false;
	 } else if (!checkEmail(document.contactForm.contact_email.value)){
	 	alert (contactError2);
	 	return false;
	} else if (document.contactForm.contact_body.value==""){
		alert (contactError3);
		return false;
	} else {
		return confirm (contactConfirm);
	}
}

