// scripts.js
// Common JavaScript functions for RedSheriff website.

// doLogin: Login to either Measurement or Ratings reporting engines:
//	    used only in index.htm & login_error.htm
function doLogin() 
{
    if (document.login_form.service.value  == "measurement")  
    {
		document.login_form.username.value = document.login_form.user.value;	
    		document.login_form.password.value = document.login_form.pword.value;
    		document.login_form.login.value    = 1;
   		document.login_form.action 	   = "https://measurement.redsheriff.com/cgi-bin/reports.pl";
		document.login_form.submit(this);
    }

    if ( document.login_form.service.value == "media") 
    {		
            document.login_form.action = "";
	    var user = escape(document.login_form.user.value);
	    var password = escape(document.login_form.pword.value);
	    var popwidth = screen.availWidth - 10;
	    var popheight = screen.availHeight;
	    var popenv = "toolbar=no,fullscreen=no, resizable=yes, left=0, top=0, width=" + popwidth + ",height=" + popheight;
	    var launchurl = 'http://' + user.replace('@', '%40') + ':' + password + '@secure2.traffion.com';
            window.open(launchurl, "", popenv);
	event.returnValue = false;
	return false;
    }
    			
    if ( document.login_form.service.value == "ratings") 
    {
	document.login_form.USERNAME.value = document.login_form.user.value;
        document.login_form.PASSWORD.value = document.login_form.pword.value;
        document.login_form.action         = "http://ratings.redsheriff.com/cgi/Login-wrLogin_process";
	document.login_form.submit(this);
    }

    if ( document.login_form.service.value == "mi" ) {
                document.login_form.username.value = document.login_form.user.value;   
                document.login_form.password.value = document.login_form.pword.value;  
                document.login_form.login.value    = 1;
                document.login_form.action         = "https://measurement.redsheriff.com/mi/cgi-bin/reports.pl";
                document.login_form.submit(this);
    }
    
    if ( document.login_form.service.value == "nz-total" ) {
                document.login_form.username.value = document.login_form.user.value;   
                document.login_form.password.value = document.login_form.pword.value;  
                document.login_form.login.value    = 1;
                document.login_form.domain.value    = "nz-total";
                document.login_form.action         = "https://measurement.redsheriff.com/mi/cgi-bin/reports.pl";
                document.login_form.submit(this);
    }
    
    if ( document.login_form.service.value == "au" ) {
                document.login_form.username.value = document.login_form.user.value;   
                document.login_form.password.value = document.login_form.pword.value;  
                document.login_form.login.value    = 1;
                document.login_form.domain.value    = "au";
                document.login_form.action         = "https://measurement.redsheriff.com/mi/cgi-bin/reports.pl";
                document.login_form.submit(this);
    }





    if ( document.login_form.service.value == "survey") 
    {		
            var project = document.login_form.user.value
            var password = document.login_form.pword.value
            window.location = "http://redeffect.redsheriff.com/webtab/webtab.asp?p=" + project + "&tlv=y&ds=2&pwd=" + password
    }

}

// unsetCountry: Reset Country selection box
function unsetCountry()
{
	document.linklist.country.selectedIndex = 0;
}

// gotoLink: Country select from index page
function gotoLink()
{
	loc = document.linklist.country.options[document.linklist.country.selectedIndex].value;

	if (loc != '')
	{
		top.location.href = loc;
	}

	else
	{
		return false;
	}
}

// doSignup: Signup for RedMeasure newsletter
function doSignup() 
{
        document.email_form.submit(this);
}
