
function verifyDateSubSectors(strDate){
//alert(strDate);
//var strDate = document.oz.date1.value;
//if (strDate.length > 0){
var strMessageSubSector = ''
var strMessageSize = ''
var strMessageType = ''
var iFirstSlash = strDate.indexOf("/",0);
var iSecondSlash = strDate.indexOf("/",iFirstSlash+1);
var strDay = '';
var strMonth = '';
var strYear = '';

var dateundefined;

var dateformat = 'dd/mm/yyyy';

if (dateundefined != document.oz.dateformat) {
	dateformat = document.oz.dateformat.value;
}


if ( dateformat== 'dd/mm/yyyy'){
	strDay = strDate.substring(0,iFirstSlash);
	strMonth = strDate.substring(iFirstSlash+1,iSecondSlash);
}
else
{
	strMonth = strDate.substring(0,iFirstSlash);
	strDay = strDate.substring(iFirstSlash+1,iSecondSlash);

}
strYear = strDate.substring(iSecondSlash+1,strDate.length);

var fromDate = new Date();
var sectorDate = new Date();
var sizeDate = new Date();
var typeDate = new Date();
fromDate.setFullYear(strYear,(strMonth-1),strDay);
sectorDate.setFullYear(2001,7,1);
sizeDate.setFullYear(2002,5,17);
typeDate.setFullYear(2004,6,29);

var iCheckboxes=0
for (var j=0;j<document.oz.elements.length;j++){
	if (document.oz.elements[j].name == 'sizecode'){
		iCheckboxes = iCheckboxes + 1
	}
}

var sizeChecked = false;
for (var k=0;k<iCheckboxes;k++){
	if (document.oz.sizecode[k].checked == true){
		sizeChecked = true;
	}
}
iCheckboxes=0
for (var j=0;j<document.oz.elements.length;j++){
	if (document.oz.elements[j].name == 'intelligencetypecode'){
		iCheckboxes = iCheckboxes + 1
	}
}
var typeChecked = false;
for (var k=0;k<iCheckboxes;k++){
	if (document.oz.intelligencetypecode[k].checked == true){
		typeChecked = true;
	}
}

//var iLegacySubSectorIssue = 2;
//var iLegacySizeIssue = 4;
//var iIssues = 0;
if ((fromDate<=sectorDate)&&(document.oz.subsectorcode.selectedIndex != -1)){
	//iIssues = iIssues + iLegacySubSectorIssue
	strMessageSubSector = 'Following recent product development changes by mergermarket, users can now '+
				'search the intelligence database by subsector for intelligence posted after 01/08/2001.'+
				'\n\nPrior to that date, intelligence can be sorted by sector only.'
}
if ((fromDate<=sizeDate)&&(sizeChecked == true)){
	//iIssues = iIssues + iLegacySizeIssue
	strMessageSize = 'Following recent product development changes by mergermarket, users can now search '+
				'the intelligence database by size for intelligence posted after 17/06/2002. Prior to that '+
				'date intelligence cannot be filtered by size.'
}

if ((fromDate<=typeDate)&&(typeChecked == true)){
	//iIssues = iIssues + iLegacySizeIssue
	strMessageType = 'On 25 July 2004 mergermarket added more search options to the '+
				'Intelligence Type classification to help you refine searches.'+
				'All Intelligence searches prior to this date will '+
				'return results according to the old classification.'
}


if((strMessageSubSector=='') && (strMessageSize=='') && (strMessageType=='')){
	return true;
}
var strSubmit = true;
var strSubmitTemp = true;

if (strMessageSubSector!='')
{
	strSubmitTemp= confirm(strMessageSubSector)
}
	
if (strSubmitTemp==false )
{
	strSubmit=false
}
if  (strMessageSize!='')

{
	strSubmitTemp= confirm(strMessageSize)
}
if (strSubmitTemp==false )
{
	strSubmit=false
}

if (strMessageType!='')
{
	strSubmitTemp= confirm(strMessageType)
}
if (strSubmitTemp==false )
{
	strSubmit=false
}
return strSubmit;

}

