﻿var selectedjobid;
function createAjaxObj()
{
	var httprequest = false
	
	if (window.XMLHttpRequest)
	{ // if Mozilla, Safari etc  Non-IE browsers
		httprequest=new XMLHttpRequest()
		
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/text')
	} 
	else if (window.ActiveXObject)
	{ // if IE
		try 
		{
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httprequest
}	

function fetchCurrentOpening(type,obj,frm,jobid,path)
{   
    //emptying the ddlCurrent Opening
    //alert(jobid);
    selectedjobid = jobid;
	document.getElementById("ddlCurrentOpening").options.length=1;
	if(obj.selectedIndex>0)
	{   
		ajaxinstance = createAjaxObj();
		xmlindicator=(arguments.length>0)?1 : 0
        if(parseInt(frm)==-1)
        {
		    var parameters="for="+type+"&AreaId="+obj.value;
		}
		//ajax.aspx?for=AreaOfInterest&AreaId=3&populated=0
		else
		{
		    var parameters="for="+type+"&AreaId="+obj.value+"&populated="+frm;
		 }
		 //alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', path+"?"+parameters, true);
		ajaxinstance.send(null)
	}	
}

function alertcontents()
{
    var iloop, option1;
    var jloop;
	var id, name;
	var ary;
	var txt_arr;
	var txt_innerarr;
	iloop = 0;
	if (ajaxinstance.readyState == 4)
	{
	    var returndata;		
	    if (ajaxinstance.status==200)
		{
		    //alert("san1");
		    mstr_text = ajaxinstance.responseText	
		    //alert(mstr_text);			
		    txt_arr =  mstr_text.split(";");	//split to check the type 	
		    for(iloop= 0; iloop<txt_arr.length-1;iloop++)
		    {       
		            txt_innerarr = txt_arr[iloop].split("^");
		            var option = new Option();
		            id= txt_innerarr[0];
		            name=txt_innerarr[1];
		            option.value = id;
					option.text =  name;
		            document.getElementById("ddlCurrentOpening").options[iloop + 1] = option;
		            if (id==selectedjobid)
		            {		                
		                option.selected = true;	
		            }
		    }
            if (document.getElementById("ddlCurrentOpening").options.length==1)
            {
                document.getElementById("ddlCurrentOpening").options[0].selected = true;	
            }
		}
	}
}

function fetchAdminCurrentOpening(type,obj,path)
{   
    //emptying the ddlCurrent Opening
    //alert(jobid);
    //alert(obj.value);
	document.getElementById("ddlCurrentOpening").options.length=1;
	if(obj.selectedIndex>0)
	{   
		ajaxinstance = createAjaxObj();
		xmlindicator=(arguments.length>0)?1 : 0        
	    var parameters="for="+type+"&AreaId="+obj.value;
		 //alert(parameters);
		ajaxinstance.onreadystatechange=alertadmincontents
		ajaxinstance.open('GET', path+"?"+parameters, true);
		ajaxinstance.send(null)
	}	
}

function alertadmincontents()
{
    var iloop, option1;
    var jloop;
	var id, name;
	var ary;
	var txt_arr;
	var txt_innerarr;
	iloop = 0;
	if (ajaxinstance.readyState == 4)
	{
	    var returndata;		
	    if (ajaxinstance.status==200)
		{
		    //alert("san1");		    
		    mstr_text = ajaxinstance.responseText	
		    //alert(mstr_text);
		    //alert(mstr_text);			
		    txt_arr =  mstr_text.split(";");	//split to check the type 	
		    for(iloop= 0; iloop<txt_arr.length-1;iloop++)
		    {       
		            txt_innerarr = txt_arr[iloop].split("^");
		            var option = new Option();
		            id= txt_innerarr[0];
		            name=txt_innerarr[1];
		            option.value = id;
					option.text =  name;
		            document.getElementById("ddlCurrentOpening").options[iloop + 1] = option;		            
		    }
            if (document.getElementById("ddlCurrentOpening").options.length==1)
            {
                document.getElementById("ddlCurrentOpening").options[0].selected = true;	
            }
		}
	}
}


// for populating discipline 

function ddlcategory_onchange(category, stateid, cityid, path)
{ 
	var iCounter;
	var opt;	
	var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline");
	//alert(document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].value);
	for(iCounter = 0; iCounter < object1[0].length; iCounter++)
	{
		if (object1[0].options[iCounter].selected) 
		{
			object1[0].options[iCounter].selected = false;
		}
	}
	//alert(object1[0].length);
	object1[0].options.length = 0;
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].selectedIndex==0)
	{
		opt = new Option();
		opt.value = "";
		opt.text = "--Select--";
		object1[0].options[object1[0].options.length]=opt;
	}
	else
	{	 
		opt = new Option();
		opt.value = "";
		opt.text = "Loading";
		object1[0].options[object1[0].options.length]=opt;
	}
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].selectedIndex==0)
	{
	    var objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")
	    if (objectvalue[0] != null)
	    {
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
		
		objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlcourses")
		if (objectvalue[0] != null)
		{
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
		
		objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlSeries")
		if (objectvalue[0] != null)
		{
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
	}
	
	if(category != "")	
	{
	    for(iCounter = 0; iCounter < document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].length; iCounter++)
	    { 
		    if (document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].options[iCounter].value==category) 
		    {
			    document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].options[iCounter].selected = true;
			    break;
		    }
	    }	
	}
	/*if (document.getElementsByName("ctl00$cplWebBody$sct_city"))
	{
		var cityObject = document.getElementsByName("ctl00$cplWebBody$sct_city")
		for(iCounter = 0; iCounter < cityObject[0].length; iCounter++)
		{
			if (cityObject[0].options[iCounter].selected) 
			{
				cityObject[0].options[iCounter].selected = false;
			}
		}
		if (cityObject[0].length > 0)	
		{
			cityObject[0].options.length = 0;
		}	
		opt = new Option();
		opt.value = "";
		opt.text = "--Select--";
		cityObject[0].options[cityObject[0].options.length]=opt;
	}*/
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].value!="")
	{	
		ajaxinstance_state = createAjaxObj();
	    xmlindicator = (arguments.length>0)? 1 : 0;
	    ajaxinstance_state.onreadystatechange = fetchdisciplineList;		    
	    ajaxinstance_state.open('GET', path+"?for=disciplinelist&categoryid="+document.getElementsByName("ctl00$cntPhldMaster$ddlCategory")[0].value+"&stateid="+stateid+"&cityid="+cityid+"", true);
	    ajaxinstance_state.send(null)		
	    return false;
	}
	else if(category !="")
	{
	    ajaxinstance_state = createAjaxObj();
	    xmlindicator = (arguments.length>0)? 1 : 0;
	    ajaxinstance_state.onreadystatechange = fetchdisciplineList;	
	    ajaxinstance_state.open('GET',path+"?for=disciplinelist&category="+category+"&stateid="+stateid+"&cityid="+cityid+"", true);
	    ajaxinstance_state.send(null)		
	    return false;
	}	
	
}
 function fetchdisciplineList()
 { 

    var mstr_text = new String();    	
    if (ajaxinstance_state.readyState==4)
    { 	           
        var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline");              
        //if request of file completed
        mstr_text = (ajaxinstance_state.responseText);
        if(mstr_text == "")
        {		    
            object1[0].options.length = 0;            
            opt = new Option();
            opt.value = "";
            opt.text = "--Select--";
            object1[0].options[object1[0].options.length]=opt;
            return false;
        }
        var iCounter;
        var valuestring;
        var listvalues;
        var listvalues1;
        var obj;
		
        listvalues = mstr_text;	
        object1[0].options.length = 0;
        //object2[0].options.length = 0;
        opt = new Option();
        opt.value = "";
        opt.text = "--Select--";
        object1[0].options[object1[0].options.length]=opt;
		
        listvalues1 = listvalues.split('@');
       
        if(listvalues1)
        {
	        for(iCounter = 0; iCounter<listvalues1.length; iCounter++)
	        {
		        valuestring = listvalues1[iCounter].split('~');
		        opt = new Option();
		        opt.value = valuestring[0];
		        opt.text = valuestring[1];
		         object1[0].options[object1[0].options.length]=opt;	
		        if (listvalues1.length==1)
		        {
			        opt.selected = true;
			        //sct_state_onchange1(valuestring[1],0);
		        }
		        if(opt.value == valuestring[2])		        
		        {
		           opt.selected = true; 
		           //sct_state_onchange1(valuestring[2], valuestring[3]);
		        }
	        }			
        }		
    }
 }  
 
 function ddlDiscipline_onchange(path)
{	
	//return false;
	var iCounter;
	var opt;
	var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")

	for(iCounter = 0; iCounter < object1[0].length; iCounter++)
	{
		if (object1[0].options[iCounter].selected) 
		{
			object1[0].options[iCounter].selected = false;
		}
	}	
	object1[0].options.length = 0;
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline")[0].selectedIndex==0)
	{
		opt = new Option();
		opt.value = "";
		opt.text = "--Select--";
		object1[0].options[object1[0].options.length]=opt;
	}
	else
	{
		opt = new Option();
		opt.value = "";
		opt.text = "Loading";
		object1[0].options[object1[0].options.length]=opt;
	}	
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline")[0].selectedIndex==0)
	{
	    var objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlcourses")
		if (objectvalue[0] != null)
		{
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
		
		objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlSeries")
		if (objectvalue[0] != null)
		{
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
    }
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline")[0].selectedIndex!=0)
	{	
        ajaxinstance_city = createAjaxObj();
	    xmlindicator = (arguments.length>0)? 1 : 0;
	    ajaxinstance_city.onreadystatechange = fetchsubjectseries;	
	    ajaxinstance_city.open('GET', path+"?for=subjectseries&disciplineid="+document.getElementsByName("ctl00$cntPhldMaster$ddlDiscipline")[0].value+"", true);
	    ajaxinstance_city.send(null)		
	    return false;	
	  }	
}

function fetchsubjectseries()
 {    
    var mstr_text = new String();    	
    if (ajaxinstance_city.readyState==4)
    { 	           
        var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlSubject");              
        //if request of file completed
        mstr_text = (ajaxinstance_city.responseText);			
        //alert(mstr_text);
        /*if(mstr_text == "")
        {*/		    
            object1[0].options.length = 0;
            opt = new Option();
            opt.value = "";
            opt.text = "--Select--";
            object1[0].options[object1[0].options.length]=opt;
            
            object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlSeries");
            object1[0].options.length = 0;
            opt = new Option();
            opt.value = "";
            opt.text = "--Select--";
            object1[0].options[object1[0].options.length]=opt;
            
           
        //}
        var iCounter;
        var valuestring;
        var listvalues;
        var listvalues1;
        var obj;
		
        listvalues = mstr_text.split('#');			
        //object1[0].options.length = 0;
        //object2[0].options.length = 0;
        //opt = new Option();
        //opt.value = "";
        //opt.text = "--Select--";
        //object1[0].options[object1[0].options.length]=opt;
		object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlSubject");  
		if (listvalues[0])
		{
            listvalues1 = listvalues[0].split('@');
            if(listvalues1)
            {
	            for(iCounter = 0; iCounter<listvalues1.length; iCounter++)
	            {
		            valuestring = listvalues1[iCounter].split('~');
		            opt = new Option();
		            opt.value = valuestring[0];
		            opt.text = valuestring[1];
		            if (listvalues1.length==1)
		            {
			            opt.selected = true;
		            }	
		           if(opt.value == valuestring[2])		        
		            {
		               opt.selected = true;		           
		            }			
		            object1[0].options[object1[0].options.length]=opt;	
	            }			
            }
         }
        
        object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlSeries");
        
        if (listvalues[1])
        {
            listvalues1 = listvalues[1].split('@');
            if(listvalues1)
            {
	            for(iCounter = 0; iCounter<listvalues1.length; iCounter++)
	            {
		            valuestring = listvalues1[iCounter].split('~');
		            opt = new Option();
		            opt.value = valuestring[0];
		            opt.text = valuestring[1];
		            if (listvalues1.length==1)
		            {
			            opt.selected = true;
		            }	
		           if(opt.value == valuestring[2])		        
		            {
		               opt.selected = true;		           
		            }			
		            object1[0].options[object1[0].options.length]=opt;	
	            }			
            }
        }		
    }
 } 
 
 
 
 function ddlSubject_onchange(path)
{	
	//return false;
	var iCounter;
	var opt;
	var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlcourses")
    //alert(document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].value);
	/*for(iCounter = 0; iCounter < object1[0].length; iCounter++)
	{
		if (object1[0].options[iCounter].selected) 
		{
			object1[0].options[iCounter].selected = false;
		}
	}	
	object1[0].options.length = 0;
	*/
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].selectedIndex==0)
	{
		opt = new Option();
		opt.value = "";
		opt.text = "--Select--";
		object1[0].options[object1[0].options.length]=opt;
	}
	else
	{
		opt = new Option();
		opt.value = "";
		opt.text = "Loading";
		object1[0].options[object1[0].options.length]=opt;
	}	
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].selectedIndex==0)
	{
	    var objectvalue = document.getElementsByName("ctl00$cntPhldMaster$ddlcourses")
		if (objectvalue[0] != null)
		{
	        objectvalue[0].options.length = 0;
	        opt = new Option();
		    opt.value = "";
		    opt.text = "--Select--";
		    objectvalue[0].options[objectvalue[0].options.length]=opt;
		}
    }
	
	if (document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].selectedIndex!=0)
	{	
        ajaxinstance_course = createAjaxObj();
	    xmlindicator = (arguments.length>0)? 1 : 0;
	    ajaxinstance_course.onreadystatechange = fetchcources;
	    //alert("for=course&subjectid="+document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].value);
	    ajaxinstance_course.open('GET', path+"?for=course&subjectid="+document.getElementsByName("ctl00$cntPhldMaster$ddlSubject")[0].value+"", true);
	    ajaxinstance_course.send(null)		
	    return false;	
	  }	
}

