arrayLabel = new Array();
arrayRegex = new Array();

arrayLabel['email']= '(valid) email address';
arrayRegex['email']= /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;

arrayLabel['fname']= 'first name';
arrayRegex['fname']= /^./;

arrayLabel['lname'] = 'last name';
arrayRegex['lname'] = /^./;

arrayLabel['company'] = 'company name';
arrayRegex['company'] = /^./;

arrayLabel['jobs_title'] = 'job title';
arrayRegex['jobs_title'] = /^./;

arrayLabel['jobs_description'] = 'job description';
arrayRegex['jobs_description'] = /^./;

arrayLabel['sales_id'] = 'recruiting contact';
arrayRegex['sales_id'] = /^./;

arrayLabel['telephone'] = 'telephone number in the format XXX-XXX-XXXX';
arrayRegex['telephone'] = /^([01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4})$/;
 
arrayLabel['subject'] = 'email subject';
arrayRegex['subject'] = /^./; 

arrayLabel['message'] = 'email message';
arrayRegex['message'] = /^./;

arrayLabel['file'] = 'file';
arrayRegex['file'] = /^./;

//arrayLabel['file'] = 'file location (or browse to it.)\nThe file should be in a .doc, .pdf, or .txt format';
//arrayRegex['file'] = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+\.(txt|TXT|pdf|PDF|doc|DOC)$/;

function clickHandler(){
}

function redirect(sURL){
	window.top.location.href=sURL;
}

function pauseThenRedirect(sURL,pause) {
	var sFunction = 'redirect(' + String.fromCharCode(39) + sURL + String.fromCharCode(39) + ')';
	self.setTimeout(sFunction,pause);  
} 

function openWindow(name,url,w) {
	var target = 'target_' + name;

	if (typeof w == 'undefined') {
		width = 640
	} else {
		width = w
	}

	if (typeof window[name] == 'undefined' || window[name].closed) {
		 window[name] = window.open(url,target,'left=20,top=20,width='+width+',height=520,toolbar=0,menubar=1,resizable=0,scrollbars=1');
	} else {
		// alert('Focus on open window.');
		window[name].focus()
	}
}

function isIn(val,arr) {
	for (n=0; n<arr.length; n++) {
		if (val == arr[n]) return true
	}
	return false
}


function validate(thisForm) {

	var formElements = thisForm.elements;

	for (i=0; i<formElements.length; i++) {
		
		if(isIn(formElements[i].name,arrayField)){
			if(!arrayRegex[formElements[i].name].test(formElements[i].value)){
				message = 'Please enter your ' + arrayLabel[formElements[i].name] + '.';
				alert(message);
				formElements[i].focus();
				return false;
			}
		}
	} 
	
	return true;
}

function doDelete(thisform){
	konfirm=confirm('Are you sure?');
	if(konfirm){
		thisform.webtask.value = 'delete';
		thisform.submit();
	} 
}

function doSave(thisform){
	if(validate(thisform)){
		thisform.webtask.value = 'save';
    	thisform.submit();
		}
}

	
function makeE(str) {
	var e = str + String.fromCharCode(64) + 'istmanagement' + String.fromCharCode(46) + 'com';
	return e;
}

function writeMailto(str) {
	var e = "<a href=\"mailto:" +makeE(str)+ "\">" +makeE(str)+ "</a>"
	document.write(e);
}



function sendEmail(thisForm) {

	var val=validate(thisForm)
	
	if(!val) return false;

	var msg = thisForm.optinMsg.value + "\nFor more information about how we handle your data, see our privacy statement at http://www.istmanagement.com/privacy.cfm.";
	
	var konfirm=confirm(msg);
	if(!konfirm) return false;

	return true;
}

function closeOrRedirect(opnr,web_root) {
	if (typeof opnr == 'undefined') {
			location.replace(web_root);
		} else {
			window.close();
		}

}

/* ================================= DOCSTOR FUNCTIONS ================================== */


function js_docstor_56qs(from_where)
	{
		var sAction = 'docstor_56Qs.cfm'
		var sTarget = 'docstor_56Qs'
		var oNewForm = make_form('fx2', sAction, sTarget)
		if (from_where!=null && from_where.length > 0){
			make_input(oNewForm, 'from_where',from_where);
			}
		else {
			make_input(oNewForm, 'from_where','public_web');
			}
		oNewForm.submit()
	}

function js_docstor_collaterals(from_where)
	{
		var sAction = 'docstor_collaterals.cfm'
		var sTarget = 'docstor_collaterals'
		var oNewForm = make_form('fx2', sAction, sTarget)
		if (from_where!=null && from_where.length > 0){
			make_input(oNewForm, 'from_where',from_where);
			}
		else {
			make_input(oNewForm, 'from_where','docstor_56Qs');
			}
		oNewForm.submit()
	}