function GoDefault(objListBox,strDefaults) {
	//alert("GoDefault:" + objListBox.name);	
	for (var i = 0;i<objListBox.options.length ;  i++) {
		if (TestDefaults(strDefaults,objListBox.options[i].value))	{
				objListBox.options[i].selected=true;
		}
	}
}
function TestDefaults(strDefaults,strValue) {
	var strDefaultItems= strDefaults.split(",");
	var z=false;
	for (var i=0; i < strDefaultItems.length; i++)	{
		if (strDefaultItems[i]==strValue) {
			z=true;
		}
	}  	
	return z;
}
	
	
function DefaultListBox(objListBox, strListBoxValue,strListBoxDescription) { 
var strDefaultValue= strListBoxValue.split(",");
//alert("strDefaultValue = " + strDefaultValue);
var strDefaultDescription= strListBoxDescription.split(","); 
var z=0; 
var arySortedListItems = new Array();
var j=0;
for (var i=0; i < strDefaultValue.length; i++)	{ 
	arySortedListItems[i] = new listBoxItem(strDefaultValue[i], strDefaultDescription[i]);
	}
if (strDefaultValue.length >=1){
	for (var i =0;i < arySortedListItems.length;i++) {
		for (var j =0;j < (arySortedListItems.length); j++) {
			if (arySortedListItems[j].description.toLowerCase()>arySortedListItems[i].description.toLowerCase()) {
				var tmpPkCode=arySortedListItems[i].pkCode
				var tmpDecription=arySortedListItems[i].description
				arySortedListItems[i].pkCode=arySortedListItems[j].pkCode
				arySortedListItems[i].description=arySortedListItems[j].description
				arySortedListItems[j].pkCode=tmpPkCode
				arySortedListItems[j].description=tmpDecription
			}
		}
	}
}
for (var i=0; i < arySortedListItems.length; i++)	{ 
	AppendDefaultListBoxItem(objListBox, arySortedListItems[i].pkCode, arySortedListItems[i].description.replace('%2C',','))
}

}
function listBoxItem(pkCode,description)
{
this.pkCode=pkCode
this.description=description
}
 
   
function AppendDefaultListBoxItem(objListBox, listBoxItemVlue, listBoxItemText) 
{ 
var newListBoxItem = document.createElement("option"); 
newListBoxItem.value = (listBoxItemVlue); 
newListBoxItem.text = (listBoxItemText); 
objListBox.options.add(newListBoxItem); 
} 

function restoreDefault(listBox1, listBox2, listBox3)
{
	if (listBox3) {
		emptySelect(listBox3);
	}
	emptySelect(listBox2);
		
	deselectAll(listBox1);
}


function appendListBoxItem(objListBox, listBoxItem)
{
	if (inListBox(objListBox,listBoxItem.childPKCode)==false)
	{
		var n_Opt = new Option();
		n_Opt.value = listBoxItem.childPKCode;
		n_Opt.text = listBoxItem.childDescription;
		objListBox.options[objListBox.options.length]=n_Opt;
		//var newListBoxItem = document.createElement("option");
		//newListBoxItem.value = listBoxItem.childPKCode;
		//newListBoxItem.text = listBoxItem.childDescription;
		//objListBox.options.add(newListBoxItem);
	}
}	

function inListBox(parrListBox, pstrName)
{
	var lbolResult = false;
	for(var loop = 0; loop < parrListBox.options.length; loop++)
	{
		if(parrListBox.options[loop].value == pstrName)
		{
			lbolResult = true;
			loop = parrListBox.options.length;
		}
	}
	return lbolResult;
}

function buildDefaultString(){
//builds string of paired values of multiple-select names and selected codes 
//for repopulating if user clicks back after having clicked search
	var strSearchDefaults='';
	var i=0;
	for(i=0;i<document.oz.elements.length;i++){		
		if(document.oz.elements[i].type=='select-multiple'){
			var selectedItems = '';
			if(document.oz.elements[i].name == 'companySysID'){
			//alert(document.oz.elements[i].options.length);
				var selectedItemValues = '';
				var selectedItemTexts = '';
				if(document.oz.elements[i].options.length > 0){
				
					for(var j=0;j<document.oz.elements[i].options.length;j++){					
						if (selectedItemValues == ''){
							selectedItemValues = document.oz.elements[i].options[j].value;
						}
						else {
							selectedItemValues = selectedItemValues + ',' + document.oz.elements[i].options[j].value;						
						}
						if (selectedItemTexts == ''){
							selectedItemTexts = document.oz.elements[i].options[j].text;
						}
						else {
							selectedItemTexts = selectedItemTexts + ',,' + document.oz.elements[i].options[j].text;						
						}					
					}
					//alert(selectedItemValues);alert(selectedItemTexts);
				selectedItems = selectedItemValues + '--' + selectedItemTexts;
				}
			}	
			else{
				
				if(document.oz.elements[i].selectedIndex != -1){					
					for(var j=0;j<document.oz.elements[i].options.length;j++){
						if(document.oz.elements[i].options[j].selected == true){
							if (selectedItems == ''){
								selectedItems = document.oz.elements[i].options[j].value;
							}
							else {
								selectedItems = selectedItems + ',' + document.oz.elements[i].options[j].value;
							}
						}
					}				
				}				
			}
			if (strSearchDefaults==''){ 
					strSearchDefaults = document.oz.elements[i].name + '=' + selectedItems;
				}
				else{	
					strSearchDefaults = strSearchDefaults + '|' + document.oz.elements[i].name + '=' + selectedItems;
				}
		}
	}
	//alert('searchdefaults = '+strSearchDefaults);

document.oz.currentSearchDefaults.value = strSearchDefaults;
}

//function to populate listBox2 according to selections of listBox1
function fillSelect(objListBox, classCodes, pkCodes)
{
	for(var i=0;i<lookupStuff.length;i++)
	{
		if (classCodes!=null) {
			if (existsIn(lookupStuff[i].childGroupCode,classCodes))
			{
				appendListBoxItem(objListBox, lookupStuff[i]);
			}
		}
		else if (pkCodes!=null) {
			if (existsIn(lookupStuff[i].parentPKCode,pkCodes))
			{
				appendListBoxItem(objListBox, lookupStuff[i]);
			}
		
		}
	}
}

