// JavaScript Document


//------------------------------pop-up box ----------------------------------------------------------//

/***********************************************
		* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
		* This notice must stay intact for legal use.
		* Visit http://www.dynamicdrive.com/ for full source code
		***********************************************/
		
		function getposOffset(overlay, offsettype)
		{
			var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
			var parentEl=overlay.offsetParent;
			while (parentEl!=null){
			totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
			parentEl=parentEl.offsetParent;
			}
			return totaloffset;
		}
		
		function overlay(curobj, subobjstr, opt_position){
		if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		
		//var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		//var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		
		//subobj.style.left=xpos+"px"
		//subobj.style.top=ypos+"px"
		center_box(subobj, 300, 180);
		//subobj.style.left="50%"
		//subobj.style.top="50%"
		return false
		}
		else
		return true
		}
		
		function overlayclose(subobj){
		document.getElementById(subobj).style.display="none"
		}




/* Script by: www.jtricks.com
 * Version: 20070703
 * Latest version:
 * www.jtricks.com/javascript/window/box_centered.html
 */
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement && document.documentElement.clientWidth;

// Moves the box object to be centered on current
// viewable area of the page
function center_box(box, width, height)
{
    cleft = has_inner
        ? pageXOffset + window.innerWidth
        : has_element
          ? document.documentElement.scrollLeft + 
            document.documentElement.clientWidth
          : document.body.scrollLeft + 
            document.body.clientWidth;

    cleft = (cleft - width)/2;

    ctop = has_inner
        ? pageYOffset + window.innerHeight
        : has_element
          ? document.documentElement.scrollTop + 
            document.documentElement.clientHeight
          : document.body.scrollTop + 
            document.body.clientHeight;

    ctop = (ctop - height)/2;

    box.style.left = cleft + 'px';
    box.style.top = ctop + 'px';
}

