﻿function imgRollover(imgObj) 
{ 
    if(imgObj.src.match("_over\.gif") != null)
    {
        var substrIndex = imgObj.src.indexOf("_over.gif");
        imgObj.src = imgObj.src.substring(0,substrIndex) + ".gif"
    }
    else
    {
        var substrIndex = imgObj.src.indexOf(".gif");
        imgObj.src = imgObj.src.substring(0,substrIndex) + "_over.gif"
    } 
}

/*Stretches the leftcolumn for better border effect*/
function stretchLeftColumn()
{

}
/*End leftcolumn stretch*/     




/*URL Get Varialbes*/
function getURLVar(urlVarName) 
{
    //divide the URL in half at the '?' 
    var urlHalves = String(document.location).split('?');
    var urlVarValue = '';
    if(urlHalves[1])
    {
        //load all the name/value pairs into an array 
        var urlVars = urlHalves[1].split('&');
        //loop over the list, and find the specified url variable 
        for(i=0; i<=(urlVars.length); i++)
        {
            if(urlVars[i])
            {
                //load the name/value pair into an array 
                var urlVarPair = urlVars[i].split('=');
                if (urlVarPair[0] && urlVarPair[0] == urlVarName) 
                {
                    //I found a variable that matches, load it's value into the return variable 
                    urlVarValue = urlVarPair[1];
                }
            }
        }
    }
    return urlVarValue;   
}
/*END URL Get Variables*/
	    
	    
/*Road Show Registration Functionality************************************************/
function FormAlreadySubmittedPageLoad()
{
    if(getURLVar('r')=='t')
    {
        document.getElementById("alertBox").className = 'alertBox';
        document.getElementById("alertBox").innerHTML = 'Lähetys OK';
        document.getElementById("alertBox").style.visibility = 'visible';
    }
    else if(getURLVar('r')=='f')
    {
        document.getElementById("alertBox").className = 'alertBox';
        document.getElementById("alertBox").innerHTML = 'Your information could not be submitted. Please try again';
        document.getElementById("alertBox").style.visibility = 'visible';
    }
}

 function SubmitForm()
        {
            
            
            resetFormErrors();
            if(validateForm())
            {
                buttonTextChange("Please Wait")
                document.getElementById("submitButton").enabled = false;
                document.ilmoform.submit();
                /*
                var dd = document.getElementById("Select1").options[document.getElementById("Select1").selectedIndex].text;
		var tx0 = document.getElementById("Text0").value
                var tx1 = document.getElementById("Text1").value;
                var tx2 = document.getElementById("Text2").value;
                var tx3 = document.getElementById("Text3").value;
                var tx4 = document.getElementById("Text4").value;
                var tx5 = document.getElementById("Text5").value;
                var tx6 = document.getElementById("Text6").value;
               
                new Ajax.Request('mail.asmx/SubmitForm',
                    {   postBody:"{dropdown:'" + dd + "', tx0:'" + tx0 + "', tx1:'" + tx1 + "', tx2:'" + tx2 + "', tx3:'" + tx3 + "', tx4:'" + tx4 + "', tx5:'" + tx5 + "', tx6:'" + tx6 + "'}",
                        method: 'post', contentType:'application/json',
                        onSuccess: completeTest,
                        onFailure: errorTest});
                 */
                return;
            }
            moreRequired();
        }
        
        //this function is called it the ajax query to the web service is successful
        function completeTest(val)
        {
            document.getElementById("alertBox").className = 'alertBox';
            document.getElementById("alertBox").innerHTML = 'Your information was successfully submitted';
            document.getElementById("alertBox").style.visibility = 'visible';  
            buttonTextChange("Your information was successfully submitted")  
        }
        
        
        //this function is called it the ajax query to the web service fails
        function errorTest(error)
        {
            document.getElementById("alertBox").className = 'alertBox';
            document.getElementById("alertBox").innerHTML = 'Your information could not be submitted. Please try again<br />' + error.responseText;
            document.getElementById("alertBox").style.visibility = 'visible';
            buttonTextChange("Your information could not be submitted. Please try again") 
        }
        
        //if not all of the require fields are filled, then this function will be called
        function moreRequired()
        {
            document.getElementById("alertBox").className = 'alertBox';
            document.getElementById("alertBox").innerHTML = 'You need to fill the required fields';
            document.getElementById("alertBox").style.visibility = 'visible'; 
            buttonTextChange("You need to fill the required fields")
        }
        
        //alert the user of a status change by changing the button's text
        function buttonTextChange(btnTxt)
        {
            document.getElementById("submitButton").innerText = btnTxt;
            //document.getElementById("submitButton").style.padding = "5px";
        }   
        
        //tests whether to see if this form is completed or not
        function validateForm()
        {
            var errorCount = 0;

            if(document.getElementById("Text6").checked==true && document.getElementById("Text4").value=='')
            {
                document.getElementById("Text4Alert").style.visibility = 'visible';
                errorCount++; 
            } 
            if(document.getElementById("Text6").checked==true && document.getElementById("Text5").value=='')
            {
                document.getElementById("Text5Alert").style.visibility = 'visible';
                errorCount++; 
            } 
                    
                
            return !(errorCount>0);
        }
        
        //when the user clicks submit, make sure all of the error messages are cleared before revalidating
        function resetFormErrors()
        {
            document.getElementById("Text1Alert").style.visibility = 'hidden';
            document.getElementById("Text2Alert").style.visibility = 'hidden';
            document.getElementById("Text3Alert").style.visibility = 'hidden';
            document.getElementById("Text4Alert").style.visibility = 'hidden';
            document.getElementById("Text5Alert").style.visibility = 'hidden';
            document.getElementById("Text6Alert").style.visibility = 'hidden';        
        }
        
        
/*END Road Show Registration Functionality************************************************/