function fillSelectfiltered(objListBox, childGroupCode,parentGroupCode_filter,parentPKCode_filter)
{
	for(var i=0;i<lookupStuff.length;i++)
	{
			if (lookupStuff[i].childGroupCode == childGroupCode && lookupStuff[i].parentGroupCode == parentGroupCode_filter  && lookupStuff[i].parentPKCode == parentPKCode_filter)
			{
				appendListBoxItem(objListBox, lookupStuff[i]);
			}
	}
}


//function to build array to populate the listBoxes
function buildSelectedItems(objListBox)
{
	var selectedItems=new Array();
	var j=0;
		for (var i = objListBox.options.length - 1; i >= 0; --i) {
			if (objListBox.options[i].selected)	{
				selectedItems[j++]=objListBox.options[i].value;
			}
		}
	return selectedItems;
}

//function to check if an item is selected in a list box
function isListItemSelected(objListBox,strPKCode)
{
		for (var i = objListBox.options.length - 1; i >= 0; --i) 
		    {
			if (objListBox.options[i].selected & objListBox.options[i].value == strPKCode){return true;}
		    }
	return false;
}

function emptyListBox(objListBox)
// Empty the SELECT element of all it's options.
{
	while (objListBox.options.length > 0)
		objListBox.options[0] = null; 
}


function deselectAll(objListBox)
// Fixer Function for IE5
{
	var idxSelected = objListBox.options.selectedIndex;

	// If there is nothing to do, don't do anything...
	if (objListBox.options.length == 0 || idxSelected == -1)
	return;

	// The Fix: remove selection from add box
	for (i = objListBox.options.length - 1; i >= 0; --i)
	{
	if (objListBox.options[i].selected)
		objListBox.options[i].selected = false;
	}
}

function selectAll(objListBox)
// Fixer Function for IE5
{
	var idxSelected = objListBox.options.selectedIndex;

	// If there is nothing to do, don't do anything...
	if (objListBox.options.length == 0)
	return;

	// The Fix: remove selection from add box
	for (i = objListBox.options.length - 1; i >= 0; --i)
	{
	//if (!objListBox.options[i].selected)
		objListBox.options[i].selected = true;
	}
}

function removeLookupOption(objListBox)		
{
	// If there is nothing to do, don't do anything...
	if (objListBox.options.length == 0)
	return;
			
	for (i = objListBox.options.length - 1; i >= 0; --i)
	{
	if (objListBox.options[i].selected== true){
		objListBox.options[i]=null; 
		}
	}
}

function inArray(parrElems, pstrName)
{
	var lbolResult = false;
	
	for(var loop = 0; loop < parrElems.length; loop++)
	{
		if(parrElems[loop] == pstrName)
		{
			lbolResult = true;
			loop = parrElems.length;
		}
	}
	
	return lbolResult;
}

function selectCheckboxes(strCheckBoxGroupName, strCheckBoxValues, blnCheck)
{
	var i=0;
    var aobjCheckBoxes;
    var astrCheckBoxValues;
    
    aobjCheckBoxes = document.getElementsByName( strCheckBoxGroupName );
	if( aobjCheckBoxes == null ) return true;
    astrCheckBoxValues = strCheckBoxValues.split(',');
	if( astrCheckBoxValues == null ) return true;

	for (i=0;i<aobjCheckBoxes.length;i++)
	{
	    if(inArray(astrCheckBoxValues, aobjCheckBoxes[i].value))
	    {
	        if ( aobjCheckBoxes[i].disabled == false)
	            {
			     aobjCheckBoxes[i].checked = blnCheck;
			    }
		}
	}
}

function ReplaceMe(strString){
   var rme1, rme2, re;
   var ss = strString;
   rme1 = ss.replace('&', '%26');
   rme2 = rme1.replace('\'', '\'');
   return(rme2);
   
}


/*************************************************/
//	deprecating this to use new function with locale information 
//				(see below)
//	author		cjs
//	date		2003-11-14
/*************************************************/
function defaultDates(objDateFrom,objDateTo){
	var dateToValue = eval('document.oz.' + objDateTo + '.value');
	var dateFromValue = eval('document.oz.' + objDateFrom + '.value');
	var dateTo = eval('document.oz.' + objDateTo)
	var dateFrom = eval('document.oz.' + objDateFrom)
	if (dateFromValue == ''){
		dateFrom.value = '01/01/2005';		
	}
	if (dateToValue == ''){		
		var todayDate = new Date();
		var todayDay = todayDate.getUTCDate();
		var todayMonth = todayDate.getUTCMonth()+1;
		var todayYear = todayDate.getYear() + ((isGecko())?1900:0);
		//alert(todayYear);
		dateTo.value =todayDay.toString() + '/' + todayMonth.toString() + '/' + todayYear.toString();	
		//dateTo.value =todayDate;	
	}	
}
/*************************************************/
//	deprecating this is new locale version
//	author		cjs
//	date		2003-11-14
/*************************************************/
function defaultDatesWithLocale(objDateFrom,objDateTo, dateFormat){
	
	/*if (objDateFrom.value == '')
	{
		var aDate = new MMDate( '01/01/2005', 'dd/mm/yyyy' );
	
		objDateFrom.value = aDate.getDateAsFormat( dateFormat );		
	}
	if (objDateTo.value == '')
	{		
		var aDate = new MMDate( '01/01/2005', 'dd/mm/yyyy' );
		
		aDate.setToNow();	
		
		objDateTo.value = aDate.getDateAsFormat( dateFormat );	
	}*/	
	defaultDatesWithLocaleEx(objDateFrom,objDateTo, dateFormat, '2005-01-01T00:00:00')
}

