function Validate_Form_Objects(frm,fieldRequired,fieldDescription,fieldEmail,fieldConfirm,fieldConfirmDesc,fieldNumeric)
  {
	
	if(!(fieldConfirm)) fieldConfirm = Array ();
	if(!(fieldConfirmDesc)) fieldConfirmDesc = Array();		
	if(!(fieldEmail)) fieldEmail = Array();	
	if(!(fieldNumeric)) fieldNumeric = Array();	
	
//	var alertMsg =  "Please fill the following fields before you submit :\n\n";
    var alertMsg =  "Please Enter ";
   	var l_Msg = alertMsg.length;
	var e = / /g;
   	for (var i = 0; i < fieldRequired.length; i++)
   	{
  		var obj = frm.elements[fieldRequired[i]];
   		if (obj)
       		{
            	switch(obj.type)
        		{
               	case "select-one":
                				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == "")
                    					alertMsg += " - " + fieldDescription[i] + "\n";
                   				break;
       			case "select-multiple":
                    			if (obj.selectedIndex == -1)
                        					alertMsg += " - " + fieldDescription[i] + "\n";
                        		break;
                case "text":
								var temp_value = obj.value.replace(e,"");
								if (temp_value.length == 0 || obj.value == null)
                         					alertMsg += " - " + fieldDescription[i] + "\n";
								break;
                case "password":
								var temp_value = obj.value.replace(e,"");
                        		if (temp_value.length == 0 || obj.value == null)
                         					alertMsg += " - " + fieldDescription[i] + "\n";
								break;
                
				case "textarea":
								var temp_value = obj.value.replace(e,"");
                        		if (temp_value.length == 0 || obj.value == null)
                         					alertMsg += " - " + fieldDescription[i] + "\n";
                   				break;
				case "undefined":
								if (obj.value == "" || obj.value == null)
                         					alertMsg += " - " + fieldDescription[i] + "\n";
								break;				
                }   

			
				if (alertMsg.length != l_Msg)
				{
					alert(alertMsg);
					switch(obj.type)
        			{
        				case "text": obj.select();
									break;
                		case "password": obj.select();
									break;
						case "textarea": obj.select();
									break;
        			}
					obj.focus();
					return false;
				}	
		} // END IF (obj)
  	} // END FOR
	
	if (alertMsg.length == l_Msg)
   	{
		
		/************ Email Validation ************/
		for (var i = 0; i < fieldEmail.length; i++)
	   	{
  			var obj = frm.elements[fieldEmail[i]];
			if (obj)
			{
			  if(obj.length < 5 || obj.value.indexOf("@")==-1 || obj.value.indexOf(".")==-1 || (obj.value.indexOf(".")- obj.value.indexOf("@")) <= 2)
			  		{
				 		var alertEmail = 'Enter a Valid Email Address';
						alert(alertEmail);
						obj.focus();
			   			return false;
					 }
			}	// END IF obj
		} // END IF FOR
		/************ Email Validation END ************/	
		
	   /************ Password Confirmation ************/
		for (var i = 0; i < fieldConfirm.length; i++)
	   	{
			var obj1 = frm.elements[fieldConfirm[i]];
			var obj2 = frm.elements[fieldConfirm[i+1]];
			if (obj1 && obj2)
			{
			 if(obj1.value != obj2.value)
			  {
				 		alertConfirm  = fieldConfirmDesc[i] + " and " + fieldConfirmDesc[i+1] +" Not Matching";
						alert(alertConfirm);
						obj1.focus();
			 			return false;
			  } // END IF obj1.value
			} // END IF obj1
		} // END IF FOR	
		
	   /************ Password Confirmation END ************/
	
	   /************ Numeric Validation ************/
		for (var i = 0; i < fieldNumeric.length; i++)
	   	{
  			var obj = frm.elements[fieldNumeric[i]];
			if (obj)
			{
			  if(isNaN(obj.value))
			  		{
						alert('Enter A Numeric Value');
						obj.focus();
			   			return false;
					 }
			}	// END IF obj
		} // END IF FOR
		/************ Numeric Validation END ************/	
		
		return true;	
  	 } // END IF (alertMsg.length == l_Msg)
	else
 	{
		alert(alertMsg);
   		return false;
   	}
}



/*********************************
			    if (obj.type == 'undefined')
       			{
        				var blnchecked = false;
           				for (var j = 0; j < obj.length; j++)
              				{
              					if (obj[j].checked)
                      						blnchecked = true;
              				}
           				if (!blnchecked)
              					alertMsg += " - " + fieldDescription[i] + "\n";
								
       			}
*******************************/	