// Hides other alone popup boxes that might be displayed
function hide_other_alone(obj)
{
    if (!document.getElementsByTagName)
        return;

    var all_divs = document.body.getElementsByTagName("DIV");

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).style.position != 'absolute' ||
            all_divs.item(i) == obj ||
            !all_divs.item(i).alonePopupBox)
        {
            continue;
        }

        all_divs.item(i).style.display = 'none';
    }
    return;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_box(an, width, height, borderStyle)
{
    show_hide_centered_href(
        an.href, width, height, borderStyle);
    return false;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_href(href, width, height, borderStyle)
{
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            hide_other_alone(boxdiv);
            // Show existing box, move it
            // if document changed layout
            center_box(boxdiv, width, height);
            boxdiv.style.display='block';

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    hide_other_alone(null);

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    // Add object identification variable
    boxdiv.alonePopupBox = 1;

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { show_hide_centered_href(href, width, height, borderStyle); }
    close_href.appendChild(document.createTextNode('Close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.

    var contents = document.createElement('iframe');
    //contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    center_box(boxdiv, width, height);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return;
}



function showVideoForm(mode, file)
{
	if(mode == 0) //the box is still close
	{
		updateValue('url', 'http://');
		updateValue('url_description', '');
		openDiv('form_holder');
		emptyDiv('form_holder2');
		updateHTML('share_video_link', '<a href="#share_video" class="dark_green" onclick="showVideoForm(1,\''+ file +'\');">Close video form</a>');
		//updateHTML('share_video_link_icon', '<a href="#share_video" class="dark_green" onclick="showVideoForm(1,\''+ file +'\');"><img src="images/'+file+'" /></a>&nbsp;&nbsp;');
		document.getElementById('content_scroller_div').className = "content_box_middle_shorter";
		new Effect.Appear('share_video_form_div'); 
	}
	else//the box is open
	{
		
		updateHTML('share_video_link', '<a href="#share_video" class="dark_green" onclick="showVideoForm(0,\''+ file +'\');">Share a Video</a>');
		//updateHTML('share_video_link_icon', '<a href="#share_video" class="dark_green" onclick="showVideoForm(0,\''+ file +'\');"><img src="images/'+ file+'" /></a>&nbsp;&nbsp;');
		document.getElementById('content_scroller_div').className = "content_box_middle";
		new Effect.Fade('share_video_form_div');
	}
	
}//end of function 




//------------------------survey verification function --------------------------------------------------//


function checkSurvey()
{
	
	//question 1 required
	if(!document.getElementById("answer11").checked && !document.getElementById("answer12").checked 
	&& !document.getElementById("answer13").checked && !document.getElementById("answer14").checked 
	&& !document.getElementById("answer15").checked)
	{
		alert("Question 1 must be answered.");	
		return false;	
	}
	
	if(document.getElementById("answer15").checked)
	{
		if(document.getElementById("other").value.length < 1)
		{
			alert("If you choose other for question 1, please specify.");
			document.getElementById("other").focus();
			return false;	
		}
	}
	
	//question 2 required
	if(!document.getElementById("answer21").checked && !document.getElementById("answer22").checked )
	{
		alert("Question 2 must be answered.");	
		return false;	
	}
	
	//question 3 required
	if(!document.getElementById("answer31").checked && !document.getElementById("answer32").checked )
	{
		alert("Question 3 must be answered.");	
		return false;	
	}
	
	
	//question 4 required
	if(!document.getElementById("answer41").checked && !document.getElementById("answer42").checked 
	&& !document.getElementById("answer43").checked && !document.getElementById("answer44").checked
	&& !document.getElementById("answer45").checked)
	{
		alert("Question 4 must be answered.");	
		return false;	
	}	
	
	//question 5 required
	if(!document.getElementById("answer51").checked && !document.getElementById("answer52").checked 
	&& !document.getElementById("answer53").checked && !document.getElementById("answer54").checked
	&& !document.getElementById("answer55").checked )
	{
		alert("Question 5 must be answered.");	
		return false;	
	}	
	
	//question 6 required
	if(!document.getElementById("answer61").checked && !document.getElementById("answer62").checked 
	&& !document.getElementById("answer63").checked && !document.getElementById("answer64").checked
	&& !document.getElementById("answer65").checked )
	{
		alert("Question 6 must be answered.");	
		return false;	
	}	
	
	//question 7 required
	if(!document.getElementById("answer71").checked && !document.getElementById("answer72").checked 
	&& !document.getElementById("answer73").checked && !document.getElementById("answer74").checked
	&& !document.getElementById("answer75").checked )
	{
		alert("Question 7 must be answered.");	
		return false;	
	}	
	
	//question 8 required
	if(!document.getElementById("answer81").checked && !document.getElementById("answer82").checked 
	&& !document.getElementById("answer83").checked && !document.getElementById("answer84").checked
	&& !document.getElementById("answer85").checked )
	{
		alert("Question 8 must be answered.");	
		return false;	
	}	
	
	//question 9 required
	if(!document.getElementById("answer91").checked && !document.getElementById("answer92").checked 
	&& !document.getElementById("answer93").checked && !document.getElementById("answer94").checked
	&& !document.getElementById("answer95").checked )
	{
		alert("Question 9 must be answered.");	
		return false;	
	}	
	
	//question 10 required
	if(!document.getElementById("answer101").checked && !document.getElementById("answer102").checked 
	&& !document.getElementById("answer103").checked && !document.getElementById("answer104").checked
	&& !document.getElementById("answer105").checked )
	{
		alert("Question 10 must be answered.");	
		return false;	
	}	
	
	//question 11 required
	if(!document.getElementById("answer111").checked && !document.getElementById("answer112").checked 
	&& !document.getElementById("answer113").checked && !document.getElementById("answer114").checked
	&& !document.getElementById("answer115").checked )
	{
		alert("Question 11 must be answered.");	
		return false;	
	}	
	
	//question 12 required
	if(!document.getElementById("answer121").checked && !document.getElementById("answer122").checked 
	&& !document.getElementById("answer123").checked && !document.getElementById("answer124").checked
	&& !document.getElementById("answer125").checked )
	{
		alert("Question 12 must be answered.");	
		return false;	
	}	
	
	
	
	if(document.getElementById("answer131").value.length < 1)
	{
		alert("Question 13 must be answered.");	
		document.getElementById("answer131").focus();
		return false;	
	}	
	
	return true;
	
	
}//end of function

//--------------------------------------------------------------------------------------------------------//


//--------------------------------function for quiz operations--------------------------------------------//
function confirmQuiz()
{
	var con = confirm("Confirm you quiz submission? \nIf so, click OK and then scroll back through to check your answers.")
	if (con == true)
		return true;
	return false;
}

function confirmDeleteGroup(url)
{
	var con = confirm("Are you sure want to remove this user from your group?")
	if (con == true)
		window.location = url;
	return false;	
	
}

function confirmDeleteGroupFromUser(gid)
{
	var con = confirm("Are you sure want to remove yourself from the group?")
	if (con == true)
		postAndFetchResponse('group_authorization_CB.asp?gid=' + gid + '&approve=2','',generalHandlerWrite, 'function' + gid);
	return false;	
}


function updateChecked(id)
{
	var x = document.getElementById("check"+id).value;
	//alert("update "+ id)
	document.getElementById("check"+id).value = Number(x) + 1;
}

function check(num_of_question)
{
	
	for(i= 1; i<=num_of_question; i++)
	{
		if(document.getElementById("check"+i).value < 1)
		{	
			alert(" You must answer all the questions " );	
			return false;
		}
	}
	
}



//--------------------------------------end of quiz functions------------------------------------------------//

//This function validates the login form
function validate_login()
{
	
	email = document.getElementById("email");
	password = document.getElementById("Password");
	
	if(email.value.length < 1)
	{
		alert("Email required");	
		email.focus();
		return false;	
	}
	
	if(password.value.length < 1)
	{
		alert("Password required");	
		password.focus();
		return false;	
	}
	
	return true;
	
}//end of function

//This function validates the create new group form
function validateCreatGroup()
{
	
	group_name = document.getElementById("group_name");
	description = document.getElementById("description");
	country = parseInt(document.getElementById("country").options[document.getElementById("country").selectedIndex].value)
	city = parseInt(document.getElementById("city").options[document.getElementById("city").selectedIndex].value)
	
	
	if(group_name.value.length < 1 || group_name.value =="Enter your group name")
	{
		alert("Group name required");	
		group_name.focus();
		return false;	
	}
	
	if(description.value.length < 1 || description.value == "Enter a short description of your group")
	{
		alert("Group description required");	
		description.focus();
		return false;	
	}
	
	if(country == -1)
	{
		alert("You must specify the country in which your program resides.");	
		return false;	
	}
	
	if(country != 2000) //for multilocation
	{
		if(city == -1)
		{
			alert("You must specify the city in which your program resides.");	
			return false;	
		}
	}
	return true;
	
}

function validateChangePassword()
{
	
	
	new_password1 = document.getElementById("new_password1");
	if(new_password1.value.length < 6)
	{
		alert("New Password required and must be at least 6 characters");	
		new_password1.focus();
		return false;	
	}
	
	new_password2 = document.getElementById("new_password2");
	if(new_password2.value.length < 6)
	{
		alert("Retype your new password and must be at least 6 characters");	
		new_password2.focus();
		return false;	
	}
	
	if(new_password2.value != new_password1.value)
	{
		alert("New passwords inserted are not identical. Make sure you typed them correctly.");	
		return false;
	}
	
	return true;
	
	
}



//This function validates the login form
function validate_forgot()
{
	
	email = document.getElementById("forgot_email");
	confirms = document.getElementById("confirms"); 
	
	if(email.value.length < 1)
	{
		alert("Email required");	
		email.focus();
		return false;	
	}
	
	if(confirms.value.length < 1) {
		alert("Confirmations required");
		confirms.focus();
		return false;
	}
	
	return true;
	
}

function show_forgot() {
	visibility = document.getElementById("forgot").style.visibility;
	if(visibility == "hidden") {
		document.getElementById("forgot").style.visibility = "visible";
	} else {
		document.getElementById("forgot").style.visibility = "hidden";
	}
}


//This function validates the update profile form
function validateUpdateProfile()
{
	
	firstname = document.getElementById("FirstName");
	lastname = document.getElementById("LastName");
	YearInSchoolList = document.getElementById("YearInSchoolList").options[document.getElementById("YearInSchoolList").selectedIndex].value;
	status_name = document.getElementById("status_name");
	age = document.getElementById("age").options[document.getElementById("age").selectedIndex].value;
	
	
	
	if(firstname.value.length < 1)
	{
		alert("Firstname required");	
		firstname.focus();
		return false;	
	}
	
	if(lastname.value.length < 1)
	{
		alert("Lastname required");	
		lastname.focus();
		return false;	
	}
	
	if(age == -1)
	{
		alert("Please specify your age group");	
		
		return false;	
	}
	
	if(YearInSchoolList == 10)//other selected
	{
		if(status_name.value.length < 1 || status_name.value == "Enter your status/role")
		{
			alert("If your status is other, please specify");	
			status_name.focus();
			return false;	
		}
		
		
		
	}
	
	return true;
	
}

//This function validates the registration form
function validateRegistration()
{
	
	email = document.getElementById("email");
	at=email.value.indexOf("@")
	email2 = document.getElementById("email2");
	at2=email2.value.indexOf("@")
	password1 = document.getElementById("password1");
	password2 = document.getElementById("password2");
	firstname = document.getElementById("firstname");
	lastname = document.getElementById("lastname");
	confirm_text = document.getElementById("confirm_text");
	YearInSchoolList = document.getElementById("YearInSchoolList").options[document.getElementById("YearInSchoolList").selectedIndex].value;
	status_name = document.getElementById("status_name");
	age = document.getElementById("age").options[document.getElementById("age").selectedIndex].value;
	institution = document.getElementById("institution").options[document.getElementById("institution").selectedIndex].value;
	InstitutionName = document.getElementById("InstitutionName");
	
	if(email.value.length < 1)
	{
		alert("Email required");	
		email.focus();
		return false;	
	}
	
	if (at==-1) 
	{
	 	alert("Not a valid e-mail!")
	 	document.getElementById("email").focus();
		return false;
	}
	
	if(email2.value.length < 1)
	{
		alert("Retype your email address");	
		email2.focus();
		return false;	
	}
	
	if (at2==-1) 
	{
	 	alert("Not a valid e-mail!")
	 	document.getElementById("email2").focus();
		return false;
	}
	
	if(email.value.toLowerCase() != email2.value.toLowerCase())
	{
		alert("Two email addresses you provide must be the same");
		return false;
	}
	
	if(firstname.value.length < 1 || firstname.value == "Enter your firstname")
	{
		alert("Firstname required");	
		firstname.focus();
		return false;	
	}
	
	if(lastname.value.length < 1 || lastname.value == "Enter your lastname")
	{
		alert("Lastname required");	
		lastname.focus();
		return false;	
	}
	
	if(password1.value.length < 6)
	{
		alert("Password required and must be at least 6 character long");	
		password1.focus();
		return false;	
	}
	
	if(password2.value.length < 6)
	{
		alert("Please reenter your password");	
		password2.focus();
		return false;	
	}
	
	if(age == -1)
	{
		alert("Please specify your age group");	
		
		return false;	
	}
	
	if(confirm_text.value.length < 1)
	{
		alert("Please enter confirmation characters");	
		confirm_text.focus();
		return false;	
	}
		
	if( institution == -1)//other institution selected
	{
		if(InstitutionName.value.length < 1 || InstitutionName.value == "Enter your university/institution name")
		{
			
			alert("If your institution is not on the list, please specify");	
			InstitutionName.focus();
			return false;	
		}
		
	}
	
	if(YearInSchoolList == 10)//other status selected
	{
		if(status_name.value.length < 1 || status_name.value == "Enter your status/role")
		{
			alert("If your status is other, please specify");	
			status_name.focus();
			return false;	
		}
		
	}
	
	
	return true;
	
}

//This function validates the registration form
function validateRegistration_noconfirm()
{
	
	email = document.getElementById("email");
	at=email.value.indexOf("@")
	password1 = document.getElementById("password1");
	password2 = document.getElementById("password2");
	firstname = document.getElementById("firstname");
	lastname = document.getElementById("lastname");
	YearInSchoolList = document.getElementById("YearInSchoolList").options[document.getElementById("YearInSchoolList").selectedIndex].value;
	status_name = document.getElementById("status_name");
	age = document.getElementById("age").options[document.getElementById("age").selectedIndex].value;
	institution = document.getElementById("institution").options[document.getElementById("institution").selectedIndex].value;
	InstitutionName = document.getElementById("InstitutionName");
	
	if(email.value.length < 1)
	{
		alert("Email required");	
		email.focus();
		return false;	
	}
	
	if (at==-1) 
	{
	 	alert("Not a valid e-mail!")
	 	document.getElementById("email").focus();
		return false;
	}
	
	if(firstname.value.length < 1 || firstname.value == "Enter new user's firstname")
	{
		alert("Firstname required");	
		firstname.focus();
		return false;	
	}
	
	if(lastname.value.length < 1 || lastname.value == "Enter new user's lastname")
	{
		alert("Lastname required");	
		lastname.focus();
		return false;	
	}
	
	if(password1.value.length < 6)
	{
		alert("Password required and must be at least 6 character long");	
		password1.focus();
		return false;	
	}
	
	if(password2.value.length < 6)
	{
		alert("Please reenter your password");	
		password2.focus();
		return false;	
	}
	
	if(age == -1)
	{
		alert("Please specify your age group");	
		
		return false;	
	}

	if( institution == -1)//other instituion selected
	{
		if(InstitutionName.value.length < 1 || InstitutionName.value == "Enter your university/institution name")
		{
			
			alert("If your institution is not on the list, please specify");	
			InstitutionName.focus();
			return false;	
		}
		
	}
	
	if(YearInSchoolList == 10)//other status selected
	{
		if(status_name.value.length < 1 || status_name.value == "Enter your status/role")
		{
			alert("If your status is other, please specify");	
			status_name.focus();
			return false;	
		}
		
	}
	
	
	return true;
	
}


//to check valid url format
function isURL(s){
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	
	return regexp.test(s);
}
function validateShareVideo()
{
	url = document.getElementById('url');
	url_description = document.getElementById('url_description');
	
	if(url.value.length < 7)
	{
		alert("URL address to the video is required");	
		url.focus();
		return false;	
	}
	
	if(!isURL(url.value))
	{
		alert("The URL is not valid");
		url.focus();
		return false;	
	}
	
	if(url_description.value.length < 2)
	{
		alert("Please give a short description about the video");	
		url_description.focus();
		return false;	
	}
	
	return true;
}
//end of function


//this function show status text field if a user chooses other status
function checkStatusOption(val)
{
	if(val == 10) //other
		document.getElementById("divStatusName").style.display="";
	else
	{	
		document.getElementById("divStatusName").style.display="none";
		document.getElementById("status_name").value="";
	}
}
//end of function 

//this function show status text field if a user chooses other institution 
function checkInstitutionOption(val)
{
	if(val == -1) //other
		document.getElementById("divInstitution").style.display="";
	else
	{	
		document.getElementById("divInstitution").style.display="none";
		document.getElementById("InstitutionName").value="";
	}
}
//end of function 


//This function check if user already checked all the checkboxes before click completed
function updateCheck(URL, num_of_steps)
{
	
	check=document.getElementsByName("check_completed")
	has_checked = 0
						
	if(check.length)
	{
		for (i=0;i<check.length;++ i)
		{
			//alert("here")
			if (check[i].checked)
			{
				//alert(i + " checked")
				has_checked++;
			}
		}
	}
	else
	{
		if (check.checked)
		{
			//alert("single checked")
			has_checked++;
		}
	}
						
				
						//alert(has_checked)
						
	if (has_checked == num_of_steps)
		window.location = URL
	else
	{
		var folder = document.getElementById("span_list").style;
		folder.display=""; 
		var folder = document.getElementById("instruction").style;
		folder.display="none"; 
		
	}	
}//end of ufnction


function jumpDel(URL, name, id)
{
	var name = confirm("Do you really want to delete '" + name +"' ?")
	if (name == true)
		postAndFetch(URL,'',generalHandler, id);
}//end of function


function jumpDelData()
{
	var name = confirm("Do you really want to delete all your info from our database ?")
	if (name == true)
		window.location="remove_user.asp";
}//end of function

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}//end of function

function spantitle(id)
{
				
	var folder = document.getElementById(id).style
	if (folder.display=="none")
	{	
		folder.display=""
	}
	else
	{	
		folder.display="none"
	}		
}//end of function

function openDiv(id)
{
				
	var folder = document.getElementById(id).style
		
	folder.display=""
	
	
}//end of function

function closeDiv(id)
{
				
	var folder = document.getElementById(id).style
	
	folder.display="none"
}//end of function


function emptyDiv(id)
{
	document.getElementById(id).innerHTML="&nbsp;";
		
	
}


//select an option based on the value comparison
function selectOption(select_id, value)
{
	var x = document.getElementById(select_id)
	
	for (i=0;i<x.length;i++)
    {
    	if(x.options[i].value == value)
			x.options[i].selected = true;
		else
			x.options[i].selected = false;
	}
}//end of function




function change(status, id)
{
var x=document.getElementById(id)

if(status == 0)
	x.bgColor = "white"
else
	x.bgColor = "#FFFFCC"

}

function highlight_background(id, pattern, total)
{
	for(i=1; i <= total; i++)
	{
		if(id == i)
		{	
			document.getElementById(pattern+i).style.background = "#333333";
			document.getElementById("url"+pattern + i).style.color="#FFFFFF"
		}
		else
		{
			document.getElementById(pattern+i).style.background = "";
			document.getElementById("url"+ pattern + i).style.color="#666666"
		}
	}
}//end of function 

function test_func(id, status, color)
{
	//alert(document.getElementById(id).style.backgroundColor);
	if(status == 0)
	{	
		
			document.getElementById(id).style.background="#333333"
			//alert("url" + id)
			document.getElementById("url" + id).style.color="#FFFFFF"
		
	}
	else
	{
		
			//alert("url" + id)
			document.getElementById(id).style.background=""
			document.getElementById("url" + id).style.color="#666666"
	}
}//end of function 


/* AJAX function begins  */


function createXMLHttpRequest() {
    try {return new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {}
    try {return new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
    try {return new XMLHttpRequest();} catch(e) {}
    return null;
}//end of function 

function postAndFetchXml(url, content, handler) 
{
   
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            handler(xmlhttp.responseXML);
        }
    };
	//alert(url);
	//alert(content);

    xmlhttp.open('POST', url);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 

//post of fetch for form submission
function postAndFetchForm(url, formId, handler, area_id) 
{
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var content;
	content = "";
	//grab all the element value of this document
	var x=document.getElementById(formId);
	for (var i=0;i<x.length;i++)
  	{
  		if(i == 0)
			content =  x.elements[i].name + "=" +  escape(x.elements[i].value) ;
  		else
			content += "&" + x.elements[i].name + "=" +  escape(x.elements[i].value) ;
		
  	}
	
	//alert(content);
   
   var indicator = document.getElementById(area_id);
	indicator.innerHTML="<div><img src='images/indicator.gif'></div>";
   
   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
            handler(xmlhttp.responseText, area_id);
        }
    };

    xmlhttp.open('POST', url, true);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 





function postAndFetch(url, content, handler) 
{
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

  
	   //indicator.innerHTML="<div><img src='images/indicator.gif'></div>";
   
   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
            handler(xmlhttp.responseText);
        }
    };

    xmlhttp.open('POST', url, true);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 


function postAndFetchResponse(url, content, handler, area_id) 
{
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

  
	   //indicator.innerHTML="<div><img src='images/indicator.gif'></div>";
   
   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
            handler(xmlhttp.responseText, area_id);
        }
    };

    xmlhttp.open('POST', url, true);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 