//MCS 2006-05-08 Case 14308 -- Pass in default Start date as UTC String
function defaultDatesWithLocaleEx(objDateFrom,objDateTo, OutputDateFormat, sStartUTCDateString){
	
	if (objDateFrom.value == '')
	{
		var aDate = new MMDate(sStartUTCDateString, 'yyyy-mm-ddThh:MM:ss' );
	    objDateFrom.value = aDate.getDateAsFormat( OutputDateFormat );		
	}
	if (objDateTo.value == '')
	{		
		var aDate = new MMDate(sStartUTCDateString, 'yyyy-mm-ddThh:MM:ss' );
		
		aDate.setToNow();	
		
		objDateTo.value = aDate.getDateAsFormat( OutputDateFormat );	
	}	
}

//MCS 2008-03-05 Case 72840  -- Set start date X Months back
function defaultDatesWithLocaleSetMonth(objDateFrom,objDateTo, OutputDateFormat, iMonthDiff){
	var sStartUTCDateString = '2005-01-01T00:00:00'
	
	if (objDateFrom.value == '')
	{
		var aDate = new MMDate(sStartUTCDateString, 'yyyy-mm-ddThh:MM:ss' );
		aDate.setToNow();	
	    aDate.setXMonths(iMonthDiff);
	    objDateFrom.value = aDate.getDateAsFormat( OutputDateFormat );		
	}
	if (objDateTo.value == '')
	{		
		var aDate = new MMDate(sStartUTCDateString, 'yyyy-mm-ddThh:MM:ss' );
		
		aDate.setToNow();	
		
		objDateTo.value = aDate.getDateAsFormat( OutputDateFormat );	
	}	
}
//MCS 2006-05-08 Case 14308 Move to library
function isWMCustomDateRangeSelected()
{
    var bReturnValue= false;
    for(var i=0;i<document.oz.dateselection.length;i++)
    {
        if (document.oz.dateselection[i].value=='custom')
        {
            bReturnValue = document.oz.dateselection[i].checked;
        }
    }
    return bReturnValue;
}
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

function isChecked(f,elementname) {
	var checked=false;
    for (var i = 0; i<f.elements.length; i++) {
        if (f.elements[i].name != null && (f.elements[i].name.indexOf(elementname) > -1)) {
			//alert(elementname+"; req=" +e.required);
            if (f.elements[i].checked) {
                checked=true;
            }
        }
    }
    return(checked);
}

function wxverify(f,p,strHost, bUseTitles)
{
    return wxverify(f,p,strHost, false);
}

