// JavaScript Document
<!-- Begin
// verify email address in form2
function verifyEmail(form2) {
checkEmail = form2.email.value
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
{alert("You have entered an invalid email address. Please try again.");
form2.email.select();
return false;
} 
else {
form2.submit();
}
}
// verify email address in form3
function verifyEmail(form3) {
checkEmail = form3.email.value
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
{alert("You have entered an invalid email address. Please try again.");
form3.email.select();
return false;
} 
else {
form3.submit();
}
}
// Required fields
function getNumericFormElement(f, name) {
		var element;
		for (var i = 0, element=f.elements[i]; i < f.elements.length && element.name!=name; element=f.elements[i++]);
		return (element.name==name)?element:null;
}
function verifytype() {
			var frm = document.form2;
  if (getNumericFormElement(frm, "00N20000000iiZ3").value == "") {
    alert("Please select a Company Type");
  return false;
  }
}
function verifyrole() {
			var frm = document.form2;
  if (getNumericFormElement(frm, "00N20000000i2EJ").value == "") {
    alert("Please select an answer - What do you do and what types of companies are you looking to find?");
  return false;
  }
}

// new popup script
function windowOpener(url, name, args) {
if(typeof(popupWin) != "object" || popupWin.closed) {
popupWin = window.open(url,name,args);
} else {
popupWin.location.href = url;
}
popupWin.focus();
}
// enter date correctly
function enterDate(theField){
  var fMsg = "Please use this Format: DD/MM/YYYY hh:mm";
  var dV = theField.value;
  var vP = dV.match(/^(\d{1,2})\/?$/);
  if(!vP) vP = dV.match(/^(\d{1,2})\/(\d{1,2})\/?$/);
  if(!vP) vP = dV.match(/^(\d{1,2})\/(\d{1,2})\/(\d{1,4})\ ?$/);
  if(!vP) vP = dV.match(/^(\d{1,2})\/(\d{1,2})\/(\d{1,4})\ (\d{1,2})\:?$/);
  if(!vP) vP = dV.match(/^(\d{1,2})\/(\d{1,2})\/(\d{1,4})\ (\d{1,2})\:(\d{1,2})$/);
  if(vP!=null){
    if(vP[1]>31) return chkMsg(theField,"Date greater then 31\n"+fMsg);
    if(vP[2]>12) return chkMsg(theField,"Month greater then 12\n"+fMsg);
    if(vP[3]&&"200".indexOf(vP[3].substr(0,3))!=0) return chkMsg(theField,"Year can be only between 2004 and 2005");
    if(vP[3]>2005) return chkMsg(theField,"Year greater then 2005\n"+fMsg);
    dV  = chkAdd(vP[1],2,3,"/");
    dV += chkAdd(vP[2],2,2,"/");
    if(dV.length==6&&!vP[3])vP[3]="200";
    dV += chkAdd(vP[3],4,9,"");
    if(dV!=theField.value) theField.value=dV;
  } else {
    if(dV>"") chkMsg(theField,fMsg);
  }
}
function chkAdd(theVal,fLen,lVal,sChar){
  if(!theVal) return "";
  if(theVal>lVal&&theVal.length==1) return "0"+theVal+sChar;
  if(theVal.length==fLen) return theVal+sChar;
  return theVal;
}
var wVal="";
function chkMsg(theObj,theMsg){
  if(wVal!=theObj.value){
    alert(theMsg);
    theObj.select();
    theObj.focus();
  }
  wVal=theObj.value;
}
// change case of form fields
<!-- Original:  William Humphreys (billy@technical-solutions.co.uk) -->
function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}
// Check CAPS LOCK isn't on
// Script to detect if Caps Lock is engaged when a key is pressed in a text input
// v2.0.0 written by Mark Wilton-Jones, 1/11/2003
// http://howtocreate.co.uk
// Updated 19/02/2004 to run the function when caps lock is not engaged - see comments

var capsError = 'WARNING:\n\nCaps Lock is enabled\n\nThis form is case sensitive';

function capsError( capsEngaged ) {
		if( capsEngaged ) {
			//do something to warn the user that caps lock is engaged
		} else {
			//remove any warnings that caps lock is engaged
		}
	}
	
function capsDetect( e ) {
	if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false ); return; }
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}

function MWJ_say_Caps( oC ) {
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError ); } } else { capsError( oC ); }
}

// copy values from buyer fields to seller fields
function getNumericFormElement(f, name) {
		var element;
		for (var i = 0, element=f.elements[i]; i < f.elements.length && element.name!=name; element=f.elements[i++]);
		return (element.name==name)?element:null;
	}
function doCopyStuff() {
		var frm = document.form2;
	copyValues(getNumericFormElement(frm, "00N20000000iBXM"), getNumericFormElement(frm, "00N20000000iBXL"),frm.samevalue.checked);
	copyValues(getNumericFormElement(frm, "00N20000000iBXO"), getNumericFormElement(frm, "00N20000000iBXN"),frm.samevalue.checked);
	copyValues(getNumericFormElement(frm, "00N20000000iCZ2"), getNumericFormElement(frm, "00N20000000iBXP"),frm.samevalue.checked);
copyValues(getNumericFormElement(frm, "00N20000000iCYK"), getNumericFormElement(frm, "00N20000000iBXQ"),frm.samevalue.checked);
}
function copyValues(from, to, checked) {
     if(checked) {
           for(var i=0;i<from.length;i++) {
            from.options[i].selected = to.options[i].selected;
        }
    } else {
           for(var i = 0;i<from.length;i++) {
            from.options[i].selected = false;
        }
	}
}
//reload page preventing javascript "state" errors
function init() {
     var mystate = document.all["_state"];
     if ( mystate.value != null && mystate.value != "" ) {
         var ar = mystate.value.split(" ");
         for ( i = 0; i < ar.length; i++ ) {
             if ( document.all[ar[i]] )
                 document.all[ar[i]].style.visibility = "visible";
         }
     }
 }
//cursor position control
function setCursorPos( x ) {

    var txtRange = x.createTextRange();
    txtRange.moveStart( "character", x.value.length - 0 );
    txtRange.moveEnd( "character", 0 );
    txtRange.select();
}
// old popup script
function popup(FILE, FEATURES) { 
CONTENT = "<HTML><head><TITLE>Sample Report</TITLE></HEAD>" + "<BODY><CENTER><FORM><INPUT TYPE='BUTTON' VALUE='Close'" + "onClick='window.close()'></FORM></BODY></HTML>";
pop = window.open("","",FEATURES);
pop.document.open();
pop.focus();
pop.document.write(CONTENT);
pop.document.close();
} 
// Can't remember
function changeBox(cbox) {
box = eval(cbox);
box.checked = !box.checked;
}
// Status Bar Text
function a(txt) {
self.status = txt
}
function b() {
self.status = ""
}
// Parse and retrieve value across URL
function getValue(varname){
    var urlArray = location.search.split('&');    // Split into parts
    for(var no=0;no<urlArray.length;no++){    // Loop through variables
        parts = urlArray[no].split('=');    // Extract name and value
        parts[0] = parts[0].replace(/\W/g,'');    // remove non alpha characters from name
        if(parts[0]==varname){ // Match
            return parts[1];    
        }            
    }    
}    
//
//  End -->
