

function MakeFrameName (FormName, Input)
{
	var IE_FrameName = ""
	for (var i = 0; i< Input.length; ++i)
	{
		var Char = Input.charAt(i)
		if ((Char == "-") || (Char == ".")) {Char ="_"}
		if (
			((Char.charCodeAt(0) >= 65) && (Char.charCodeAt(0) <= 90)) ||
			((Char.charCodeAt(0) >= 97) && (Char.charCodeAt(0) <= 122)) ||
			((Char.charCodeAt(0) >= 48) && (Char.charCodeAt(0) <= 57)) ||
			(Char == "_")
			)
		{
			IE_FrameName += Char;
		}
	}
	
	IE_FrameName += "_" + FormName;
	return IE_FrameName
}



function QuerySearchWindow(theURL, Largeur, Hauteur, FrameName) 
{
	var WinLocAttributes = ", top=" + GetWinTopPos() + ", left=" + GetWinLeftPos();	
	var Newwindow=window.open(theURL,FrameName,'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,top=0,left=0,width=' + Largeur + ',height=' + Hauteur + WinLocAttributes);
	if (Newwindow) { Newwindow.focus(); }
	return (Newwindow);
}


function PromptECHADatabase(theForm, Location, DisplayWIN, DefaultWWWPath) 
{
	var DefaultWWWPath = 'http://www.echemportal.eu'
	//var DefaultWWWPath = ''
	if (BrowserDetect.browser == "Explorer") {DefaultWWWPath = ''}
	if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
	{ 
		IncrementWinLocation(10, 10); // left, top
	   	var Qwin = QuerySearchWindow(DefaultWWWPath,970,450,DisplayWIN);		
		theForm.target = DisplayWIN;
		theForm.submit();
		return Qwin;
    }
	return false;
}


function QueryEchaDatabase(SearchParams, FormName, Location) 
{
	var theForm = document.forms[FormName];
	//if (!theForm) { theForm = document.EchaSearchForm;}	
	
	
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
	{		
        theForm.ctl00$ctl00$CPHContent$CPHPageContent$TextBox2.value = SearchParams[0]; // Search pattern
		theForm.ctl00$ctl00$CPHContent$CPHPageContent$DropDownList3.value = SearchParams[1]; // "EC" or "CAS" or "NAMEORSYNONYM" or "ALL"
		theForm.ctl00$ctl00$CPHContent$CPHPageContent$searchRadioButtons.value = SearchParams[2]; // "start", or "contain", or "exact"
		PromptECHADatabase(theForm, Location, MakeFrameName(FormName, SearchParams[3]))
    }
}