//TODO: if datatype validation fails, ignore other errors
//TODO: rename parameters to MAKE SENSE, DAMMIT!
function wxverify(f,p,strHost, bUseTitles)
{
	// This is a hook for date to checking.... 
	// Since verification is not generated from script so it is possible that date to is not part of the form
	// so everything is in a exception handler
	
	try
	{
		// If this function is not there then, it will blow up but...
		eval( 'CheckDateTo()' );
	}
	catch(e)
	{
	}
	
    var msg;
    var empty_fields = "";
    var errors = "";
	var atpos=0;
	var dotpos=0;
	var bCheckedTime=false;
	var bCheckedFrequency=false;

	/* the below variables are included for the locale project */
	if( f.localedateformat == null || f.localedateformat == 'undefined' )
	{
		userLocale = new Locale();
	}
	else
	{
		userLocale = new Locale( f.localedateformat, 
								 f.localecurrencycode,
								 f.localelanguagecode,
								 f.localetimezone );	
	}							
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];		
        
        //alert('name:'+e.name + ' *** type:' + e.type + ' *** required:' + e.required);
        //if (e.required) {
		//	alert('required:'+e.description);
		//}
        //errors  += "\n          t." + e.type + ":n." + e.name + ":v." + e.value + ":c." + e.checked + ":r." + e.required + ":r." + e.description;
        if (((e.type == "checkbox") || (e.type == "radio"))  && e.required) {
			//05/06/2006 - case 15968: If you fail to add a Frequency or Time to a wm alert the site crashes
			//the bChecked stuff is to ensure the error messagebox only puts up one instance of 'Time' &/or 'Frequency'
			if (!(isChecked(f,e.name))) {
				/*if (e.name=='timecode'){
					if(!bCheckedTime){
						bCheckedTime = true;
						empty_fields += "- " + e.description + "\n";
					}
				}
				else if(e.name=='frequencycode'){
					if(!bCheckedFrequency){
						bCheckedFrequency = true;
						empty_fields += "- " + e.description + "\n";
					}
				}
				else{
					empty_fields += "- " + e.description + "\n";
				}	//end if timecode or frequency check
				*/
				// firefox doesn't like the custom description attribute so check if the description has been put in the 'title' attribute instead
				if(e.title != undefined && bUseTitles)
				{
				    empty_fields += "\n          " + e.title;
				}
				else
				{
				    empty_fields += "\n          " + e.description;
				}
			}
        }
        else if ((e.type == "select-one") && e.required) {
        //else if ((e.type == "select-one") && e.required) {
            if ((e.options[e.selectedIndex].value == null) 
				|| (e.options[e.selectedIndex].value == "") 
				|| (e.options[e.selectedIndex].value == "ignore") 
				|| isblank(e.options[e.selectedIndex].value)) {
                empty_fields += "\n          " + e.description;
                continue;
            }

        }
        else if ((e.type == "select-multiple") && e.required) {
			var z=0;
			if(e.requiredCustomFunct != null) {
			    empty_fields += e.requiredCustomFunct();
			}
			else {
			    for (var j=0;j<e.options.length;j++) {
				    if (e.options[j].selected) {
					    z=1;
				    }
			    }			
			    if (z==0) {
			        // firefox doesn't like the custom description attribute so check if the description has been put in the 'title' attribute instead
			        if(e.title != undefined && bUseTitles)
			        {
			            empty_fields += "\n          " + e.title;
			        }
			        else
			        {
			            empty_fields += "\n          " + e.description;
			        }
			    }
			}
        }
        
        else if (((e.type == "hidden") || (e.type == "text") || (e.type == "textarea") || (e.type=="password")) && ((e.required) || (e.datatype))) {
            //remove trailing blank spaces before any validation:
			e.value = trim(e.value);     
			
			// FF won't recognise 'description' for textarea so look for description in 'title'
			var sDesc = "";
			if(e.type == "textarea" && e.title != undefined && bUseTitles)
			{
			    sDesc = e.title;
			}
			else
			{
			    sDesc = e.description;
			}
			
            if ((e.required) && ((e.value == null) || (e.value == "") || (e.value == "ignore") || isblank(e.value))) {
                empty_fields += "\n          " + sDesc;
                continue;
            }
            if (e.minlength) {
				if (e.value.length<e.minlength) {
					errors += "- " + e.description + " must contain at least " + e.minlength + " characters.\n";
				}
			}
			if (e.maxlength) {
					if (e.value.length>e.maxlength) {
						errors += "- " + e.description + " must contain less than " + e.maxlength + " characters.\n";
					}

			 }
			
			if (!((e.value == null) || (e.value == "") || (e.value == "ignore") || isblank(e.value))) { 
            	
				if ((e.datatype=="email")) {
					var regexTemplate=/^([a-zA-Z\d\-\_\.\+\*\'\`\&]+)@([a-zA-Z\d\-\+\_\.]+[\.][a-z]{2,4})$/;
					
					var strMultipleEmails= e.value.split(";");
					var z=0;
					for (var z=0; z < strMultipleEmails.length; z++)	{ 	
						if (!regexTemplate.test(trim(strMultipleEmails[z]))) {
							errors += "- " + e.description + " is not a valid email address.\n";
						}
					}
				}
				if ((e.datatype=="date")) 
				{	 
					if (userLocale.localeIsSet)
					{	
						var aMMDate = new MMDate( e.value, userLocale.dateformat );
						//alert( aMMDate == null );											
						if (aMMDate == null || aMMDate.oDate == null || !aMMDate.isValid())
						{
						    errors += "- " + e.description + " is not a valid date. Format: " + userLocale.dateformat + "\n";
						}
						else if (e.max)					 
					    {
    					    //checks whether the date is less than the max passed in.
						    var MMDateMax = new MMDate(e.max, userLocale.dateformat);		
						    if( MMDateMax != null || MMDateMax.oDate != null || MMDateMax.isValid() )
						    {				
						        var inputdate = aMMDate.toUKDate();						
						        var maxdate = MMDateMax.toUKDate(); 						
					            inputdate = Date.parse(inputdate); 
					             maxdate = Date.parse(maxdate);					
        					
						        if(inputdate >= maxdate)
                               {
                                  errors += "- " + e.description + " must be less than " + e.max + "\n";                                   
                               }
                               
						    }
						}
					}
					else if (!isValidDateTime(e.value,0))  // no locale set
					{
					    errors += "- " + e.description + " is not a valid date. Format: dd/mm/yyyy\n";
					}
					
						
				}
				if ((e.datatype=="datetime")) 
				{
					if( userLocale.localeIsSet )
					{	
						var aMMDate = new MMDate( e.value, userLocale.dateformat + ' hh:MM' );
						//29/11/2006 - stevep - Case 21470: admin - save opp need to validate the set to final date/time format
						//dateArray is not created if the datetime is invalid
						if(aMMDate.dateArray==null){
							errors += "- " + e.description + " is not a valid date time. Format: " + userLocale.dateformat +  " hh:MM" + "\n";
						}		
						else if( ! aMMDate.isValid() ) errors += "- " + e.description + " is not a valid date time. Format: " + userLocale.dateformat +  " hh:MM" + "\n";
					}
					else if (!isValidDateTime(e.value,1)) {
						errors += "- " + e.description + " is not a valid date time. Format: dd/mm/yyyy hh:mm\n";
					}
				}
				
				if ((e.datatype=="real")) {
					var regexTemplate=/\d{6}\.\d{4}/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid number. Format: 1234.34\n";
					}
				}
				if ((e.datatype=="decimal")) {
					var regexTemplate=/^[0-9\.]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid number. Format: 1234.34\n";
					}
				}
				// allow only 3 decimal places
				if ((e.datatype=="decimal3")) {
					var regexTemplate=/^(\d+\.\d{0,3}|\d+)$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid number. Format: 1234.345\n";
					}
				}
				
				// allow only 3 decimal places with max value
				// Add maxvalue property to your object to validate agains it
				// Add custommessage property to your object to display different message than default one.
				if ((e.datatype=="decimal3withmaxvalue")) {
					var regexTemplate=/^(\d+\.\d{0,3}|\d+)$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid number. Format: 1234.345\n";
					}
					else if (e.value>e.maxvalue)
					{
					    
					    if (e.custommessage==undefined)
						    errors += "- " + e.description + " exceeded. Please enter valid " + e.description + " to continue.\n";
						else
						    errors += "- " + e.custommessage;
					}
				}
				
				if ((e.datatype=="decimalNew")) {
					var regexTemplate=/^[0-9\/\\\.\-]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid number. Format: (-) 1234.34\n";
					}
				}
			
				if ((e.datatype=="character")) {
					var regexTemplate=/^[a-zA-Z]$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="alpha")) {
					var regexTemplate=/^[a-zA-Z ]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="alphaname")) {
				//allows inclusion of standard non-alpha characters in a name such as hypens, where appropriate.
				//added May 3 2005 SMJ
					var check=/^[a-zA-Z\- ]{2,}$/;
					var checkSpace=/[  ]{2,}/;
					var checkHyphen=/^[\-]|[\-]$/;
					var strName = e.value;
					//clean up entry first:
					strName = strName.replace(/[  ]{2,}/g, " ");
					strName = strName.replace(" -", "-");
					strName = strName.replace("- ", "-");
					strName = strName.replace(/[--]{2,}/g, "-");
					e.value = strName;
					//check it is at least 2 characters long
					if(strName.length<2){
						errors += "- " + e.description + " is too short.\n";
					}
					//check it only contains A-Z, a-z, hyphens and spaces.
					if( strName.search(check) == -1 ){
						errors += "- " + e.description + " contains invalid characters.\n";
					}
					//check that hyphens only occur between words.
					if( strName.search(checkHyphen) != -1 ){
						errors += "- " + e.description + " may only contain hyphens between words.\n";
					}
				}
				if ((e.datatype=="alphanumeric")) {
					var regexTemplate=/^[a-zA-Z0-9 ]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="username")) {
					var regexTemplate=/^[a-zA-Z0-9 \@\.\_\-]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="alphanumerictextarea")) {
					//var regexTemplate=/^[a-zA-Z0-9\s]+$/;
					var regexTemplate=/^[a-zA-Z0-9\/\\\.\*\+\?\|\(\)\[\]\{\}\"\!\:\;\@\,\#\~\_\-\&\%\$\£ ]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="freetextarea")) {
					//var regexTemplate=/^[a-zA-Z0-9\s]+$/;
					var regexTemplate=/^[a-zA-Z0-9\/\\\.\*\+\?\|\(\)\[\]\{\}\"\'\!\:\;\@\,\_\-\–\&\$\£ ]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if ((e.datatype=="nodoublequotes")) {
					//var regexTemplate=/^[a-zA-Z0-9\s]+$/;
					if (e.value.indexOf('"') != -1) {
						errors += "- " + e.description + " contains invalid characters - no double quotes allowed.\n";
					}
				}
				if ((e.datatype=="productnumber")) {
					var regexTemplate=/^[a-zA-Z0-9\/\\\.\*\+\(\)\[\]\{\}\-\_ ]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}

				if ((e.datatype=="digit")) {
					var regexTemplate=/^\d$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				
				if ((e.datatype=="digits")) {
					var regexTemplate=/^\d+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				
				if ((e.datatype=="chardigit")) {
					var regexTemplate=/^[a-zA-Z]|\d$/
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if (((e.datatype) && (e.datatype.toLowerCase()=="integer"))) { //tolower to fix bug where had proper case 'Integer'
					var regexTemplate=/^\d+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid integer.\n";
					}
				}
				if ((e.datatype=="CommaSeparatedIntegers")) {
					var regexTemplate=/^[0-9,]+$/;
					var checkComma=/^[\,]|[\,]$/;
					var strName = e.value;
					//clean up entry first:
					strName = strName.replace(/[  ]{2,}/g, " ");
					strName = strName.replace(/[, ]{2,}/g, ",");
					strName = strName.replace(/[ ,]{2,}/g, ",");
					strName = strName.replace(/[,,]{2,}/g, ",");
					e.value = strName;
					
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid integer.\n";
					}
					//check that commas only occur between integers.
					if( strName.search(checkComma) != -1 ){
						errors += "- " + e.description + " may only contain commas between integers.\n";
					}
				}
				if ((e.datatype=="signedinteger")) {
					var regexTemplate=/^(\+|-)?\d+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid signed integer.\n";
					}
				}
				if ((e.datatype=="zip")) {
					var regexTemplate=/\d{5}(-\d{4})?/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " is not a valid zip code.\n";
					}
				}
				if ((e.datatype=="creditcard")) {
					if (!isCreditCard(e.value)) {
						errors += "- " + e.value + " is not a valid credit card number.\n";
					}
				}
				if ((e.datatype=="alertnames")) {
					var regexTemplate=/^[a-zA-Z0-9 \&]+$/;
					if (!regexTemplate.test(e.value)) {
						errors += "- " + e.description + " contains invalid characters.\n";
					}
				}
				if (e.datatype=="real" || 
					e.datatype=="digit" ||
					e.datatype=="digits" ||
					e.datatype=="decimal" || 				 
					(e.datatype && e.datatype.toLowerCase()=="integer") ||
					e.datatype=="signedinteger" || (e.min != null && e.min!="") || (e.max != null && e.max!="")) { 
				    var v = parseFloat(e.value);
				    
				    if 
				    (
			            (
			                isNaN(v) 
			            )
			            || 
			            (
			                (e.min != null) && (v < e.min)
			            )
			            || 
			            (
			                (e.max != null) && (v > e.max)
			            )
			            || 
			            (//allow specification of another field that it must be greater than
			                (e.greaterthan != null) && (v <= parseFloat(e.greaterthan.value))
			            )
			            || 
			            (//allow specification of another field that it must be less than
			                (e.lessthan != null) && (v >= parseFloat(e.lessthan.value))
			            )
				    ) 
				    {
				        if ((e.greaterthan != null) && (v <= parseFloat(e.greaterthan.value)))
				            errors += "- The field " + e.description + " must be greater than " + e.greaterthan.description + ".\n";
				        else if ((e.lessthan != null) && (v >= parseFloat(e.lessthan.value)))
				            errors += "- The field " + e.description + " must be less than " + e.lessthan.description + ".\n";
				        else
				        {
				            errors += "- The field " + e.description + " must be a number";
				            if (e.min != null) 
				                errors += " that is greater than " + e.min;
				            if (e.max != null && e.min != null) 
				                errors += " and less than " + e.max;
				            else if (e.max != null)
				                errors += " that is less than " + e.max;
				            errors += ".\n";
                        }
				    }
				}
				if (e.datatype=="decimal")
				{
				        if ((e.decimalplace!=null) &&  (e.value.indexOf(".")!=-1))
				        {
				            if (((e.value.length)-(e.value.indexOf(".")+1))>e.decimalplace){
		                        errors += "- The field " + e.description + " can only contain " + e.decimalplace + " decimal place.\n";
	                        }
				        }
				}
				if (e.datatype=="url") {
				    if ((e.value.indexOf("'") != -1) || (e.value.indexOf('"') != -1))
				        errors += "- The field " + e.description + " cannot contain single quotes or double quotes.\n";
				    else if ((e.value.indexOf("http://") != 0) && (e.value.indexOf("https://") != 0))
				        errors += "- The field " + e.description + " is not a valid url. Urls must start with 'http://' or 'https://'.\n";
				}
				
			}
		}
    }
	if (p) {
	 var minlength = 6;
		if (f.password.value!=f.confirmpassword.value) {
			errors +="- Your Password and Confirm Password do not match.\n"
			}
		}
				
		
		
		
	//errors +="- Your gender must be either Male or Female." + f.fldgender[1].checked
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += strHost + "\n";
    msg += "\n";
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
        msg += "- The following required field(s) are empty:\n" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

