

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 MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImageToThumb() { //v3.0 - sends a thumb version
  var i,j=0,x,a=MM_swapImageToThumb.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; 
   var destinationImgSrc = a[i+2];
   var destinationImgSrcThumb = destinationImgSrc.replace('.jpg','_thumb.jpg');
  // document.write(destinationImgSrcThumb);
   x.src=destinationImgSrcThumb;
   }
}
function MM_swapImageFromThumb() { //v3.0 - sends a thumb version
  var i,j=0,x,a=MM_swapImageFromThumb.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; 
   var destinationImgSrc = a[i+2];
   var destinationImgSrcFull = destinationImgSrc.replace('_thumb.jpg','.jpg');
   //document.write(destinationImgSrcFull);
   x.src=destinationImgSrcFull;
   }
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggle(targetId){   
	if (document.getElementById){         
	target = document.getElementById( targetId );            
		if (target.className == "noDisplay"){               
		target.className = "";
	} else {               
		target.className = "noDisplay"; 
	}      
	} 
}
function hide(targetId){   
	if (document.getElementById){         
	target = document.getElementById(targetId);                          
		target.className = "noDisplay";    
	} 
}
function show(targetId){   
	if (document.getElementById){         
	target = document.getElementById(targetId);                          
		target.className = "";    
	} 
}
function toggleElements(targetId,prefix,upperRange){   
	if (document.getElementById){         
	
	//remove previous showing divs
	for (var x = 1; x <= (upperRange-1); x++)
	{
	tempSuffix = prefix+(x)
//	document.write (tempSuffix);
		if (x==3 || x==7 || x==8 || x==9){
		
			tempTarget = document.getElementById(tempSuffix);
			if (tempTarget.className == ""){ 
			tempTarget.className = "noDisplay";
			tempTarget.value = ""
	//		document.write('test');
			}
		}
	}
	y = (targetId)
	if (y==3 || y==7 || y==8 || y==9){	
	//document.write (y)
	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();
}