function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must be an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  }
  if (validateRadio(document.getElementById('form1')) != '') {
	errors+= validateRadio(document.getElementById('form1'))
  }
  if (errors) alert('Please fill out all the following required fields\nbefore submitting this form.\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_validateForm3() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm3.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must be an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  }
//  if (validateRadio(document.getElementById('form1')) != '') {
//	errors+= validateRadio(document.getElementById('form1'))
//  }
  if (errors) alert('Please fill out all the following required fields\nbefore submitting this form.\n'+errors);
  document.MM_returnValue3 = (errors == '');
}

function MM_validateForm2() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must be an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  }
  if (errors) alert('Please fill out all the following required fields\nbefore submitting this form.\n'+errors);
  document.MM_returnValue = (errors == '');
}

function validateRadio(oForm) {

	bUnchecked = false;
	radioErrors = ""
	profileErrors = ""

/*
	//check companyGroup
	bNoSelected = false;
	bYesSelected = false;
	for (var i=0;i < oForm.length;i++) {
		if ((oForm.elements[i].name == 'companyGroup') && (oForm.elements[i].value == 'no') && (oForm.elements[i].checked)) {
			bNoSelected = true;
		}
		if ((oForm.elements[i].name == 'companyGroup') && (oForm.elements[i].value == 'yes') && (oForm.elements[i].checked)) {
			bYesSelected = true;
		}
	}
	//check yes/no
	if (bNoSelected == true || bYesSelected == true) {
	} else {
		bUnchecked = true;
		radioErrors = radioErrors + '- companyGroup (y/n) is required\n'
	}

	//check Sites
	bNoSelected = false;
	bYesSelected = false;
	for (var i=0;i < oForm.length;i++) {
		if ((oForm.elements[i].name == 'companySite') && (oForm.elements[i].value == 'no') && (oForm.elements[i].checked)) {
			bNoSelected = true;
		}
		if ((oForm.elements[i].name == 'companySite') && (oForm.elements[i].value == 'yes') && (oForm.elements[i].checked)) {
			bYesSelected = true;
		}
	}
	//check yes/no
	if (bNoSelected == true || bYesSelected == true) {
	} else {
		bUnchecked = true;
		radioErrors = radioErrors + '- companySite (y/n) is required\n'
	}
*/

	//check profile
	for (var iCount=1; iCount < 11; iCount++) {
		bNoSelected = false;
		bYesSelected = false;
		for (var i=0;i < oForm.length;i++) {
			if ((oForm.elements[i].name == iCount) && (oForm.elements[i].value == 'no') && (oForm.elements[i].checked)) {
				bNoSelected = true;
			}
			if ((oForm.elements[i].name == iCount) && (oForm.elements[i].value == 'yes') && (oForm.elements[i].checked)) {
				bYesSelected = true;
			}
		}
		//check yes/no
		if (bNoSelected == true || bYesSelected == true) {
		} else {
			bUnchecked = true;
			profileErrors = '- All profile questions (y/n) are required\n'		
		}

	}	

	if (bUnchecked == true) {
		return(radioErrors + profileErrors)
	} else {
		return('')
	}
}

function popup (href, name, width, height) {
	var winW = width
	var winH = height
	var winName = name
	var winL = (screen.width - winW) / 2;
    var winT = (screen.height - winH) / 2;
	theWindow = window.open(href, winName, 'location=no, toolbar=no, status=no, directories=no, scrollbars=yes, menubar=0, resizable=yes, left=' + winL + ', top=' + winT +', width=' + winW + ', height=' + winH);
	theWindow.focus();
}

function toggle( targetId ){   
	if (document.getElementById){         
	target = document.getElementById( targetId );            
		if (target.className == "noDisplay"){               
		target.className = "";
	} else {               
		target.className = "noDisplay"; 
	}      
	} 
}
function toggleElements(targetId,prefix,upperRange){   
	if (document.getElementById){         
	
	//remove previous showing divs
	for (var x = 1; x <= (upperRange); x++)
	{
	tempSuffix = prefix+(x)
//	document.write (tempSuffix);
		if (x==3 || x==7 || x==8 ||  x==10 || x==9 ){
		
			tempTarget = document.getElementById(tempSuffix);
			//alert(tempTarget);
			if (tempTarget.className == ""){ 
			tempTarget.className = "noDisplay";
			tempTarget.value = ""
	//		document.write('test');
			}
		}
	}
	y = (targetId)
	if (y==3 || y==7 || y==8 || y==10 || y==9 ){	
	//document.write 
	
	target = document.getElementById(prefix+(targetId));            
			if (target.className == "noDisplay"){               
				target.className = "";
			} else {               
				target.className = "noDisplay"; 
			} 
		}
	} 
}
//for captcha image changing
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function flipMandatory(oForm,sFieldName,sValue){
	//check for selectedindex..
	if (sValue==9 || sValue==10 || sValue==11 || sValue==12 || sValue==13){
	//make the details box mandatory
	//document.getElementById('validation').value = document.getElementById('validation').value + ', '+sFieldName.replace(/Diff/,'DiffDetails');
	
		oForm[sFieldName.replace(/Diff/,'DiffDetails')].value = '';
	
	oForm[sFieldName.replace(/Diff/,'DiffDetails')].style.backgroundColor = '#FFCCCC';
	
	alert('Please enter comments for your selection');
	}
	else{
		oForm[sFieldName.replace(/Diff/,'DiffDetails')].value = ' ';	
		oForm[sFieldName.replace(/Diff/,'DiffDetails')].style.backgroundColor = '';
	}
}

function productShowSummary(sID,sStyle){
	//change the style of the given element ID (its a blank version of the existing one so the summary can be read over the top
	//also show the summary div
	document.getElementById(sID).className = sStyle;
	
	document.getElementById(sID+'Summary').className  = 'productSummaryShow';
	document.getElementById(sID+'UnitCost').style.display  = 'none'; //hide the unit cost circle
	document.getElementById(sID+'Image').style.display  = 'none'; //hide the custom image
}

function productHideSummary(sID,sStyle){
	//hide the summary div
	//change the style of the given element ID to the one provided
	document.getElementById(sID).className  = sStyle;
	document.getElementById(sID+'Summary').className  = 'productSummary';
	document.getElementById(sID+'UnitCost').style.display  = 'block'; //show the unit cost circle
	document.getElementById(sID+'Image').style.display  = 'block'; //show the custom image
}

var openProductPanel = '1' //default open position global

function showPanel(sID,iRegID){
	//alert (openProductPanel);
	
	document.getElementById('productPanel'+sID).style.display='block';	
	document.getElementById('productPanelTab'+sID).className = 'selected'+iRegID
	
	//close the currently open tab
	if ('productPanel'+openProductPanel!='productPanel'+sID) {
		document.getElementById('productPanel'+openProductPanel).style.display='none'; //only closes it if not the open one
		document.getElementById('productPanelTab'+openProductPanel).className = '';
	}
	//reset the open prod panel
	openProductPanel = sID;
	
	//alert (openProductPanel);
}
function protectMail(address, domain, ext) {
	document.write('<a href="');
	document.write('ma'+'il'+'to:');
	document.write(address);
	document.write('&#64;');
	document.write(domain);
	document.write('.');
	document.write(ext);  
	document.write('">'); 
	document.write(address + '&#64;' + domain + '.' + ext + '</a>');
}