function trim(str)
{
 return( 
	(""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);
}


function isValidDateTime(strDate,intTime) {
	if (intTime==0) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	}
	else if (intTime==1) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4}) (\d{1,2})(:)(\d{1,2})$/;
	}
	else if (intTime==2) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4}) (\d{1,2})(:)(\d{1,2})$/;
	}
	
     //var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
     var matchArray = strDate.match(datePat);

     if (matchArray == null) return false;

     var month = matchArray[3];
     var day = matchArray[1];
     var year = parseInt(matchArray[4]);
     if (year>=0 && year<67) {year=2000+year};
     if (year>=67 && year<=99) {year=1900+year};
     
     //alert(year);
	 if (year < 1967 || year > 2100) return false;
     if (month < 1 || month > 12) return false;
     if (day < 1 || day > 31) return false;
     if ((month == 4 || month == 6 || month==9 || month == 11) && day == 31) return false;
     if (month == 2) {
          var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

          if (day > 29 || (day == 29 && !isleap)) return false;
     }
     return true;
}

function countWindow() {
  	openWindow = window.open('', 'CountRecords', 'width=220,height=150,resizable=0,scrollbars=0');
  document.oz.target = 'CountRecords'; 
  openWindow.focus();
}

function removeMe(objItem)
{
	objItem.value = ""
}