function checkSimpleForm(oName)
{
	var bRet = true;
	oName.style.border = '1px solid #000000';
	if(oName.value == '')
	{
		oName.style.border = '1px solid #cc0000';
		bRet = false;		
	}
	return bRet;
}

function checkAddProductAuction(oForm)
{
	var bRet = true, oElem;
	for(var i=0; i<oForm.elements.length; i++)	
	{
		oElem = oForm.elements[i];		
		if(oElem.type == 'text' || oElem.type == 'select-one' || oElem.tagName.toLowerCase() == 'textarea')
		{			
			oElem.style.border = '1px solid #000000';
			if(oElem.value == '' && (oElem.type == 'text' || oElem.tagName.toLowerCase() == 'textarea') || 
				oElem.type == 'select-one' && (oElem.selectedIndex == -1 || oElem.options[oElem.selectedIndex].value == ''))
			{
				oElem.style.border = '1px solid #cc0000';
				bRet = false;
			}
		}
	}
	return bRet;
}

// allow only digits, ->, <-, Backspace, Del, Tab, '.', ','
function allowOnlyNumbers(evt)
{
	evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 9 && charCode != 37 && charCode != 39 
    	&& charCode != 8 && charCode != 46 && charCode != 44) 
        return false;
    return true;
}

function checkAuctionLoginForm(oForm)
{
	var bRet = true, oElem;
	for(var i=0; i<oForm.elements.length; i++)
	{
		oElem = oForm.elements[i];
		if(oElem.type != 'text' && oElem.type != 'password') continue;
		document.getElementById(oElem.name + 'Err').style.display = "none";
		if(oElem.value == '')
		{
			document.getElementById(oElem.name + 'Err').style.display = "inline";
			bRet = false;
		}		
	}
	return bRet;
}



function isFutureDate(sDateValue)
{
	// a future date must be choosen
	arDate = sDateValue.split('-');			
	sDate = new Date(arDate[2],arDate[1] - 1, arDate[0]);
	var sDateNow = new Date();
	sDateNow = new Date(sDateNow.getFullYear(),sDateNow.getMonth(), sDateNow.getDate());
	if(sDate >= sDateNow)						
		return true;
	return false;
}

function isFutureTime(sDate, sTime)
{
	arDate = sDate.split('-');			
	sDate = new Date(arDate[2],arDate[1] - 1, arDate[0]);
	var sDateNow = new Date();
	sDateNow = new Date(sDateNow.getFullYear(),sDateNow.getMonth(), sDateNow.getDate());
	
	if(sDate.getTime() == sDateNow.getTime() && sTime <= (new Date()).getHours())
		return false;
	return true;
}

function checkAuctionPutBid(oForm)
{
	if(oForm.aucLogged.value == '0')
	{
		window.location = 'index.php?link=auctionloginform&err=3';
		return false;
	}
	
	var bRet = true;
	var oErr3 = document.getElementById('aucBidPeriodErr');
	var oErr4 = document.getElementById('aucBidTimeErr');
	var oErr5 = document.getElementById('aucBidTimeFutureErr');
	
	var iBid = oForm.aucBid.value;
	var oTime = oForm.aucBidTime;
	iBid = iBid.replace(/,/,'.');
	
	document.getElementById('aucbidErr1').style.display = 'none';
	document.getElementById('aucbidErr2').style.display = 'none';
	
	oErr3.style.display = 'none';
	oErr4.style.display = 'none';
	oErr5.style.display = 'none';
	
	if(oForm.aucBid.value == '')
	{
		document.getElementById('aucbidErr1').style.display = 'inline';
		bRet = false;
	}
	if(oForm.aucBid.value == '')
	{
		document.getElementById('aucbidErr1').style.display = 'inline';
		bRet = false;
	}
	if(parseFloat(iBid) <= (oForm.aucHighestBid.value))
	{
		document.getElementById('aucbidErr2').style.display = 'inline';
		bRet = false;
	}

	if(oForm.aucBidPeriod.value && !isFutureDate(oForm.aucBidPeriod.value))
	{
		oErr3.style.display = 'inline';
		bRet = false;
	}
	if(oTime.selectedIndex == -1 || oTime.options[oTime.selectedIndex].value == '' )
	{
		oErr4.style.display = 'inline';
		bRet = false;
	}
	if(oErr3.style.display != 'inline' && oErr4.style.display != 'inline' 
		&& !isFutureTime(oForm.aucBidPeriod.value, oTime.options[oTime.selectedIndex].value))
	{
		oErr5.style.display = 'inline';
		bRet = false;
	}
	
	var ard = oForm.aucLastDate.value.split('/');
	var art = oForm.aucLastTime.value.split('/');
	
	var ard1 = oForm.aucBidPeriod.value.split('-');
	
	var d1 = new Date(ard[0],ard[1], ard[2],0,0,0);
	var d2 = new Date(ard1[2],ard1[1],ard1[0],0,0,0);
	

	if(d1.getTime() == d2.getTime())
		if(oErr4.style.display != 'inline' && parseInt(art[0]) < parseInt(oTime.options[oTime.selectedIndex].value))
			{
				oErr3.style.display = 'inline';
				bRet = false;
			}
	
	return bRet;
}