//The call back from AJAX response 
function generalHandlerShareVideo(Text, area_id)
{
	
	//alert(Text);
	var str= Text;
	
	var content = Text
	//alert(holder);
	
	if(area_id != "")
	{
		var updateform = document.getElementById(area_id);
		   updateform.innerHTML=content;
	}
	
	setTimeout('showVideoForm(1)',1500);
	
	
}//end of function

function generalHandlerWrite(Text, area_id)
{
	
	//alert(Text);
	var str= Text;
	
	var content = Text
	//alert(holder);
	
	var updateform = document.getElementById(area_id);
	   updateform.innerHTML=content;
}

function generalHandler(Text)
{
	
	//alert(Text);
	var str= Text;
	
	var content = Text
	//alert(holder);
	
	var updateform = document.getElementById(area_id);
	   updateform.innerHTML=content;
}

function generalHandler_reorder(Text, area_id)
{
	
	//alert(Text);
	
	var content = Text
	//alert(holder);
	
	var updateform = document.getElementById(area_id);
	   updateform.innerHTML=content;
	make_list('module_list');
}

function validateSearch()
{
	search_query = document.getElementById("search_query");
	
	if(search_query.value.length < 1 || search_query.value == "Search Course by Keyword")
	{
		alert("Search keyword is required");	
		search_query.focus();
		return false;	
	}
	
	return true;
}


function updateHTML(id, content)
{
	var updateform = document.getElementById(id);
	   updateform.innerHTML=content;	
}

function updateValue(id, input)
{
	var updateform = document.getElementById(id);
	   updateform.value= input;	
}//end of function 

function openSection(id)
{
	if(document.getElementById('function'+id).innerHTML == "(click to view content)")
	{
		openDiv('section'+id);
		document.getElementById('function'+id).innerHTML="(close)";
	}
	else
	{
		closeDiv('section'+id);
		document.getElementById('function'+id).innerHTML="(click to view content)";
	}
}


function MM_preloadImages() 
{ //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