function GetDateFromDateFormat(strDate, strDateFormat)
{
	var i;
	var day;
	var month;
	var year;
	
	var arrDateArray;
	
	arrDateArray = strDate.split('/');

	i = strDateFormat.indexOf('dd');	
	if (i==1) 
	{
		day= arrDateArray[0];
		month=arrDateArray[1];
	}
	else
	{	
		day=arrDateArray[1];
		month= arrDateArray[0];
	}
	year = arrDateArray[2];
	
	//if hours, minutes and seconds are present they will be in the year bit
	return  day + '/' + month + '/' + year;
	
	
}

/* ***********************************************************
*
*	class:		Locale
*	author:		c stevenson
*	purpose:	accepts the locale information about a user and 
*				performs tests based on this information as to whether
*				a date is valid or not.
*
* ************************************************************
*/

//constructor definition
function Locale( dateformat, currencycode, languagecode, timezone )
{
	//set up member variables
	this.dateformat 	=	dateformat;
	this.currencycode 	= 	currencycode;
	this.languagecode 	= 	languagecode;
	this.timezone 		= 	timezone;
	this.dateToTest 	= 	'';
	this.dateArray 		= 	null;
	this.formatArray	= 	null;
	this.localeIsSet	=	false;
	
	if( dateformat == null || dateformat == 'undefined' ) return;
	if( currencycode == null || dateformat == 'undefined' ) return;
	if( languagecode == null || dateformat == 'undefined' ) return;
	if( timezone == null || timezone == 'undefined' ) return;
	
	this.localeIsSet	=	true;
}