function auctionBuyNow(oBtn, iId)
{	
	var oForm = oBtn.form, bRet = true;
	
	if(oForm.aucLogged.value == '0')
	{
		window.location = 'index.php?link=auctionloginform&err=3';
		return false;
	}
	oForm.action = 'index.php?link=auctiondetailspreview&id='+ iId +'&act=buynow';
	oForm.submit();
	
	return bRet;
}
function isValidEmail(sValue)
{
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!sValue.match(re))
        return false;
    return true;
}

function allowNotDigits(evt)
{
	evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode < 48 || charCode > 57)
        return true;
    return false;
}

function isValidPostCode(sValue)
{
	var re = /^\d{4}\s[a-zA-Z]{2}$/;
	if (!sValue.match(re))
        return false;
    return true;
}

function checkAuctionRegisterForm(oForm)
{
	var bRet = true, oElem;
	for(var i=0; i<oForm.elements.length; i++)
	{
		oElem = oForm.elements[i];	
		if(oElem.type != 'text' && oElem.type != 'password' || oElem.name == "rec[fax]" || oElem.name == 'rec[postcode]') continue;
		document.getElementById(oElem.name + 'Err').style.display = 'none';
		if(oElem.value == '' 
			|| (oElem.name == 'passConf' && oElem.value != '' && oForm.elements['rec[password]'].value != oElem.value)
			|| (oElem.name == 'rec[postcode]' && !isValidPostCode(oElem.value))
			|| (oElem.name == 'rec[email]' && !isValidEmail(oElem.value)))
		{
			document.getElementById(oElem.name + 'Err').style.display = 'inline';
			bRet = false;
		}		
	}
	return bRet;	
}

function checkAuctionEditDetailsForm(oForm)
{
	var bRet = true, oElem;
	var oPassCont = document.getElementById('passwordDetails');
	for(var i=0; i<oForm.elements.length; i++)
	{
		oElem = oForm.elements[i];	
		if(oElem.type != 'text' && oElem.type != 'password' || oElem.name == "rec[fax]" 
			 || oElem.name == 'rec[postcode]' || oElem.name.toLowerCase().indexOf('password') != -1) continue;
		document.getElementById(oElem.name + 'Err').style.display = 'none';
		if(oElem.value == ''
			|| (oElem.name == 'rec[postcode]' && !isValidPostCode(oElem.value))
			|| (oElem.name == 'rec[email]' && !isValidEmail(oElem.value)))
		{
			document.getElementById(oElem.name + 'Err').style.display = 'inline';
			bRet = false;
		}		
	}
	var oOldPass = oForm.elements['rec[password]'];
	var oNewPass = oForm.elements['rec[newPassword]'];
	var oConfPass = oForm.elements['passwordConf'];
	if(oPassCont.style.display == 'block' && oOldPass.value)
	{
		document.getElementById('rec[password]Err').style.display = 'none';
		document.getElementById('rec[newPassword]Err').style.display = 'none';
		document.getElementById('passwordConfErr').style.display = 'none';
		
		if(oConfPass.value == '' || oConfPass.value != '' && oNewPass.value != oConfPass.value)
		{
			document.getElementById('passwordConfErr').style.display = 'inline';
			bRet = false;
		}
		if(oNewPass.value == '')
		{
			document.getElementById('rec[newPassword]Err').style.display = 'inline';
			bRet = false;
		}
	}
	return bRet;	
}

