/*
 *   js/jquery_custom.js - 24/02/2009 - 2.00pm MYT - 1.0
 *
 *   Stronium E-Learning System (SELS)
 *   http://www.stronium.com/
 *
 *   Copyright (c) 2009 Stronium Sdn Bhd
 *
 *   Description: JQuery common functions
 *   Author: Sabrina (sabrina@stronium.com)
 *
 *   Changelog:
 *      0.1 (24/02/2009):
 *              - Development
 *              - Done by Sabrina
 *
 */

$(document).ready( function() {

// checkbox and radio button
//        $("input[type='radio'],input[type='checkbox']").custCheckBox();
        $("input[type='checkbox']").custCheckBox();

/// table sorting and pagination
	$("#tablesort")
        	.tablesorter({widthFixed: true, widgets: ['zebra']})
                .tablesorterPager({container: $("#pager")});

	$('.textfield').Autoexpand(400);

/* textarea resizer plugin usage */
	$('textarea.resizable:not(.processed)').TextAreaResizer();
	$('iframe.resizable:not(.processed)').TextAreaResizer();
});


// masked input
jQuery(function($){
   $("#int").mask("9");
   $("#float").mask("99.99");
   $("#date").mask("99/99/9999");
   $("#phone").mask("(999) 999-9999");
   $("#tin").mask("99-9999999");
   $("#ssn").mask("999-99-9999");
});

// AJAX for combobox
function getXMLHTTP() { //fuction to return the xml http object

	var xmlhttp = false;	
	try {
		xmlhttp=new XMLHttpRequest();
	} catch(e) {		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e1) {
				xmlhttp=false;
			}
		}
	}
		 	
	return xmlhttp;
}
	
function getsublevel(levelid) {		
	
	var strURL="getvalues.php?criteria=level&id="+levelid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsublevel').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsublevelbysubject(subjectid) {		
	
	var strURL="getvalues.php?criteria=sublevelbysubject&id="+subjectid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsublevel').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsubject(levelid) {		// added by siva
	var strURL="getvalues.php?criteria=subject&id="+levelid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsubject').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsubjecttopic1(subjectid, levelid, questiontypegroupid) {		// added by siva
	var strURL="getvalues.php?criteria=subjecttopic1&id="+subjectid+"&levelid="+levelid+"&qtgid="+questiontypegroupid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsubjecttopic1').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsubjecttopic2(subjectid, levelid, questiontypegroupid) {		// added by siva
	var strURL="getvalues.php?criteria=subjecttopic2&id="+subjectid+"&levelid="+levelid+"&qtgid="+questiontypegroupid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsubjecttopic2').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsubjecttopic3(subjectid, levelid, questiontypegroupid) {		// added by siva
	var strURL="getvalues.php?criteria=subjecttopic3&id="+subjectid+"&levelid="+levelid+"&qtgid="+questiontypegroupid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsubjecttopic3').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function getsubjecttopic4(subjectid, levelid, questiontypegroupid) {		// added by siva
	var strURL="getvalues.php?criteria=subjecttopic4&id="+subjectid+"&levelid="+levelid+"&qtgid="+questiontypegroupid;
	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divsubjecttopic4').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}


function getschooldistrictbystate(stateid,levelid) {		
	var strURL="getvalues.php?criteria=schooldistrict&id="+stateid+"&levelid="+levelid;

	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divschooldistrict').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}


function getschool(districtid,levelid) {		
	var strURL="getvalues.php?criteria=school&id="+districtid+"&levelid="+levelid;

	var req = getXMLHTTP();
		
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('divschool').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}