function toggleParentCheckBox(element,iSiteBitWise){
	if (iSiteBitWise==1){
		if (element.checked) document.oz.sitebitwise[0].checked=true;
	}
	if (iSiteBitWise==16){
		if (element.checked) document.oz.sitebitwise[1].checked=true;
	}
	if (iSiteBitWise==2){
		if (element.checked) document.oz.sitebitwise[2].checked=true;
	}
	if (iSiteBitWise==8){
		if (element.checked) document.oz.sitebitwise[3].checked=true;
	}


}

function toggleChildCheckBox(element,iSiteBitWise){
//!!! this needs to be dynamically created - MCS
/*
	if (element.checked && iSiteBitWise==1){
	        var x = 0;
	        while (x <= 4)
	        {
	            document.oz.datafederation_1[x].checked=true; 
	            x++;
	        }
	}
	if (element.checked && iSiteBitWise==2){
	        var x = 0;
	        while (x <= 4)
	        {
	            document.oz.datafederation_2[x].checked=true; 
	            x++;
	        }
	}
	if (element.checked && iSiteBitWise==8){
	        var x = 0;
	        while (x <= 4)
	        {
	            document.oz.datafederation_8[x].checked=true; 
	            x++;
	        }
	}

	if (!element.checked && iSiteBitWise==1) {
		document.oz.datafederation_1[0].checked=false; 
		document.oz.datafederation_1[1].checked=false;
		document.oz.datafederation_1[2].checked=false;
		document.oz.datafederation_1[3].checked=false;
		document.oz.datafederation_1[4].checked=false;
	}
	if (!element.checked && iSiteBitWise==2) {
		document.oz.datafederation_2[0].checked=false; 
		document.oz.datafederation_2[1].checked=false;
		document.oz.datafederation_2[2].checked=false;
	}
	if (!element.checked && iSiteBitWise==8) {
		document.oz.datafederation_8[0].checked=false; 
		document.oz.datafederation_8[1].checked=false;
		document.oz.datafederation_8[2].checked=false;
	}
*/
}

function checkMinimumValue()
{
	
	if(document.oz.mindealvalue.value != '')
	{
		document.oz.undiscloseddealvalues.checked = false;
	}
	else
	{
		document.oz.undiscloseddealvalues.checked = true;
	}
	
}

// This fixes the sector combo boxes if a country is selected and state isn't. 
function triggerSectorLoad()
{
	if( document.oz.countrycode.value == 'USA' && document.oz.statecode != null && document.oz.statecode.options.length == 0)
		fillSelect(document.oz.statecode,null,buildSelectedItems(document.oz.countrycode));
}

function triggerSectorLoad_Target()
{
	if( document.oz.targetcountrycode.value == 'USA' && document.oz.targetstatecode.options.length == 0 )
		fillSelect(document.oz.targetstatecode,null,buildSelectedItems(document.oz.targetcountrycode));
}

function triggerSectorLoad_Bidder()
{
	if( document.oz.biddercountrycode.value == 'USA' && document.oz.bidderstatecode.options.length == 0 )
		fillSelect(document.oz.bidderstatecode,null,buildSelectedItems(document.oz.biddercountrycode));
}

function getradiovalue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function setradiovalue(radioObj, newValue) 
{
    
    if(!radioObj)
        return;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for(var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if(radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}
function setItemDisableStatus(oItem)
{
    if(!oItem)
        return;
    if (oItem.disabled)
        oItem.disabled = false;
    else
        oItem.disabled = true;
}