function fillProdSelect(oSelSrc, oSelDest)
{	
	var iCatId = oSelSrc.options[oSelSrc.selectedIndex].value, oOpt;	
	while(oSelDest.options.length)
		oSelDest.remove(0);
		
	if(!iCatId) return;
	
	oOpt = document.createElement('option');
	oOpt.value = '';
	oOpt.text = '';
	oSelDest.options.add(oOpt);
	
	for(var i=0; i<arProd.length; i++)
	{
		if(arProd[i].catid == iCatId)
		{
			oOpt = document.createElement('option');
			oOpt.value = arProd[i].id;
			oOpt.text = arProd[i].name;
			oSelDest.options.add(oOpt);
		}
	}	
}

function showProductDescription(oSel)
{
	var oArea = document.getElementById('descriptionArea');	
	var iProdId = oSel.options[oSel.selectedIndex].value;	
	var sDesc = '';
	
	if(!iProdId)
	{
		oArea.innerHTML = '';
		return;
	}
		
	for(var i=0; i<arProd.length; i++)
	{
		if(arProd[i].id == iProdId)
		{
			sDesc = arProd[i].description;
			sDesc = sDesc.replace(/\<br\/>/g,"\r\n");
			oArea.innerHTML = sDesc;
			
			document.getElementById('priceUnit').innerHTML = arProd[i].unit;
			document.getElementById('qtyUnit').innerHTML = arProd[i].displayUnit;
			return;
		}
	}
}
function checkPlaceParcelForm(oForm)
{
	var bRet = true, oElem, arDate, bErr;
	for(var i=0; i<oForm.elements.length; i++)
	{
		oElem = oForm.elements[i];		
		if(oElem.type != 'text' && oElem.type != 'select-one' && oElem.type != 'checkbox') continue;
		if(document.getElementById(oElem.name + 'Err'))
			document.getElementById(oElem.name + 'Err').style.display = 'none';
				
		if(oElem.type == 'text' && !oElem.value 
			|| ((oElem.name == 'rec[productid]' || oElem.name == 'rec[available]' || oElem.name == 'rec[year]' || oElem.name == 'rec[newdate]'
				|| oElem.name == 'rec[region]' || oElem.name == 'rec[endtime]') && oElem.type == 'select-one' && (oElem.selectedIndex == -1 || !oElem.options[oElem.selectedIndex].value))
			|| oElem.name == 'rec[enddate]')
			{
				bErr = true;
				if(oElem.name == 'rec[enddate]')
				{					
					if(oElem.value && isFutureDate(oElem.value))
						bErr = false;											
				}
				if(bErr)
				{	
					document.getElementById(oElem.name + 'Err').style.display = 'inline';
					bRet = false;
				}
			}
	}
	document.getElementById('futureWeekErr').style.display = 'none';
	var oAv = document.getElementById('rec[available]');
	var oYear = document.getElementById('rec[year]');
	var iAv, iYear, iWeek = oForm.weekNr.value;	
	if(oAv.selectedIndex != -1 && (iAv = oAv.options[oAv.selectedIndex].value) 
		&& oYear.selectedIndex != -1 && (iYear = oYear.options[oYear.selectedIndex].value))
	{
		
		if(iYear == (new Date()).getFullYear() && iAv < iWeek)
		{
			document.getElementById('futureWeekErr').style.display = 'block';
			bRet = false;
		}
	}	
	
	var oErr5 = document.getElementById('aucBidTimeFutureErr');
	oErr5.style.display = 'none';
	
	var oTime = document.getElementById('rec[endtime]');
	if(document.getElementById('rec[enddate]Err').style.display != 'inline' 
		&& document.getElementById('rec[endtime]Err').style.display != 'inline' 
		&& !isFutureTime(document.getElementById('rec[enddate]').value, oTime.options[oTime.selectedIndex].value))
	{
		oErr5.style.display = 'inline';
		bRet = false;
	}
	
	
	return bRet;
}

