/****
Author: Jerome Mouneyrac
Bug Reference: http://tracker.moodle.org/browse/MDL-14439
IE and Opera fire the onchange when ever you move into a dropdwown list with the keyboard.
These functions fix this problem.
****/

/*
global variables

Note:
if I didn't use global variables, we would need to pass them as parameter:  
=> in initSelect(): 
   I would write "theSelect.onchange = selectChanged(...);"
   This code causes a javascript error on IE. (not firefox)
so I had to write theSelect.onchange = selectChanged; It's why I use global variables .
Because I use global variables, I didn't put this code in javascript-static.js.
This file is loaded in javascript.php.
*/ 
var select_formid;
var select_targetwindow;

//we redefine all user actions on the dropdown list
//onfocus, onchange, onkeydown, and onclick
//this function written by niranjan for the registration page to validate when the miscellaneous is selected the dapartment filed must be written othere wise no need of the department filed
// and when the othere is selected in the job/role title filed then that perticulat job title must(mandotary) be written in the next field

var temp ="block";
function showme(cou)
{
 
  var courseshow = "courseshow" ;


     if(temp == "block")
       {
        document.getElementById("courseshow"+cou).style.display = "none";
         temp = "none";
       }
     else
               {
            document.getElementById("courseshow"+cou).style.display = "block";
                temp = "block";
               }
        
 }




function popitup(url) {
	newwindow=window.open(url,'name','height=200,width=150');
	if (window.focus) {newwindow.focus()}
	return false;
}

function custom_validation()
    {
     var org=document.getElementById('id_profile_field_dept');
     var jobrole = document.getElementById('id_profile_field_jobrole');
     var dep = document.getElementById('id_profile_field_otherdept');
     var otherjob = document.getElementById('id_profile_field_otherjobrole');
     var usstate = document.getElementById('id_profile_field_stateus');
     var country = document.getElementById('id_profile_field_count');

     
     if(org.value=="6" && dep.value=="")
     {
       alert("If  department is Others, please specify your department / organizations");
       return false;
       
     }
 if(org.value=="0")
       {
        alert("Please Login From the www.adph.org/extranet ");
     	 return false ;
       }
     if(org.value=="1")
       {
          alert("Please Login From the www.train.org");
     	 return false ;
       }

     if(jobrole.value=="44" && otherjob.value=="")
     {
      alert("If Job Role/Title is other, please specify the other job role/title");
      return false ;
     }
    if(usstate.value=="0" && country.value=="232" )
        {
         alert("Please Select the State");
     	   return false ;
       }

     
    }

function initSelect(formId,targetWindow)
{
    //initialise global variables
    select_formid=formId;
    select_targetwindow=targetWindow;

    var theSelect = document.getElementById(select_formid+"_jump");

    theSelect.changed = false;

    selectFocussed();

    theSelect.onchange = selectChanged;
    theSelect.onkeydown = selectKeyed;
    theSelect.onclick = selectClicked;
    
    return true;
}

function selectChanged(theElement)
{
    var theSelect;
    
    if (theElement && theElement.value)
    {
        theSelect = theElement;
    }
    else
    {
        theSelect = this;
    }
    
    if (!theSelect.changed)
    {
        return false;
    }

    //here is the onchange redirection
    select_targetwindow.location=document.getElementById(select_formid).jump.options[document.getElementById(select_formid).jump.selectedIndex].value;                                
    
    return true;
}

function selectClicked()
{
    this.changed = true;
}

function selectFocussed()
{
    this.initValue = this.value;
    
    return true;
}

//we keep Firefox behaviors: onchange is fired when we press "Enter", "Esc", or "Tab"" keys.
//note that is probably not working on Mac (keyCode could be different)
function selectKeyed(e)
{
    var theEvent;
    var keyCodeTab = "9";
    var keyCodeEnter = "13";
    var keyCodeEsc = "27";
    
    if (e)
    {
        theEvent = e;
    }
    else
    {
        theEvent = event;
    }

    if ((theEvent.keyCode == keyCodeEnter || theEvent.keyCode == keyCodeTab) && this.value != this.initValue)
    {
        this.changed = true;
        selectChanged(this);
    }
    else if (theEvent.keyCode == keyCodeEsc)
    {
        this.value = this.initValue;
    }
    else
    {
        this.changed = false;
    }
    
    return true;
}

function recordusers()
  {
alert("test");

window.location ="http://lms.southcentralpartnership.org/scphp/redirect.php"

}
