window.onload = function()
{
	po(7); 
	showbox(1);
	OnLoad();
}	
var flg;
//google.load("search", "1");
//google.setOnLoadCallback(OnLoad);
var searchControl;
var mysearchForm;

function OnLoad() {
  searchControl = new google.search.SearchControl();
  var options = new GsearcherOptions();
  options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
  var siteSearch = new GwebSearch();
  siteSearch.setUserDefinedLabel("ShahroodUT.ac.ir");
  siteSearch.setSiteRestriction("ShahroodUT.ac.ir");
  searchControl.addSearcher(siteSearch,options);
  searchControl.addSearcher(new GwebSearch());
  searchControl.addSearcher(new GnewsSearch());
  searchControl.addSearcher(new GbookSearch());
  searchControl.setResultSetSize(GSearch.LARGE_RESULTSET); 

  var drawOptions = new GdrawOptions();
  drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
  //drawOptions.setSearchFormRoot(document.getElementById("searchForm"));
  
  
  mysearchForm = new GSearchForm(false, document.getElementById("searchForm"));
  mysearchForm.setOnSubmitCallback(null, OnSearchStarting); 
  drawOptions.setInput(mysearchForm);
     
  searchControl.draw(document.getElementById("searchresults"),drawOptions);
}


function OnSearchStarting(mysearchForm)
{
    searchControl.execute(mysearchForm.input.value);
    document.getElementById('btn9').style.display='block';
    po(9);
    return false;
}        

function po(n)
{
    flg = n;
    clearTimeout;
    setTimeout("tempfunc("+n+")",300);
}    
function tempfunc(n)
{
    if (flg==0 || flg!=n) return;
    temp="btn"+ n;
    document.getElementById(temp).style.background="url(images/button.png) no-repeat right";
    document.getElementById(temp).style.fontWeight="bold";
    if (n != 8)
    	document.getElementById(temp).style.color="#366C90";
    var object=document.getElementById('div'+n);
    /*object.style.opacity = 0;
    object.style.MozOpacity = 0;
    object.style.KhtmlOpacity = 0;
    object.style.filter="alpha(opacity=0)";
    object.style.display="block";
    FadeIn('div'+n);*/
    object.style.display="block";
    for(i=1;i<=8;i++)
    {
        if (i==n) continue;
        temp="btn"+ i;
        document.getElementById(temp).style.background="";
       // document.getElementById(temp).style.fontWeight="bold";
        if (n != 8)
			document.getElementById(temp).style.color="#D9D9E7";//2000FF-Blue 64FF00-lightgreen
			document.getElementById(temp).style.background="url(images/buttond.png) no-repeat right";

        document.getElementById('div'+i).style.display='none';
    }
}
function FadeIn(item)
{
    for (i=0;i<=100;i++)
    {
        clearTimeout();
        setTimeout("ChangeOpac('"+item+"',"+i+")",i);
    }
}
function  ChangeOpac(item,opac)
{
    var obj=document.getElementById(item)
    obj.style.MozOpacity = (opac/100);
    obj.style.opacity = (opac/100);
    obj.style.KhtmlOpacity = (opac/100); 
    obj.style.filter="alpha(opacity="+opac+")";
} 
function hideResults()
{
    document.getElementById('btn6').style.display='none';
    po(7);
}
function showbox(item)
{
    for (i=1;i<=4;i++)
        if (i==item)
        {
            document.getElementById('box'+i).style.display='block';
            document.getElementById('wsl'+i).style.border='1px solid #A2AAAD';
            document.getElementById('wsl'+i).style.borderBottom='';
            document.getElementById('wsl'+i).style.fontWeight='bold';
            document.getElementById('wsl'+i).style.backgroundColor='#EBF8FE';            
        }
        else
        {
            document.getElementById('box'+i).style.display='none';
            document.getElementById('wsl'+i).style.border='1px solid #EFFBFF';
            document.getElementById('wsl'+i).style.borderBottom='';
            document.getElementById('wsl'+i).style.fontWeight='';
            document.getElementById('wsl'+i).style.backgroundColor='';
        }
}
function doLogin()
{
    if (document.getElementById('uname').value=="")
    {
        cheshmak=true;
        mhmdam('uname',0);
        return false;
    }
        if (document.getElementById('upass').value=="")
    {
        cheshmak=true;
        mhmdam('upass',0); 
        return false;
    }
    document.getElementById('loginform').submit();
}
function mhmdam(objname,flg)
{
    obj=document.getElementById(objname);
    if (flg==0)
        obj.style.backgroundColor="#fff";
    else
        obj.style.backgroundColor="#fff0f7";    
    flg=!flg;
    if (cheshmak) 
        setTimeout("mhmdam('"+objname+"',"+flg+")",500);
    else
        obj.style.backgroundColor="#fff";    
}
function clearpass1(opt)
{
	mus = document.getElementById('musername').value;
    //if (mus.indexOf('@') == -1)
    //    mus += "@shahroodut.ac.ir";
        //alert(mus); 
    document.getElementById('normal_username2').value = mus;
    document.getElementById('normal_password2').value = document.getElementById('mpassword').value;
    
    if (opt == 1)
    {
        document.getElementById('normal_username2').name = "username";
        document.getElementById('normal_password2').name = "passwort";
        document.getElementById('formmail').action = "http://www.shahroodut.ac.ir:81/mailuser/login/index.php";
    }
    else
    {
        document.getElementById('normal_username2').name = "f_email";
        document.getElementById('normal_password2').name = "f_pass";
        document.getElementById('formmail').action = "http://www.shahroodut.ac.ir:81/webmail/msglist.php";
    }
    document.getElementById('formmail').submit();
	document.getElementById('musername').value='';
	document.getElementById('mpassword').value='';
	return false;
}
function clearpass2()
{
	document.getElementById('normal_username').value=document.getElementById('normal_username1').value;
	document.getElementById('normal_password').value=document.getElementById('normal_password1').value;
	document.getElementById('forminternet').submit();
	document.getElementById('normal_password1').value='';
	document.getElementById('normal_username1').value='';
	return false;
}