function fetchcources()
 {    
    var mstr_text = new String();    	
    if (ajaxinstance_course.readyState==4)
    { 	           
        var object1 = document.getElementsByName("ctl00$cntPhldMaster$ddlcourses");              
        //if request of file completed
        mstr_text = (ajaxinstance_course.responseText);
        if(mstr_text == "")
        {		    
            object1[0].options.length = 0;            
            opt = new Option();
            opt.value = "";
            opt.text = "--Select--";
            object1[0].options[object1[0].options.length]=opt;
            return false;
        }
        var iCounter;
        var valuestring;
        var listvalues;
        var listvalues1;
        var obj;
		
        listvalues = mstr_text;	
        object1[0].options.length = 0;
        //object2[0].options.length = 0;
        opt = new Option();
        opt.value = "";
        opt.text = "--Select--";
        object1[0].options[object1[0].options.length]=opt;
		
        listvalues1 = listvalues.split('@');
       
        if(listvalues1)
        {
	        for(iCounter = 0; iCounter<listvalues1.length; iCounter++)
	        {
		        valuestring = listvalues1[iCounter].split('~');
		        opt = new Option();
		        opt.value = valuestring[0];
		        opt.text = valuestring[1];
		         object1[0].options[object1[0].options.length]=opt;	
		        if (listvalues1.length==1)
		        {
			        opt.selected = true;
			        //sct_state_onchange1(valuestring[1],0);
		        }
		        if(opt.value == valuestring[2])		        
		        {
		           opt.selected = true; 
		           //sct_state_onchange1(valuestring[2], valuestring[3]);
		        }
	        }			
        }		
    }
 } 
