if ("https:" == document.location.protocol)
{
	var www = "https://tcsrv4/custom/";
}
else
{
	var www = "http://tcsrv4/custom/";
}

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //test for MSIE x.x;
{ 
	var ieversion=new Number(RegExp.$1)

	if (ieversion<=7)
	{
		document.write("<link rel='stylesheet' type='text/css' href='"+www+"css/customSynthesisIE.css'>")
	}
}

// preload images

var preloadFlag = false;
function preloadImages() {
	if (document.images) {

		pre_DDMenuBgOvr 		= newImage('img/ddmenuBgOver.gif');
		pre_DDMenuBg2Ovr 	= newImage('img/ddmenuGreyFillOver.gif');
		pre_submitButtonOver 	= newImage('img/submitButtonOver.gif');

		preloadFlag = true;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

sfHover = function() {

	if (document.getElementById("nav"))
	{
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");

		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function printEAdd(em1, em2, em3, em4)
{
	if (em1 && em2)
	{
		if(!atxt)
		{
			var atxt = "E-Mail";
		}
		document.write('<a href=\"mailto:' + em1 + '@' + em2);
		if (em3)
		{
			document.write('?subject='+em3);
		}

		document.write('\"')

		if (em4)
		{
			document.write(' class=\"'+ em4 +'\" ');
		}

		document.write('>' + em1 + '@' + em2 + '</a>');
	}
	else
	{
		document.write(' -- No email address supplied -- ');
	}
}


function form_write(method, name, onsubmit, action)
{
	document.write("<form method='"+method+"' name='"+name+"' onsubmit='"+onsubmit+";' action='"+action+".php' enctype='multipart/form-data'>");
}


function input_write(type, src, srcOver, name, id, submit)
{
	document.write("<input type='"+type+"' src= '"+www+"img/"+src+"' name='"+name+"' id='"+id+"' onmouseover=\"changeImages('"+id+"','"+www+"img/"+srcOver+"');return true\" onmouseout=\"changeImages('"+id+"','"+www+"img/"+src+"');return true\"")
	if (submit == true)
	{
		document.write(" onclick='submit(this);return false'>");
	}
	else
	{
		document.write(">");
	}
}


function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}


function KeyUpNumeric(f)
{
	var keycode;
	if (window.event){
		keycode = window.event.keyCode;
	}
	else if (f){
		keycode = f.which;
	}

	if (keycode != 37 && keycode != 39){
		var re = /^[0-9]*$/;
		if (!re.test(f.value)) {
			alert("Only numbers allowed!");
			f.value = f.value.replace(/[^0-9]/g,"");
		}
	}
}

function KeyUpNoChars(f){

	var keycode;
	if (window.event){
		keycode = window.event.keyCode;
	}
	else if (f){
		keycode = f.which;
	}

	if (keycode != 37 && keycode != 39){
		var re = /['\''&'\"'&';'&'<'&'>'']/g;

		if (re.test(f.value)){
			alert("Character not allowed.");
		}
  		f.value = f.value.replace(re,'');
	}
}


function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null || value=="" || value==" " || value == 'Enter Target Here')
  		{
			alert(alerttxt);
			return false
		}
		else
		{
			return true
		}
	}
}

function validate_email(field,alerttxt)
{
	with (field)
	{
		atPos=value.indexOf("@")
		dotPos=value.lastIndexOf(".")
		if (atPos<1 || dotPos-atPos<2) 
		{
			alert(alerttxt);
			return false
		}
		else
		{
			return true
		}
	}
}

function validate_form(thisform)
{
	with (thisform)
	{
		if (Name2.value!="")
		{
			return false
		}

		if (validate_required(Name,"You are required to give your Name")==false)
		{
			Name.focus();
			return false
		}
		if (validate_required(Company,"You are required to specify your Company / Organisation")==false)
		{
			Company.focus();
			return false
		}
		if (validate_required(Country,"You are required to select a Country")==false)
		{
			Country.focus();
			return false
		}

		if (validate_email(E_mail,"It appears that your e-mail address is invalid. Please check your details and re-submit")==false)
		{
			E_mail.focus();
			return false
		}


		fs = document.getElementById("filename");
		var arrImage = new Array(".cdx", ".skc", ".pdf");
	
		if (fs.value != "")
		{
			if (!extensionAllowed(fs, arrImage))
			{
				alert("The selected file is not permitted. We can only accept ChemDraw (.cdx) and ISIS Draw (.skc) files");
				return false;
			}
		}

		var i=HowDidYouFindUs.length;

		for (var j=0; j < i; j++)
		{
			if (HowDidYouFindUs[j].checked)
			{
				var chk = j;
				break;
			}
		}

		if(chk !== "")
		{
			switch(chk)
			{
				case 0:
					if(Search_Engine_Specify.value == 0)
					{
						alert("Please select a search engine");
						return false;
					}
				break;

				case 2:
					if (validate_required(Link_Specify,"Please specify a web site")==false)
					{
						Link_Specify.focus();
						return false
					}
				break;

				case 6:
					if (validate_required(Other_Specify,"Please specify")==false)
					{
						Other_Specify.focus();
						return false
					}
				break;
			}
		}
	}
}

function extensionAllowed(fld, exts)
{
	ext=fld.value.substr(fld.value.lastIndexOf("."));
	for (x in exts)
	{
		if (ext.toLowerCase()== exts[x])
		{
			return true;
		}
	}
	flag = true
	fld.select();
	fld.focus();
	return false;
}

function valRadio(btn, alerttxt)
{
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--)
	{
		if (btn[i].checked)
		{
			return i;
			// cnt = i; i = -1;
		}
	}
	if (cnt == -1)
	{
		alert(alerttxt);
		return false;
	}
	else
	{
		return true;
	}
}


function bookmark_us(url, title)
{
	if (window.sidebar) // firefox
	{
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print)  // opera
	{
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all) // ie
	{
		window.external.AddFavorite(url, title);
	}
}

















function SetAction(val)
{
	if(val==0 || val==''){
		alert("Please select a country");
		return false;
	}

	setCookies(val);
	return true;
}


function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""

}