function markAsClicked(oDiv)
{
	var arDivs = oDiv.parentNode.childNodes;
	for(var i=0; i<arDivs.length; i++)
		arDivs[i].className = 'aucparcel';
	oDiv.className = 'aucparcel_active';
}
function cancelParcel(iNr, iId)
{
	document.getElementById('cancelReason').style.display = 'block';
	var sLabel = document.getElementById('cancelParcelLabel').innerHTML;	
	if(sLabel.indexOf('{parcelnr}') != -1)
		document.getElementById('cancelParcelLabel').innerHTML = sLabel.replace(/\{parcelnr\}/,'<b>#' + iNr + '</b>');	
	else
		document.getElementById('cancelParcelLabel').innerHTML = sLabel.replace(/\<b>\#[^\<]*\<\/b>/,'<b>#' + iNr + '</b>');	
	document.forms["cancelParcelForm"].parcelId.value = iId;
	document.forms["cancelParcelForm"].parcelNr.value = iNr;
}

function roundDecimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function showPreview()
{
	var oProd = document.getElementById('rec[productid]');
	var oHour = document.getElementById('rec[endtime]');
	var oYear = document.getElementById('rec[year]');
	var oWeek = document.getElementById('rec[available]');
	var iYear, iWeek;
	
	document.getElementById('preview').style.display = "block";
	document.getElementById('prodname').innerHTML = (oProd.selectedIndex != -1) ? oProd.options[oProd.selectedIndex].text : '';
	document.getElementById('proddesc').innerHTML = document.getElementById('descriptionArea').innerHTML;
	document.getElementById('quant').innerHTML = document.getElementById('rec[quantity]').value;
	document.getElementById('enddate').innerHTML = document.getElementById('rec[enddate]').value + ' ' + 
		((oHour.selectedIndex != -1 && oHour.options[oHour.selectedIndex].value) ? oHour.options[oHour.selectedIndex].text + ':00' : '' );
	if(oYear.selectedIndex != -1 && (iYear = oYear.options[oYear.selectedIndex].value) 
		&& oWeek.selectedIndex != -1 && (iWeek = oWeek.options[oWeek.selectedIndex].value))
	{	
		var sDate = new Date(iYear,0,1);
		var sStartDate = sDate;
		sStartDate.setDate(sStartDate.getDate() + (iWeek - 1) * 7);
		if(sStartDate.getDay() == 0)
			sStartDate.setDate(sStartDate.getDate() + 1);
		
		var sEndDate = new Date(sStartDate.getFullYear(),sStartDate.getMonth(),sStartDate.getDate());
		sEndDate.setDate(sEndDate.getDate() + 6);

		var iStartM = sStartDate.getMonth() + 1;
		if(iStartM.toString().length == 1)
			iStartM = '0' + iStartM;
		iEndM = sEndDate.getMonth() + 1;
		if(iEndM.toString().length == 1)
			iEndM = '0' + iEndM;
		
		document.getElementById('weekstart').innerHTML = sStartDate.getDate() + '-' + iStartM + '-' + sStartDate.getFullYear();
		document.getElementById('weekend').innerHTML = sEndDate.getDate() + '-' + iEndM + '-' + sEndDate.getFullYear();
	}
	document.getElementById('controlmarkYes').style.display = "none";
	document.getElementById('controlmarkNo').style.display = "none";
	if(document.getElementById('rec[controlmark]').checked)
		document.getElementById('controlmarkYes').style.display = "inline";
	else
		document.getElementById('controlmarkNo').style.display = "inline";
	var iPrice = document.getElementById('rec[buyprice]').value;
	if(iPrice)
	{
		if(iPrice.indexOf(',') != -1)
			iPrice = iPrice.replace(/\,/,'.');	
		iPrice = roundDecimals(iPrice,3);
		iPrice = iPrice.replace(/\./,',');
		document.getElementById('buyprice').innerHTML = '&euro; ' + iPrice;
	}
	else
		document.getElementById('buyprice').innerHTML = '';
}

function showPreviewBid()
{	
	var oForm = document.forms["formbid"];
	var iPrice = oForm.aucBid.value;
	
	document.getElementById('preview').style.display = "block";
	if(iPrice)
	{
		if(iPrice.indexOf(',') != -1)
			iPrice = iPrice.replace(/\,/,'.');	
		iPrice = roundDecimals(iPrice,3);
		iPrice = iPrice.replace(/\./,',');
		document.getElementById('bid').innerHTML = '&euro; ' + iPrice;
	}	
	else
		document.getElementById('bid').innerHTML = '';
	document.getElementById('validity').innerHTML = oForm.aucBidPeriod.value
}

function checkPlaceParcelPreview(oForm)
{
	var bRet = true;
	var oElem = oForm.chkAgree;
	document.getElementById(oElem.name + 'Err').style.display = 'none';
	if(!oElem.checked && document.getElementById(oElem.name + 'Err'))
	{
		document.getElementById(oElem.name + 'Err').style.display = 'block';
		bRet = false;
	}
	return bRet;
}

function checkPutBidPreview(oForm)
{
	var bRet = true;
	document.getElementById('aucAgreeErr').style.display = 'none';
	if(!oForm.aucAgree.checked)
	{
		document.getElementById('aucAgreeErr').style.display = 'block';
		bRet = false;
	}
	return bRet;
}
