function  Trim(str){
	while  (str.charAt(0)  ==  ' '){
	//  remove  leading  spaces       
		str  =  str.substring(1);
	}
	while(str.charAt(str.length  -  1)  == ' '){
	//  remove  trailing  spaces
		str  =  str.substring(0,str.length-1);
	}
	return str;
}

function IsEmail(sEmail)
{
	var str= sEmail;
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        return filter.test(str)
}

// check that entered string is number
function IsNumeric(sText){
   	var sValidChars = "0123456789";
   	var chChar;
   	for (i=0; i<sText.length;i++) 
      	{ 
      		chChar = sText.charAt(i); 
      		if (sValidChars.indexOf(chChar) == -1) {
        		return false;
 		}
      	}
   return true;
}

function ChangeBgColor(object,color)
{
	object.style.background=color
}

function WinResize()
{ 			
	
	if (document.body.clientWidth < 1000 )
	{
		document.getElementById('LeftBannerId').style.display = "none"
	}
	else
	{
		document.getElementById('LeftBannerId').style.display = ""
	}
 }


var objFormToExec = null;
var sFuncToExecute = "";
var sValue = "";

function ExecuteFunction(sFancName)
{
	
	if(sFancName == "CheckLoginFields")
	{
		CheckLoginFields();
	}
	if(sFancName == "DoSubmit")
	{
		DoSubmit();
	}
	if(sFancName == "SubmitGoogle")
	{
		SubmitGoogle();
	}
	if(sFancName == "PollSubmit")
	{
		PollSubmit(sValue);
	}
	if(sFancName == "CheckQSearchForm")
	{
		CheckQSearchForm();
	}
	if(sFancName == "SubmitStudySearch")
	{
		SubmitStudySearch();
	}
	if(sFancName == "Calc")
	{
		Calc();
	}
	if(sFancName == "SubmitPedia")
	{
		//SubmitPedia();
	}
	if(sFancName == "CheckSearchFields")
	{
		CheckSearchFields();
	}
	if(sFancName == "CheckFields")
	{
		CheckFields();
	}
	if(sFancName == "SignUp")
	{
		SignUp();
	}
	if(sFancName == "SubmitNextStep")
	{
		SubmitNextStep();
	}
	if(sFancName == "SubmitPart2")
	{
		SubmitPart2();
	}
	if(sFancName == "Match")
	{
		Match();
	}
	if(sFancName == "CalculateNum")
	{
		CalculateNum();
	}
}


function ExecuteSubmit()
{
	if (objFormToExec != null)
	{
		objFormToExec.submit();
	}
}


function SetSubmitData(sFormName, sFuncToExec)
{
	objFormToExec = document.getElementsByName(sFormName).item(0)
	sFuncToExecute  = sFuncToExec;
}

function SetFuncToExec(sFuncToExec)
{
	sFuncToExecute  = sFuncToExec;
}

function SetFuncAndValueToExec(sFuncToExec, sVal)
{
	sFuncToExecute  = sFuncToExec;
	sValue  = sVal;
}

document.onkeydown = CheckCode;

function CheckCode(e) {
	var whichCode = window.event.keyCode;
	if ( whichCode == "13" ) {
		if(sFuncToExecute!="")
		{
			ExecuteFunction(sFuncToExecute);
		}
		
	}
}


function OpenBus()
{
	window.open("/ibus.asp",'','scrollbars=no toolbar=no width=460 height=170');
}

