/* JavaScript Document */

var sUpload 		= false;
var sRate			= 1048576;
var secRem 			= 2;
var percentUploaded = 80;

function validation()
{
	var errMsg			=	'';
	var strPass			=	document.getElementById('password').value;
	var strFname		=	document.getElementById('fname').value;
	var strLname		=	document.getElementById('lname').value;
	var strEmail		=	document.getElementById('email').value;

	//Check user email
	if(strEmail.length == '')
		errMsg	+=	'Email is empty. \n';
	else
	{
}

	//Check Password
	if(strPass.length == '')
		errMsg	+=	'Password is empty. \n';
	else
	{
		var ans		=	checkAlnum('registration','password');
		if(!ans)
			errMsg	+=	'Password should contain only alphanumeric characters. \n';
	}

	//Check user first name	
	if(strFname.length == '')
		errMsg	+=	'First name is empty. \n';
	else
	{
		var ans		=	checkAlpha('registration','fname');
		if(!ans)
			errMsg	+=	'First name should contain only alphabetical characters. \n';
	}

	//Check user last name	
	if(strLname.length == '')
		errMsg	+=	'Last name is empty. \n';
	else
	{
		var ans		=	checkAlpha('registration','lname');
		if(!ans)
			errMsg	+=	'Last name should contain only alphabetical characters. \n';
	}

	if(errMsg != '')
	{
		alert('Error occured : \n' + errMsg);
		return false;
	}
	else
		return true;
}	

function checkEmail(email)
{
	// a very simple email validation checking. 
	// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
		return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      	var regexp_user=/^\"?[\w-_\.]*\"?$/;
      	if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      	var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      	if(splitted[2].match(regexp_domain) == null) 
      	{
	    	var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    	if(splitted[2].match(regexp_ip) == null) return false;
      	}// if
      	return true;
    }
	return false;
}

function checkAlpha(val)
{ 
	var charpos = val.search("[^A-Za-z. ]"); 
	if(val.length > 0 &&  charpos >= 0) 
	{ 
		if(!strError || strError.length ==0) 
			return false; 
	}//if 
	return true;
}//alpha 

function checkAlnum(val)
{ 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@$:,.\"'-_=[] ";
	var checkStr = val;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid)
	{
		return (false);
	}
	else
		return true;
}//alpha 

function checkEnter(e, _URL)
{
	var characterCode;
	
	if(e && e.which)
	{
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		searchResults(_URL);
		return false;
	}
	else
	{
		return true;
	}		
}

function _redirect(page)
{
	window.location.href = page;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr	=	[];
	
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null)
	{
		document.MM_sr[j++]=x;
		if(!x.oSrc)
			x.oSrc	=	x.src;
			
		x.src	=	a[i+2];
	}
}

/*---------------- AJAX function  ----------------------*/

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		 {
			 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 }
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function initRequest()
{
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		isIE = true;
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function deleteType(_URL, type, id,group_id, page_id, limit)
{
	var urlString	= _URL;
	var gid	= group_id;	

	switch(type)
	{
		case 'deck':
			var redirect = window.location.href;
			var ans = confirm("WARNING !!\n\nAre you sure, do you want to delete this DECK from the group? \nAre you sure you want to continue?");
			if(ans)
			{
				var req =	GetXmlHttpObject();			
				var url	=	_URL + "AJAX_FUNCTIONS/delete.php?type=groupDeck&deck_id="+id+"&group_id="+group_id;
				
				var ele	=	'grpdecks';
				var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
				window.top.document.getElementById(ele).innerHTML	=	waitcursor;
				req.onreadystatechange = function()
				{
					if(req.readyState==4)
					{
						incrementCount("totDecks", -1);
						getGroupTabSets(''+_URL+'', ''+group_id+'',  ''+page_id+'', 'decks', 'add');
						getGroupTabSets(''+_URL+'', ''+group_id+'', 1, 'overdeck', 'add');
					}
				}
				req.open("GET", url, true);
				req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
				req.send(null);
				return true;
			}
			else
				return false;
		break;
		
		case 'groupQuiz':
			var redirect = window.location.href;
			var ans = confirm("WARNING !!\n\nAre you sure, do you want to delete this QUIZ from the group? \nAre you sure you want to continue?");
			if(ans)
			{
				var req =	GetXmlHttpObject();			
				var url	=	_URL + "AJAX_FUNCTIONS/delete.php?type=groupQuiz&quiz_id="+id+"&group_id="+group_id;
				var ele	=	'grpquizzes';
				var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
				window.top.document.getElementById(ele).innerHTML	=	waitcursor;
	
				req.onreadystatechange = function()
				{
					if(req.readyState==4)
					{
						incrementCount("totQuizzes", -1);
						window.top.getGroupTabSets(''+_URL+'', ''+group_id+'', ''+page_id+'', 'quizzes', 'add');
						window.top.getGroupTabSets(''+_URL+'', ''+group_id+'', 1, 'overdeck', 'add');
					}
				}
				req.open("GET", url, true);
				req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
				req.send(null);
				return true;
			}
			else
				return false;
		break;
		
		case 'blog':	var ans = confirm("WARNING !!\n\nAre you sure, do you want to delete this Blog from the group? \nAre you sure you want to continue?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=groupBlog&blog_id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							var ele	=	'grpblogs';
							var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
							window.top.document.getElementById(ele).innerHTML	=	waitcursor;
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
									incrementCount("blognum", -1);
									window.top.getGroupTabSets(''+_URL+'', ''+group_id+'', ''+page_id+'', 'blogs', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
						else
							return false;
		break;
		
		case 'doc':		var ans = confirm("WARNING !!\n\nAre you sure, do you want to delete this document? \nAre you sure you want to continue?");
							
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=groupDoc&doc_id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							var ele	=	'grpdocuments';
							var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
							window.top.document.getElementById(ele).innerHTML	=	waitcursor;
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
									incrementCount("docnum", -1);
									window.top.getGroupTabSets(''+_URL+'', ''+group_id+'', ''+page_id+'', 'documents', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
						else
							return false;
		break;
	}
}

function saveAddFlashCard(_URL,id,action)
{		
		
		var fronttext = ''; 
		var backtext  = '';
		var template_fronttext 	= document.getElementById('frontTemplate').value;
		var template_backtext 	= document.getElementById('backTemplate').value;
		
		
		switch(template_fronttext)
		{
			case 'text':
					var front_txt  	= 	FCKeditorAPI.GetInstance('fronttext0');
					fronttext 	= 	front_txt.GetHTML();		
			break;
			case 'video':
					fronttext	= document.getElementById('fronttext_video').value;
			break;
			case 'audio':
					fronttext	= document.getElementById('fronttext_audio').value;
			break;
			case 'photo':
					fronttext	= document.getElementById('fronttext_photo').value;
			break;
		}
		switch(template_backtext)
		{
			case 'text':
					var back_txt  	= 	FCKeditorAPI.GetInstance('backtext0');
					backtext 	= 	back_txt.GetHTML();		
			break;
			case 'video':
					backtext	= document.getElementById('backtext_video').value;
			break;
			case 'audio':
					backtext	= document.getElementById('backtext_audio').value;
			break;
			case 'photo':
					backtext	= document.getElementById('backtext_photo').value;
			break;
		}
		
		var title			= '';//document.getElementById('fcTitle').value; temporarily commented
		var additionalTags	= document.getElementById('additionalTags').value;
		var text			= '';//document.getElementById('txt').value;  temporarily commented
		var video			= '';//document.getElementById('video').value; temporarily commented
		var image			= '';//document.getElementById('image').value; temporarily commented
		var audio			= '';//document.getElementById('audio').value; temporarily commented
		var mnemonics		= document.getElementById('mnemonics').value;
		var explanation		= document.getElementById('explanation').value;
		var reading			= document.getElementById('reading').value;
		
		// do not remove the below lines (temporarily commneted)
		/*if(title == '')
		{
			alert('Please enter flashcard title');
			document.getElementById('fcTitle').focus();
			return false;	
		}
		else 
		{*/
			if(document.getElementById('reading').value !='') // Validating the reading URLs
				var urlResult = validateURL(action);
			else
				var urlResult = 'another';
		//}
		if(urlResult == 'another')
		{
			var req	=	GetXmlHttpObject();
			var url	=	_URL + "AJAX_FUNCTIONS/addAdditionalFlashCard.php?action="+action+"&deck_id="+id+"&fcTitle="+title+"&additionalTags="+additionalTags+"&text="+text+"&video="+video+"&image="+image+"&audio="+audio+"&fronttext0="+fronttext+"&backtext0="+backtext+"&mnemonics="+mnemonics+"&explanation="+explanation+"&reading="+reading+"&frontTemplate="+template_fronttext+"&backTemplate="+template_backtext+"&page_action=";
			
			req.onreadystatechange = function()
			{
				if(req.readyState==4)
				{
					document.getElementById('fronttext0').value ='';
					document.getElementById('backtext0').value ='';
					document.getElementById('mnemonics').value ='';
					document.getElementById('explanation').value ='';
					document.getElementById('reading').value = '';
					window.location.href = _URL + 'createFlashCards.php?deck_id='+id+'&action=addCard&listFC=Y';
					document.getElementById('fronttext0').focus();
				}
			}
			
			req.open("GET", url, true);
			req.send(null);
			return true;
		}
}

function updateFlashCard(_URL,flashcard_id,deck_id,action)
{		
				
		var front_txt  	= 	FCKeditorAPI.GetInstance('fronttext0');
		var fronttext 	= 	front_txt.GetHTML();
		var back_txt  	= 	FCKeditorAPI.GetInstance('backtext0');
		var backtext 	= 	back_txt.GetHTML();
		
		
		var title			= document.getElementById('fcTitle').value;
		var additionalTags	= document.getElementById('additionalTags').value;
		var text			= document.getElementById('txt').value;
		var video			= document.getElementById('video').value;
		var image			= document.getElementById('image').value;
		var audio			= document.getElementById('audio').value;
		var mnemonics		= document.getElementById('mnemonics').value;
		var explanation		= document.getElementById('explanation').value;
		var reading			= document.getElementById('reading').value;
		
		
		var req	=	GetXmlHttpObject();
		var url	=	_URL + "AJAX_FUNCTIONS/addAdditionalFlashCard.php?action="+action+"&fc_id="+flashcard_id+"&deck_id="+deck_id+"&fcTitle="+title+"&additionalTags="+additionalTags+"&text="+text+"&video="+video+"&image="+image+"&audio="+audio+"&fronttext0="+fronttext+"&backtext0="+backtext+"&mnemonics="+mnemonics+"&explanation="+explanation+"&reading="+reading;
		
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				if(req.responseText == 'updated')
				{
						window.location.href = _URL + 'deckConfirmation.php?deck_id=' + deck_id;				
				}
			}
		}
		
		req.open("GET", url, true);
		req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
		req.send(null);
		return true;
		
}

function deleteCardFromDeck(_URL, deck_id, card_id)
{
	var ans = confirm('Are you sure? Do you want to delete this card from the deck?');
	if(ans)
	{
		var req =	GetXmlHttpObject();
		var url	=	_URL + "AJAX_FUNCTIONS/delete.php?type=deckCard&card_id="+card_id+"&deck_id="+deck_id;
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				document.getElementById('flashcardDelete').style.visibility= "hidden";
				document.getElementById('flashcardDelete').style.display= "none";
				document.getElementById('flashcardDelShow').innerHTML = req.responseText;
				//loadPage(_URL + 'deckConfirmation.php?deck_id=' + deck_id);
			}
		}
		req.open("GET", url, true);
		req.send(null);
	}
}

function pageReload()
{
	window.location.href = document.location.href;
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		//Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		//Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}
/////////////////////////////////////////////////////////////////////////////////////

function showFrontText()
{
	var frontText 				= document.getElementById("frontText");
	var backText  				= document.getElementById("backText");
	var viewAns					=	document.getElementById("viewAnswer");
	viewAns.style.display		=	'block';
	frontText.style.display 	=	'block';
	backText.style.display 		=	'none';
	document.getElementById('frontTextContainer').style.visibility  = 'visible';
	document.getElementById('frontTextContainer').style.display 	= '';
	document.getElementById('backTextContainer').style.visibility   = 'hidden';
	document.getElementById('backTextContainer').style.display 	    = 'none';
}

function showBackText()
{
	var frontText				=	document.getElementById("frontText");
	var backText				=	document.getElementById("backText");
	var viewAns					=	document.getElementById("viewAnswer");
	viewAns.style.display		=	'none';
	frontText.style.display 	= 'none';
	backText.style.display  	= 'block';
	document.getElementById('frontTextContainer').style.visibility  = 'hidden';
	document.getElementById('frontTextContainer').style.display 	= 'none';
	document.getElementById('backText').style.visibility   			= 'visible';
	document.getElementById('backText').style.display 	    		= '';
	document.getElementById('backTextContainer').style.visibility   = 'visible';
	document.getElementById('backTextContainer').style.display 	    = '';
}

function showFrontText2()
{
	document.getElementById("backText").style.display 				= 'none';
	document.getElementById('frontText').style.visibility   		= 'visible';
	document.getElementById('frontText').style.display 	    		= '';	

	document.getElementById("viewQuestion").style.visibility   		= 'hidden';
	document.getElementById("viewQuestion").style.display	    	= 'none';

	document.getElementById('queTags').style.visibility				= 'visible';
	document.getElementById('queTags').style.display   				= '';	
	document.getElementById('ansTags').style.visibility				= 'hidden';
	document.getElementById('ansTags').style.display   				= 'none';
	document.getElementById('ansTools').style.visibility			= 'hidden';
	document.getElementById('ansTools').style.display   			= 'none';
	document.getElementById('queTools').style.visibility			= 'visible';
	document.getElementById('queTools').style.display   			= '';
	document.getElementById('editCardDiv').style.visibility			= 'hidden';
	document.getElementById('editCardDiv').style.display   			= 'none';
	document.getElementById('queFCK').style.visibility				= 'hidden';
	document.getElementById('queFCK').style.display   				= 'none';
	document.getElementById('ansFCK').style.visibility				= 'hidden';
	document.getElementById('ansFCK').style.display   				= 'none';
	document.getElementById('editQueCardLink').style.visibility		= 'hidden';
	document.getElementById('editQueCardLink').style.display   		= 'none';
	document.getElementById('editAnsCardLink').style.visibility		= 'hidden';
	document.getElementById('editAnsCardLink').style.display   		= 'none';

}

function showBackText2()
{
	document.getElementById("frontText").style.display 				= 'none';
	document.getElementById('backText').style.visibility   			= 'visible';
	document.getElementById('backText').style.display 	    		= '';

	document.getElementById("viewQuestion").style.visibility   		= 'visible';
	document.getElementById("viewQuestion").style.display   		= '';
	document.getElementById('queTags').style.visibility				= 'hidden';
	document.getElementById('queTags').style.display   				= 'none';	
	document.getElementById('ansTags').style.visibility				= 'visible';
	document.getElementById('ansTags').style.display   				= '';
	document.getElementById('ansTools').style.visibility			= 'visible';
	document.getElementById('ansTools').style.display   			= '';
	document.getElementById('queTools').style.visibility			= 'hidden';
	document.getElementById('queTools').style.display   			= 'none';
	document.getElementById('editCardDiv').style.visibility			= 'hidden';
	document.getElementById('editCardDiv').style.display   			= 'none';
	document.getElementById('queFCK').style.visibility				= 'hidden';
	document.getElementById('queFCK').style.display   				= 'none';
	document.getElementById('ansFCK').style.visibility				= 'hidden';
	document.getElementById('ansFCK').style.display   				= 'none';
	document.getElementById('editQueCardLink').style.visibility		= 'hidden';
	document.getElementById('editQueCardLink').style.display   		= 'none';
	document.getElementById('editAnsCardLink').style.visibility		= 'hidden';
	document.getElementById('editAnsCardLink').style.display   		= 'none';
}

function editQuesFCK()
{
	document.getElementById("frontText").style.display 				= 'none';
	document.getElementById('backText').style.visibility   			= 'hidden';
	document.getElementById('backText').style.display 	    		= 'none';
	document.getElementById("viewQuestion").style.visibility   		= 'hidden';
	document.getElementById("viewQuestion").style.display   		= 'none';
	document.getElementById('queTags').style.visibility				= 'hidden';
	document.getElementById('queTags').style.display   				= 'none';	
	document.getElementById('ansTags').style.visibility				= 'hidden';
	document.getElementById('ansTags').style.display   				= 'none';
	document.getElementById('ansTools').style.visibility			= 'hidden';
	document.getElementById('ansTools').style.display   			= 'none';
	document.getElementById('queTools').style.visibility			= 'hidden';
	document.getElementById('queTools').style.display   			= 'none';
	document.getElementById('editCardDiv').style.visibility			= 'visible';
	document.getElementById('editCardDiv').style.display   			= '';
	document.getElementById('queFCK').style.visibility				= 'visible';
	document.getElementById('queFCK').style.display   				= '';
	document.getElementById('ansFCK').style.visibility				= 'hidden';
	document.getElementById('ansFCK').style.display   				= 'none';
	document.getElementById('editQueCardLink').style.visibility		= 'visible';
	document.getElementById('editQueCardLink').style.display   		= '';
	document.getElementById('editAnsCardLink').style.visibility		= 'hidden';
	document.getElementById('editAnsCardLink').style.display   		= 'none';
}

function editAnswFCK()
{
	document.getElementById("frontText").style.display 				= 'none';
	document.getElementById('backText').style.visibility   			= 'hidden';
	document.getElementById('backText').style.display 	    		= 'none';
	document.getElementById("viewQuestion").style.visibility   		= 'hidden';
	document.getElementById("viewQuestion").style.display   		= 'none';
	document.getElementById('queTags').style.visibility				= 'hidden';
	document.getElementById('queTags').style.display   				= 'none';	
	document.getElementById('ansTags').style.visibility				= 'hidden';
	document.getElementById('ansTags').style.display   				= 'none';
	document.getElementById('ansTools').style.visibility			= 'hidden';
	document.getElementById('ansTools').style.display   			= 'none';
	document.getElementById('queTools').style.visibility			= 'hidden';
	document.getElementById('queTools').style.display   			= 'none';
	document.getElementById('editCardDiv').style.visibility			= 'visible';
	document.getElementById('editCardDiv').style.display   			= '';
	document.getElementById('queFCK').style.visibility				= 'hidden';
	document.getElementById('queFCK').style.display   				= 'none';
	document.getElementById('ansFCK').style.visibility				= 'visible';
	document.getElementById('ansFCK').style.display   				= '';
	document.getElementById('editQueCardLink').style.visibility		= 'hidden';
	document.getElementById('editQueCardLink').style.display   		= 'none';
	document.getElementById('editAnsCardLink').style.visibility		= 'visible';
	document.getElementById('editAnsCardLink').style.display   		= '';
}

function closeEditCard(type)
{
	if(type == 'que')
	{
		showFrontText2();
	}
	else if(type == 'ans')
	{
		showBackText2();
	}
}

function loadPage(params)
{
	window.parent.location.href	=	params;
}

function cookieEnable(){
	document.cookie = 'fb_tcookie= fbtc; path=/';
	var test =  get_cookie("fb_tcookie");	
	if(test != null){
		document.cookie = 'fb_tcookie= ; path=/';
		return true;
	}
	else
		return false;
}

function showOfDiv(div) 
{
	var rtnarr	=	[];
	if(!div) {	return;	}
	div = typeof div === "string" ? document.getElementById(div) : div;
	var elms = div.getElementsByTagName("*");
	var j = 0;
	for(var i = 0, maxI = elms.length; i < maxI; ++i) 
	{
		var elm = elms[i];
		switch(elm.type) 
		{
			case "text":
			case "textarea":
			case "button":
			case "reset":
			case "submit":
			case "file":
			case "hidden":
			case "password":
			case "image":
			case "radio":
			case "checkbox":
			case "select-one":
			case "select-multiple":

			if (elm.type!='undefined' && elm.type!=null)
			{
				rtnarr[j]	=	{ 'type' : elm.type, 'id': elm.id  };
				j++;
			}
		}
	}
	return rtnarr;
}

function revenueLeadSubmit(_URL, from, dgId)
{
	showLoadingImage();
	var req 		=	GetXmlHttpObject();
	var url			=	_URL + "AJAX_FUNCTIONS/submitRevenueLead.php";
	
	var	cid			=	(document.getElementById('cid')!='undefined' && document.getElementById('cid')!=null)?document.getElementById('cid').value:'';
	var gid			=	(document.getElementById('gid')!='undefined' && document.getElementById('gid')!=null)?document.getElementById('gid').value:'';
	var email		=	encodeURIComponent(document.getElementById('email').value);
	var Name		=	encodeURIComponent(document.getElementById('Name').value);
	var Address		=	encodeURIComponent(document.getElementById('Address').value);
	var Zip			=	document.getElementById('Zip').value;
	var PhoneNumber	=	(document.getElementById('PhoneNumber').value).replace(/[^0-9]+/g,'');
	var degreeId	=	(window.top.document.getElementById('degreeId')!='undefined' && window.top.document.getElementById('degreeId')!=null)?window.top.document.getElementById('degreeId').value:dgId;

	if (degreeId=='')
	{
		degreeId	=	(document.getElementById('degreeId')!='undefined' && document.getElementById('degreeId')!=null)?document.getElementById('degreeId').value:dgId;
	}
	
	var optText		=	(document.getElementById('optText')!=null && document.getElementById('optText')!='undefined')?encodeURIComponent(document.getElementById('optText').checked):'';
	var gradYear	=	window.top.document.getElementById('yearGrad').value;
	var highEdu		=	window.top.document.getElementById('highEducation').value;
	
	var params 	= 'cid='+cid+'&gid='+gid+'&email='+email+'&Name='+Name+'&Address='+Address+'&Zip='+Zip+'&PhoneNumber='+PhoneNumber+'&degreeId='+degreeId+'&gradYear='+gradYear+'&highEdu='+highEdu+'&optText='+optText+'&from='+from;

	if (from=='cQuiz' || from=='quiz')
	{
		if (document.getElementById('userScoreId')!='undefined' && document.getElementById('userScoreId')!=null)
		{	
			var userScoreId	=	window.top.document.getElementById('userScoreId').value;
			params	=	params+'&userScoreId='+userScoreId;
		}
	}

	if (window.top.document.getElementById('display_two_step_lead_form')!='undefined' && window.top.document.getElementById('display_two_step_lead_form')!=null)
	{
		var display2	=	window.top.document.getElementById('display_two_step_lead_form').value;
		if (display2=='Y')
		{
			var extraFieldNum	=	document.getElementById('extraFieldNum').value;

			var rtnarr	=	showOfDiv('eleDiv');
			for(var i = 0; i < rtnarr.length; ++i)
			{
				switch(rtnarr[i].type) 
				{
					case "text"			:	if (document.getElementById(rtnarr[i].id)!='undefined' && document.getElementById(rtnarr[i].id)!=null)
											{
												var txtval	=	document.getElementById(rtnarr[i].id).value;
												params		=	params+'&'+rtnarr[i].id+'='+txtval;
											}

					break;
					case "select-one"	:	if (document.getElementById(rtnarr[i].id)!='undefined' && document.getElementById(rtnarr[i].id)!=null)
											{
												var txtval	=	document.getElementById(rtnarr[i].id).value;
												params		=	params+'&'+rtnarr[i].id+'='+txtval;
											}
					break;
				}	
			}
			params		=	params+'&schoolIds='+window.top.document.getElementById('schdegId').value;
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				switch(req.responseText)
				{
					case 'success':		switch(from)	
										{
											case 'group': 	var dLoad	=	window.top.document.getElementById('docToLoad').value;
															window.top.closeFacebox();
															var docPg		=	window.top.document.getElementById('docPg').value;
															window.top.getGroupDocuments(_URL,gid,docPg,'documents','get');
															window.location.href	=	dLoad;
											break;
											case 'cQuiz':	window.top.document.getElementById('popUp').className	=	'delvisible';
															window.top.document.getElementById('quizResultShow').className	=	'delvisible';
															window.top.closeFacebox();
											break;
											case 'quiz' :	window.top.document.getElementById('popUp').className	=	'delvisible';
															window.top.document.getElementById('quizResultShow').className	=	'delvisible';
															window.top.closeFacebox();
											break;
											case 'flash':	window.top.document.getElementById('getFlashCards').className	=	'getCardContainer';
															window.top.closeFacebox();
											break;
										}
					break;
					default:			document.getElementById('modalerr').innerHTML	=	req.responseText;
				}
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function setDocToLoad(_URL, docLoc)
{
	window.top.document.getElementById('docToLoad').value	=	'';
	window.top.document.getElementById('docToLoad').value	=	docLoc;
	
	var gid		=	window.top.document.getElementById('gid').value;
	var url		=	_URL + 'popLeadForm.php?gid='+gid+'&from=group';
	window.top.openFaceBox(url);
}

function customFormSubmit(_URL, custom_value)
{
	showLoadingImage();
	var req 		=	GetXmlHttpObject();
	var url			=	_URL + "AJAX_FUNCTIONS/submitCustomForm.php";
	
	var contestId	=	encodeURIComponent(document.getElementById('contestId').value);
	var score		=	encodeURIComponent(document.getElementById('score').value);
	
	var params 	= 'contestId='+contestId+'&score='+score+'&custom_value='+custom_value;

	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				switch(req.responseText)
				{
					case 'error'	:	alert('Error: Invalid parameters.')
					
					break;
					case 'success'	:	window.top.document.getElementById('popUp').className	=	'delvisible';
										window.top.document.getElementById('quizResultShow').className	=	'delvisible';

										window.top.closeFacebox();
					break;
					default:			document.getElementById('modalerr').innerHTML	=	req.responseText;
				}
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function revenueLeadToggle(_URL, userAction, quizID, sqid, from)
{
	switch(userAction)
	{
		case 'open'			:	var url		=	_URL + 'popLeadConfirm.php?quizID='+quizID+'&sqid='+sqid+'&from='+from;										if (window.top.document.getElementById('schdegId')!='undefined' && window.top.document.getElementById('schdegId')!=null)
								{
									window.top.document.getElementById('schdegId').value	=	'';
								}
								window.top.openFaceBox(url);
		break;
		case 'close'		:	var cid	=	window.top.document.getElementById('cid').value;
								window.top.location.href	=	_URL+'contestInfo.php?cid='+cid;
								window.top.initFaceBox(_URL);
		break;
		case 'lead'			:	var cid		=	window.top.document.getElementById('cid').value;

								if (window.top.document.getElementById('display_two_step_lead_form').value=='Y' && window.top.document.getElementById('schdegId').value=='')
								{
									var url		=	_URL + 'popLeadSchool.php?quizID='+quizID+'&sqid='+sqid+'&cid='+cid+'&from='+from;
								}
								else {
									var schdegId	=	window.top.document.getElementById('schdegId').value;
									var url		=	_URL + 'popLeadForm.php?quizID='+quizID+'&sqid='+sqid+'&cid='+cid+'&from='+from+'&schdegId='+schdegId;
								}
								window.top.openFaceBox(url);
		break;
		case 'custom' 		: 	var cid		=	window.top.document.getElementById('cid').value;
								var url		=	_URL + 'popCustomForm.php?quizID='+quizID+'&sqid='+sqid+'&cid='+cid+'&from='+from;
								window.top.openFaceBox(url);
		break;
		case 'showResult'	:	window.top.document.getElementById('popUp').className	=	'delvisible';
								window.top.document.getElementById('quizResultShow').className	=	'delvisible';
								window.top.closeFacebox();
		break;
		case 'fClose'		:	var fcid	=	window.top.document.getElementById('leadfirst').value;
								window.top.location.href	=	_URL + 'flashcardViewer.php?fcid='+fcid;
								window.top.initFaceBox(_URL);
		break;
		case 'flash'		:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadForm.php?gid='+gid+'&from='+from;
								window.top.openFaceBox(url);
		break;
		case 'fOpen'		:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadConfirm.php?gid='+gid+'&from='+from;						
								window.top.openFaceBox(url);
		break;
		case 'gClose'		:	var gid	=	window.top.document.getElementById('gid').value;
								window.top.location.href	=	_URL + 'groupProfile.php?gid='+gid;
								window.top.initFaceBox(_URL);
		break;
		case 'group'		:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadForm.php?gid='+gid+'&from='+from;
								window.top.openFaceBox(url);
		break;
		case 'gOpen'		:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadConfirm.php?gid='+gid+'&from='+from;						
								window.top.openFaceBox(url);
		break;
		case 'qClose'		:	var quizId	=	window.top.document.getElementById('quizID').value;
								window.top.location.href	=	_URL + 'quizViewer.php?quizID='+quizId;
								window.top.initFaceBox(_URL);
		break;
		case 'quiz'			:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadForm.php?gid='+gid+'&from='+from;
								window.top.openFaceBox(url);
		break;
		case 'qOpen'		:	var gid		=	window.top.document.getElementById('gid').value;
								var url		=	_URL + 'popLeadConfirm.php?gid='+gid+'&from='+from;						
								window.top.openFaceBox(url);
		break;
	}
}

function checkAndSubmitLead(_URL, from, email, dgId)
{
	document.getElementById('modalerr').innerHTML	=	'';
	if (email) 
	{
		if (trim(document.getElementById('email').value)=='')
		{
			document.getElementById('email').focus();
			document.getElementById('modalerr').innerHTML	=	'Please fill in the required fields to continue, Email is missing.';
			return false;
		}
		else
		{
			if (!window.top.checkEmail(document.getElementById('email').value))
			{
				document.getElementById('email').focus();
				document.getElementById('modalerr').innerHTML	=	'Please enter a valid email.';
				return false;
			}
		}
	}	
	if (trim(document.getElementById('Name').value)=='')
	{
		document.getElementById('Name').focus();
		document.getElementById('modalerr').innerHTML	=	'Please fill in the required fields to continue, Name is missing.';
		return false;
	}
	else
	{
		
		var name =	trim(document.getElementById('Name').value);
		if(!checkValidName(name))
		{
			document.getElementById('Name').focus();
			document.getElementById('modalerr').innerHTML	=	'Please enter your Full Name. \'First\' or \'Last\' name is missing, or they are less than 2 characters.';
			return false;
		}
	}
	if (trim(document.getElementById('Address').value)=='')
	{
		document.getElementById('Address').focus();
		document.getElementById('modalerr').innerHTML	=	'Please fill in the required fields to continue, Address is missing.';
		return false;
	}
	else
	{
		if(trim(document.getElementById('Address').value.length)<3)
		{
			document.getElementById('Address').focus();
			document.getElementById('modalerr').innerHTML	=	'Address field should atleast 3 characters.';
			return false;
		}
	}
	if(trim(document.getElementById('Zip').value)=='')
	{
		document.getElementById('Zip').focus();
		document.getElementById('modalerr').innerHTML	=	'Please fill in the required fields to continue, Zip is missing.';
		return false;
	}
	else
	{
		var ans		=	validateZipPhone(document.getElementById('Zip').value,'zip');
		if(ans)
		{
			document.getElementById('Zip').focus();
			document.getElementById('modalerr').innerHTML	=	'Please enter a valid ZIP.';
			return false;
		}
	}

	if(trim(document.getElementById('PhoneNumber').value)=='')
	{
		document.getElementById('PhoneNumber').focus();
		document.getElementById('modalerr').innerHTML	=	'Please fill in the required fields to continue, phone number is missing.';
		return false;
	}
	else
	{
		var phone =	trim(document.getElementById('PhoneNumber').value);
		var ans		=	validatePhoneNumber(phone);
		if(!ans)
		{
			document.getElementById('PhoneNumber').focus();
			document.getElementById('modalerr').innerHTML	=	'Please enter a valid phone number.<br />E.g (308)-135-7895 or 308-135-7895 or 308135-7895 or 308.135.7895 or 308135.7895 or 3081357895';
			return false;
		}
		else
		{
			if (!validateUSPhoneAreaCode(phone))
			{
				document.getElementById('PhoneNumber').focus();
				document.getElementById('modalerr').innerHTML	=	'Please enter a valid phone number.';
				return false;
			}
		}
	}
	
	

	var dyn		=	true;
	var ffield	=	'';
	if (window.top.document.getElementById('display_two_step_lead_form')!='undefined' && window.top.document.getElementById('display_two_step_lead_form')!=null)
	{
		var display2	=	window.top.document.getElementById('display_two_step_lead_form').value;
		if (display2=='Y')
		{
			var extraFieldNum	=	document.getElementById('extraFieldNum').value;

			var rtnarr	=	showOfDiv('eleDiv');
			for(var i = 0; i < rtnarr.length; ++i)
			{
				switch(rtnarr[i].type) 
				{
					case "text"			:	if (document.getElementById(rtnarr[i].id)!='undefined' && document.getElementById(rtnarr[i].id)!=null)
											{
												if (trim(document.getElementById(rtnarr[i].id).value)=='')
												{
													if (ffield=='')
													{	ffield	=	rtnarr[i].id;	}
													dyn	=	false;
												}
												else if((document.getElementById(rtnarr[i].id).getAttribute('rel'))=='validatePhone')
												{
													 phone 		=	trim(document.getElementById(rtnarr[i].id).value);
													 ans		=	validatePhoneNumber(phone);
													if(!ans)
													{
														document.getElementById(rtnarr[i].id).focus();
														document.getElementById('modalerr').innerHTML	=	'Please enter a valid phone number.<br />E.g (308)-135-7895 or 308-135-7895 or 308135-7895 or 308.135.7895 or 308135.7895 or 3081357895';
														return false;
													}
													else
													{
														if (!validateUSPhoneAreaCode(phone))
														{
															document.getElementById(rtnarr[i].id).focus();
															document.getElementById('modalerr').innerHTML	=	'Please enter a valid phone number.';
															return false;
														}
													}
												}
											}
					break;
					case "select-one"	:	if (document.getElementById(rtnarr[i].id)!='undefined' && document.getElementById(rtnarr[i].id)!=null)
											{
												if (trim(document.getElementById(rtnarr[i].id).value)=='')
												{
													if (ffield=='')
													{	ffield	=	rtnarr[i].id;	}
													dyn	=	false;
												}
											}
					break;
				}	
			}
		}
	}
	if (!dyn)
	{
		if (document.getElementById(ffield)!='undefined' && document.getElementById(ffield)!=null)
		{	document.getElementById(ffield).focus();	}
		document.getElementById('modalerr').innerHTML	=	'All fields are mandatory. Please provide input for all.';	
		return false;
	}

	window.top.revenueLeadSubmit(_URL, from, dgId);
	return false;
}

function validateZipPhone(field,entity) 
{
   var num = field.replace(/[^\d]/g,'');
   if(entity == 'phone')
   {
	 if(num.length != 10) 
		return true;
	 else
		return false;
   }
   else if(entity == 'zip')
   {
	 if(num.length != 5) 
		return true;
	 else
		return false;
   }
}

function checkValidName(name)
{
	var subname	=	name.split(' ');
	return ((subname.length<2)?false:((subname[0].length<2 || (subname[1].length<2))?false:true));
}

//function LoadAds()

//{
//	var adtext = "<a href=\"http://www.dpbolvw.net/click-3390417-10465035\" target=\"_blank\" onmouseover=\"window.status='http://www.questia.com';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"http://www.lduhtrp.net/image-3390417-10465035\" width=\"120\" height=\"600\" alt=\"Unlimited Access 24/7\" border=\"0\"/></a>\"";
//	document.getElementById('FlashcardLeftRailAd').innerHTML	=	adtext;
	
//	var adtext_right = "<a href=\"http://www.anrdoezrs.net/click-3390417-10495146\" target=\"_blank\" onmouseover=\"window.status='http://www.tellmemorestore.com';return true;\" onmouseout=\"window.status=' ';return true;\"><span class=\"cancelButton\">TELL ME MORE Language Learning Software</span></a><img src=\"http://www.ftjcfx.com/image-3390417-10495146\" width=\"1\" height=\"1\" border=\"0\"/><br><br>";
//	adtext_right = adtext_right + "<a href=\"http://www.jdoqocy.com/click-3390417-10294937\" target=\"_top\"><span class=\"cancelButton\">Improve Your College Application Essay at EssayEdge.com!<br><br>Let Harvard-Educated editors give you an edge!</span></a><img src=\"http://www.ftjcfx.com/image-3390417-10294937\" width=\"1\" height=\"1\" border=\"0\"/>";
//	document.getElementById('SponsoredLinks').innerHTML	=	adtext_right;
//}

function viewDeck(page)
{
	var req 	=	initRequest();
	var url		=	_URL+page;
	req 		=	initRequest(url);
	
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				document.getElementById('flashCard_data').innerHTML	=	req.responseText;
			} else if (req.status == 204)
			{}
		}
	};
	req.open('POST', url, true);
	req.send(null);
	return false;
}

function viewVersion( fc_log_id, fc_id, _URL, logFlag, versionLogID )
{
	window.location.href  =	 _URL + "viewFcChangeLogs.php?action=modified&fc_log_id=" + fc_log_id + "&fc_id=" + fc_id + "&logFlag=" + logFlag + "&versionLogID=" + versionLogID;
}

function compareVersion(_URL)
{
	var j = 0;
	var fc_log_id = [];
	var fc_ver_id = [];
	var the_form  = window.document.forms[0];
	for(var i = 0; i < the_form.length; i++)
	{
		 var temp = the_form.elements[i].type;
		 if((temp == "radio") && (the_form.elements[i].checked)) 
		 { 
		 	fc_log_id[j]  =  the_form.elements[i].id;
			fc_ver_id[j]  =  document.getElementById('ver'+fc_log_id[j]).innerHTML;
			j++; 
		}
	}
	if(fc_log_id.length == 0)
	{
		alert("Please select any two versions for comparison");
	}
	else if(fc_log_id.length == 1)
	{
		alert("Please select another version for comparison");
	}
	else
	{
		var req 	=	initRequest();
		var url		=	_URL + "ajax_functions/versions.php?fc_log_id=" + fc_log_id + "&fc_ver_id=" + fc_ver_id;
		
		req 		=	initRequest(url);
		
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					var verDetails = req.responseText.split("~~");
					for(var i = 0; i < verDetails.length; i++)
					{
						document.getElementById('logHistory').style.visibility     =  'visible';
						document.getElementById('logHistory').style.display        =  '';
						document.getElementById('currentVersion').style.visibility =  'hidden';
						document.getElementById('currentVersion').style.display    =  'none';
						document.getElementById('version1FrontText').innerHTML     =  verDetails[0];
						document.getElementById('version2FrontText').innerHTML     =  verDetails[1];
						document.getElementById('version1BackText').innerHTML      =  verDetails[2];
						document.getElementById('version2BackText').innerHTML      =  verDetails[3];
						document.getElementById('verNo2').innerHTML                =  verDetails[4];
						document.getElementById('verNo1').innerHTML                =  verDetails[5];
						for(var k = 0;k < fc_log_id.length; k++)
						{
							document.getElementById(fc_log_id[k]).checked          =  false;
						}						
					}
				} else if (req.status == 204)
				{}
			}
		};
		req.open('POST', url, true);
		req.send(null);
		return false;
	}
}

function versionTwo()
{
	var j = 0;
	var fc_log_id    = [];
	var fc_log_value = [];
	var the_form     = window.document.forms[0];
	for(var i = 0; i < the_form.length; i++)
	{
		 var temp = the_form.elements[i].type;
		 if((temp == "radio") && (the_form.elements[i].checked)) 
		 { 
		 	fc_log_id[j]    = the_form.elements[i].id;
			fc_log_value[j] = the_form.elements[i].value;
			j++; 
		}
	}
	if(fc_log_id.length > 2)
	{
		alert("Please select any two versions for comparison");
		for(var k = 0;k < fc_log_id.length; k++)
		{
			document.getElementById(fc_log_id[k]).checked = false;
		}
	}
}

function toggleLoginElements(el1, el2, el3, e14)
{
	el_1 = document.getElementById(el1);
	el_2 = document.getElementById(el2);
	el_3 = document.getElementById(el3);
	el_4 = document.getElementById(e14);
	
	if(el_1.style.display == 'block')
	{
		el_1.style.display = 'none';
		el_2.style.display = 'block';
		el_3.style.display = 'block';
		el_4.style.display = 'block';
	}
	else
	{
		el_1.style.display = 'block';
		el_2.style.display = 'none';
		el_3.style.display = 'none';
		el_4.style.display = 'none';
	}
}

var ic = 7; 
var xoxo = new Array(7);
xoxo[0] = "ads/000.jpg"; 
xoxo[1] = "ads/001.jpg"; 
xoxo[2] = "ads/002.jpg"; 
xoxo[3] = "ads/003.jpg"; 
xoxo[4] = "ads/004.jpg"; 
xoxo[5] = "ads/005.jpg"; 
xoxo[6] = "ads/006.jpg"; 

function pickRandom(range) 
{ 
	if (Math.random) return Math.round(Math.random() * (range-1)); 
	else { var now = new Date(); return (now.getTime() / 1000) % range; } 
} 

// Set the length of the timer, in seconds
var secs 	=	0;
var mins	=	0;
var hr		=	0;
var timerRunning= false;

function StopTheClock()
{
	secs 	=	0;
	mins	=	0;
	hr		=	0;

	if(timerRunning)
		clearTimeout(timerID)
	var timerRunning = false
}

function StopTheClockQ()
{
	secs 	=	0;
	mins	=	0;
	hr		=	0;

	//if(timerRunning)
	clearTimeout(timerID)
	var timerRunning = false
}

function StartTheTimer()
{
	timerRunning = true
	secs = secs + 1
	if(secs == 59)
	{
		mins	+=	1;
		secs 	=	0;
	}
	if(mins	==	59)
	{
		hr	+=	1;
		mins	=	0;
	}
	
	dsecs	=	secs;
	dmins	=	mins;
	dhr		=	hr;
	
	if(secs <= 9)
		var dsecs	=	'0' + secs;
		
	if(mins < 9)
		var dmins	=	'0' + mins;

	if(hr < 9)
		var dhr		=	'0' + hr;
		
	if(hr > 0)
	{
		if(timerRunning)
		{
			if(document.getElementById('txtTime'))
				document.getElementById('txtTime').innerHTML	=	dhr + ":" + dmins + ":" + dsecs;
			if(document.getElementById('QTime'))
				document.getElementById('QTime').innerHTML	=	dhr + ":" + dmins + ":" + dsecs;
		}
	}
	else
	{
		if(timerRunning)
		{
			if(document.getElementById('txtTime'))
				document.getElementById('txtTime').innerHTML	=	dmins + ":" + dsecs;
			if(document.getElementById('QTime'))
				document.getElementById('QTime').innerHTML	=	dmins + ":" + dsecs;
		}
	}
	timerID = self.setTimeout("StartTheTimer()", 1000)
}

function showHidePopup(t,m,s,h)
{
		var ctrl	=	document.getElementById('imageUpload');
		
		if(ctrl.style.display == 'block')
		{
			ctrl.style.display = 'none';
			document.getElementById('imageChangeFlag').value = 0;
		}
		else
		{
			document.getElementById('imageChangeFlag').value = 2;
			ctrl.style.display = 'block';
		}
		
		var tag		=	t;
		var mode	= 	m;
		var	sh		= 	s;
		var	hd		= 	h;
		
		
		
		if(mode == '1')
		{
			document.getElementById(tag).style.visibility	= "visible";
			document.getElementById(tag).style.display		= "";
			//document.getElementById(sh).style.visibility	= "hidden";
			//document.getElementById(sh).style.display		= "none";
			document.getElementById(hd).style.visibility	= "visible";
			document.getElementById(hd).style.display		= "";
			return true;
		}
		else
		{
			document.getElementById(tag).style.visibility	= "hidden";
			document.getElementById(tag).style.display		= "none";
			//document.getElementById(sh).style.visibility	= "visible";
			//document.getElementById(sh).style.display		= "";
			document.getElementById(hd).style.visibility	= "hidden";
			document.getElementById(hd).style.display		= "none";
			//document.getElementById(tag).value		    = '';
			return true;
		}
}

function get_cookie(cookie_name)
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( decodeURIComponent ( results[2] ) );
  else
    return null;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name + "=; expires=" + cookie_date.toGMTString();
}

function set_cookie(cookie_name, value)
{
  	document.cookie = cookie_name + "=" + encodeURIComponent(value) + "; expires=0; path=/; domain=" + cookie_domain;
}

var hiliteClass = 'hilightedInputField';
var normalClass = 'inputField';
var hilitedElem = '';
var regExp = /TEXTAREA/;

var ns6=document.getElementById && !document.all

//Function to highlight form element
function hilite(_URL,no,mnemo)
{
	var req	=	GetXmlHttpObject();
	if(mnemo !='')
	{
		var flashcardString = mnemo;
		
		var url	=	_URL + "AJAX_FUNCTIONS/addFlashCardSession.php?flashcard_"+resp+"="+resp+"&mnemonics="+no;
			
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				//resp	= req.responseText;
				//result	= 'flashcard_no'+resp; 
				//document.getElementById("mnemonics").seAttribute('id',result));
				//document.getElementById("mnemonics").focus();
			}
		}
		
	}
	
	
	else
	{
		var url	=	_URL + "AJAX_FUNCTIONS/addFlashCardSession.php?flashcard_"+no+"="+no;
			
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				resp	= req.responseText;
				result	= 'flashcard_no'+resp; 
				//document.getElementById("mnemonics").seAttribute('id',result));
				document.getElementById("mnemonics").focus();
			}
		}
	}
		
		req.open("GET", url, true);
		req.send(null);
		return true;
    
	
	var fronttext = 'fronttext'+no;
	var backtext = 'backtext'+no;
	
	
	document.getElementById(fronttext).className = hiliteClass
	document.getElementById(backtext).className = hiliteClass
}

function removeHilite(evt)
{
    evt = evt ? evt : window.event;
    var currentElem = evt.srcElement ? evt.srcElement : evt.target || evt.currentTarget;
    if(currentElem.className && regExp.test(currentElem.tagName))
	{
        currentElem.className = normalClass;
    }
}

function charactersLeft(count,input,limit)
{
  var countEl = document.getElementById(count);
  var inputEl = document.getElementById(input);
  var inputStr = inputEl.value;
  var charsLeft = limit - inputStr.length;
  
  if(charsLeft <= 5)
  {
    countEl.style.color = "red";
  }
  else
  {
    countEl.style.color = "#b5b5b5";
  }
  
  if(charsLeft <= 0)
  {
    charsLeft = 0;
    inputEl.value = inputStr.substring(0,limit);
  }
  
  countEl.innerHTML = charsLeft;
}

function deleteProfileType(_URL, type, id, mid,from)
{
	if((type == 'funnel') || (type == 'deckMember'))
	{
		//ans = confirm("WARNING !!\n\nAre you sure, do you want to delete this DECK from your funnel? \nAre you sure you want to continue?");
		//if(ans)
		//{
			var req =	GetXmlHttpObject();
			var url	=	_URL + "AJAX_FUNCTIONS/delete.php?type="+type+"&id="+id;
			req.onreadystatechange = function()
			{
				if(req.readyState==4)
					window.location.href = _URL + "addEditProfile.php?exp="+from;
			}
			req.open("GET", url, true);
			req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
			req.send(null);
			return true;
		//}
	}
	else
	{
		ans = confirm("Are you sure? Do you want to delete this " + type + "?");
		if(ans)
		{
			var req =	GetXmlHttpObject();
			var url	=	_URL + "AJAX_FUNCTIONS/delete.php?type="+type+"&id="+id;
			req.onreadystatechange = function()
			{
				if(req.readyState==4)
					window.location.href = _URL + "memberProfile.php?mid="+mid;
			}
			req.open("GET", url, true);
			req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
			req.send(null);
			return true;
		}
	}
}

function editMemberDetails(cntDeckAdded, cntDeckCreated)
{
	document.getElementById('memEditDetails').style.visibility      = 'visible';
	document.getElementById('memEditDetails').style.display         = '';
	document.getElementById('closeProfile').style.visibility      	= 'visible';
	document.getElementById('closeProfile').style.display         	= '';
	document.getElementById('memDetails').style.visibility          = 'hidden';
	document.getElementById('memDetails').style.display             = 'none';
	document.getElementById('memberDecksEdited').style.visibility   = 'hidden';
	document.getElementById('memberDecksEdited').style.display      = 'none';
	
	if(cntDeckAdded > 0)
	{
		for(var i = 0; i < cntDeckAdded; i++)
		{
			document.getElementById('memDeckAdded'+i).style.visibility   = 'visible';
			document.getElementById('memDeckAdded'+i).style.display      = '';
		}
	}
	if(cntDeckCreated > 0)
	{
		for(var j = 0; j < cntDeckCreated; j++)
		{
			document.getElementById('memDeckCreated'+j).style.visibility = 'visible';
			document.getElementById('memDeckCreated'+j).style.display    = '';
		}
	}
}

function closeMemberDetails(cntDeckAdded, cntDeckCreated)
{
	document.getElementById('memEditDetails').style.visibility      = 'hidden';
	document.getElementById('memEditDetails').style.display         = 'none';
	document.getElementById('memDetails').style.visibility          = 'visible';
	document.getElementById('memDetails').style.display             = '';
	document.getElementById('memberDecksEdited').style.visibility   = 'visible';
	document.getElementById('memberDecksEdited').style.display      = '';
	
	if(cntDeckAdded > 0)
	{
		for(var i = 0; i < cntDeckAdded; i++)
		{
			document.getElementById('memDeckAdded'+i).style.visibility   = 'hidden';
			document.getElementById('memDeckAdded'+i).style.display      = 'none';
		}
	}
	if(cntDeckCreated > 0)
	{
		for(var j = 0; j < cntDeckCreated; j++)
		{
			document.getElementById('memDeckCreated'+j).style.visibility = 'hidden';
			document.getElementById('memDeckCreated'+j).style.display    = 'none';
		}
	}
	document.getElementById('closeProfile').style.visibility      	= 'hidden';
	document.getElementById('closeProfile').style.display         	= 'none';
}

function saveMemberDetails( _URL, mid )
{
	var req	   =	GetXmlHttpObject();
	
	var disName   	=   encodeURIComponent(window.top.document.getElementById('disName').value);
	var selfDesc  	=   encodeURIComponent(window.top.document.getElementById('selfDesc').value);
	var memSchool	=   encodeURIComponent(window.top.document.getElementById('memSchool').value);
	
	var url		=	_URL + "ajax_functions/members.php";
	
	var params	=	"disName="+disName+"&memSchool="+memSchool+"&selfDesc=" +selfDesc;
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				if(req.responseText == 'done')
				{	window.location.href = _URL + "memberProfile.php?mid="+mid+"&tabnum=9";	}
				else if(req.responseText == 'invalid')
				{	window.top.document.getElementById('memErr').innerHTML	= 'Error: Invalid parameters.'	}
				else
				{	window.top.document.getElementById('memErr').innerHTML	=	'Unable to update your profile details! Please try again. ';	}
			} else if (req.status == 204)
			{}
		}
	};
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function tagCloud(_URL)
{
	var req	   =	GetXmlHttpObject();
					
	var url	   =	_URL + "AJAX_FUNCTIONS/tagsCloud.php";
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if((req.responseText != '') && (req.responseText != 'undefined'))
			{
				document.getElementById('browsebyTags').innerHTML = req.responseText;
				document.getElementById('siTagVal').value  = '';
				newsSection(_URL);
			}
		}
	}
		
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function newsSection(_URL)
{
	var req	   =	GetXmlHttpObject();
					
	var url	   =	_URL + "AJAX_FUNCTIONS/indexNewsSection.php";
			
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if((req.responseText != '') && (req.responseText != 'undefined'))
			{
				document.getElementById('news').innerHTML = req.responseText;
				//showAddThis(_URL);
			}
		}
	}
		
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function searchResults(_URL)
{
	var searchTxt				=	document.getElementById('search').value;
	
	if(searchTxt != "Search for any Subject, Class, Teacher, Classmates or Group")
	{
		window.location.href	=	_URL + "searchResults.php?searchTxt=" + encodeURIComponent(searchTxt) + "&decks=true";
	}
	else
	{		
		window.location.href	=	_URL + "searchResults.php?searchTxt=&decks=true";
	}		
}

function searchLeftContainer(_URL, searchTxt)
{
	var req	   =	GetXmlHttpObject();
					
	var url	   =	_URL + "AJAX_FUNCTIONS/searchRightRail.php?searchTxt=" + searchTxt;
			
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if((req.responseText != '') && (req.responseText != 'undefined'))
			{
				document.getElementById('centerRightContent').innerHTML = req.responseText;
			}
		}
	}
		
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function uploadError() {
	document.getElementById('fileUplodPop').innerHTML	= 'Please try smaller size file.';
}

function uploadSuccess(fileObject, serverData, receiveResponse) {
	try {
		data = JSON.parse(serverData);
		
		if (data != null) {
			data.msg=decodeURIComponent(data.msg);
			data.error=decodeURIComponent(data.error);
		
			if(typeof(data.error) != 'undefined')
			{ 
				if(data.error != '')
				{
					alert(data.error);
				}
				else 
				{
					var _URL 		= swfu.customSettings._URL;
					var sourcePage 	= swfu.customSettings.sourcePage;
					var cardNum		= swfu.customSettings.cardNum;
					var formatType 	= swfu.customSettings.formatType;
					
					switch(sourcePage)
					{
					
						case 'quiz':
								if (formatType=='quizImage')
								{
									quizId		=	window.top.document.getElementById('quizId').value;
									openURL	=	_URL+'cropperIframe.php?qid='+quizId+'&filename='+data.msg+'&imgType=quizPhoto';
									window.top.openFaceBox(openURL);	
								}
								if (formatType==('quizQuesImage'))
								{
									var cat		= data.msg.split('~~~');
									var openURL	= _URL+'popBox.php?enc=n&height=428&width=900&url='+_URL+'popAddEditQuestion.php?'+window.top.urlToLoad;
									window.top.document.getElementById('t_Qformat').value			=	'Photo';
									window.top.document.getElementById('t_qImg').innerHTML			=	'';
									window.top.document.getElementById('t_qImg').innerHTML			=	cat[0];
									window.top.document.getElementById('t_qImgPath').value			=	cat[1];
									window.top.openFaceBox(openURL);
								}
								if (formatType==('quizAnsImage'))
								{
									var cat		= data.msg.split('~~~');
									var openURL	= _URL+'popBox.php?enc=n&height=428&width=900&url='+_URL+'popAddEditQuestion.php?'+window.top.urlToLoad;
									window.top.document.getElementById('t_aFormat_'+cardNum).value	=	'Photo';
									window.top.document.getElementById('t_aImg_'+cardNum).innerHTML	=	'';
									window.top.document.getElementById('t_aImg_'+cardNum).innerHTML	=	cat[0];
									window.top.document.getElementById('t_aImgPath_'+cardNum).value	=	cat[1];
									window.top.openFaceBox(openURL);
								}
						break;
						case 'flashcard':
								var cat	= data.msg.split("--");
								if(cat[0] == 'mnemonics')
									document.getElementById('m_medialist').innerHTML	+= cat[1];
								else
									document.getElementById('e_medialist').innerHTML	+= cat[1];
						break;
						
						case 'deck':	deck_id		=	window.top.document.getElementById('deck_id').value;
										openURL	=	_URL+'cropperIframe.php?did='+deck_id+'&filename='+data.msg+'&imgType=deckPhoto';
										window.top.openFaceBox(openURL);	
						break;
					
						case 'template':
								window.top.closeFacebox();
						break;
						case 'profilePhoto':	mid		=	window.top.document.getElementById('profileId').value;
												openURL	=	_URL+'cropperIframe.php?mid='+mid+'&filename='+data.msg+'&imgType=profilePhoto';
												window.top.openFaceBox(openURL);		
						break;
						
						case 'groups': 	gid		=	window.top.document.getElementById('gid').value;
										openURL	=	_URL+'cropperIframe.php?gid='+gid+'&filename='+data.msg+'&imgType=group';
										window.top.openFaceBox(openURL);
						break;
						
						case 'answer':
							if(formatType == 'photo')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var aText		= window.top.document.getElementById('APhotoTexTTmp').value;
								
								var content	=	"<div align=\"center\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=photo&from=answer&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">"+tags[0]+"</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"APhotoTexT\" name=\"APhotoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Answer in Text Here after Uploading Picture');\" onblur=\"writeDefaultText(this.id, 'Enter Answer in Text Here after Uploading Picture');\">"+aText+"</textarea></span></div>";
								window.top.document.getElementById('APhotoTemp').innerHTML	=	'';
								window.top.document.getElementById('APhotoTemp').innerHTML	=	content;
								window.top.document.getElementById('mbackTmp').value		=	tags[1];
								window.top.document.getElementById('AsetFmtTmp').value		=	'photo';
								window.top.openFaceBox(openURL);
							}

							if(formatType == 'video')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var aText		= window.top.document.getElementById('AVideoTexTTmp').value;
								
								var content	=	"<div class=\"nonText\">"+tags[0]+"</div><div class=\"nonText\" align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=video&from=answer&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Video</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"AVideoTexT\" name=\"AVideoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Answer in Text Here after Uploading Video');\" onblur=\"writeDefaultText(this.id, 'Enter Answer in Text Here after Uploading Video');\">"+aText+"</textarea></span></div>";
								window.top.document.getElementById('AVideoTemp').innerHTML	=	'';
								window.top.document.getElementById('AVideoTemp').innerHTML	=	content;
								window.top.document.getElementById('mbackTmp').value		=	tags[1];
								window.top.document.getElementById('AsetFmtTmp').value		=	'video';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'audio')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var aText		= window.top.document.getElementById('AAudioTexTTmp').value;
								
								var content	=	"<div align=\"center\">"+tags[0]+"</div><div align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=audio&from=answer&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Audio</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"AAudioTexT\" name=\"AAudioTexT\" onfocus=\"clearFlashText(this.id, 'Enter Answer in Text Here after Uploading Audio');\" onblur=\"writeDefaultText(this.id, 'Enter Answer in Text Here after Uploading Audio');\">"+aText+"</textarea></span></div>";
								window.top.document.getElementById('AAudioTemp').innerHTML	=	'';
								window.top.document.getElementById('AAudioTemp').innerHTML	=	content;
								window.top.document.getElementById('mbackTmp').value		=	tags[1];
								window.top.document.getElementById('AsetFmtTmp').value		=	'audio';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'PhotoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('answer_photo_'+cardNum).value;
								window.top.document.getElementById('AnswerPhoto_'+cardNum).innerHTML	= "<div align=center>"+data.msg+"<textarea name=answer_photo_"+cardNum+" id=answer_photo_"+cardNum+" class=templateTextArea style=\"height:22px;margin:2px;\" onclick=\"clearDefaultText('answer_photo_"+cardNum+"','Enter answer in text here');\" onblur=\"writeDefaultText('answer_photo_"+cardNum+"','Enter answer in text here');\"></textarea></div>";
								window.top.document.getElementById('answer_photo_'+cardNum).value		= tempText;
								window.top.document.getElementById('answer_photo_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
							if(formatType == 'VideoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('answer_video_'+cardNum).value;
								window.top.document.getElementById('AnswerVideo_'+cardNum).innerHTML	= data.msg+"<div align=center><textarea name=answer_video_"+cardNum+" id=answer_video_"+cardNum+" class=templateTextArea style=\"height:25px;\" onclick=\"clearDefaultText('answer_video_"+cardNum+"','Enter answer in text here');\" onblur=\"writeDefaultText('answer_video_"+cardNum+"','Enter answer in text here');\"></textarea></div>";
								window.top.document.getElementById('answer_video_'+cardNum).value		= tempText;
								window.top.document.getElementById('answer_video_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
						break;
						
						case 'question':
						
							if(formatType == 'photo')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var qText		= window.top.document.getElementById('QPhotoTexTTmp').value;
								
								var content	=	"<div align=\"center\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=photo&from=question&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">"+tags[0]+"</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"QPhotoTexT\" name=\"QPhotoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Question in Text Here after Uploading Picture');\" onblur=\"writeDefaultText(this.id, 'Enter Question in Text Here after Uploading Picture');\">"+qText+"</textarea></span></div>";
								window.top.document.getElementById('QPhotoTemp').innerHTML	=	'';
								window.top.document.getElementById('QPhotoTemp').innerHTML	=	content;
								window.top.document.getElementById('mfrontTmp').value		=	tags[1];
								window.top.document.getElementById('QsetFmtTmp').value		=	'photo';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'video')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var qText		= window.top.document.getElementById('QVideoTexTTmp').value;
								
								var content	=	"<div class=\"nonText\">"+tags[0]+"</div><div class=\"nonText\" align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=video&from=question&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Video</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"QVideoTexT\" name=\"QVideoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Question in Text Here after Uploading Video');\" onblur=\"writeDefaultText(this.id, 'Enter Question in Text Here after Uploading Video');\">"+qText+"</textarea></span></div>";
								window.top.document.getElementById('QVideoTemp').innerHTML	=	'';
								window.top.document.getElementById('QVideoTemp').innerHTML	=	content;
								window.top.document.getElementById('mfrontTmp').value		=	tags[1];
								window.top.document.getElementById('QsetFmtTmp').value		=	'video';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'audio')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var qText		= window.top.document.getElementById('QAudioTexTTmp').value;
								
								var content	=	"<div align=\"center\">"+tags[0]+"</div><div align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=audio&from=question&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Audio</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"QAudioTexT\" name=\"QAudioTexT\" onfocus=\"clearFlashText(this.id, 'Enter Question in Text Here after Uploading Audio');\" onblur=\"writeDefaultText(this.id, 'Enter Question in Text Here after Uploading Audio');\">"+qText+"</textarea></div>";
								window.top.document.getElementById('QAudioTemp').innerHTML	=	'';
								window.top.document.getElementById('QAudioTemp').innerHTML	=	content;
								window.top.document.getElementById('mfrontTmp').value		=	tags[1];
								window.top.document.getElementById('QsetFmtTmp').value		=	'audio';
								window.top.openFaceBox(openURL);
							}
							if(formatType == 'PhotoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('question_photo_'+cardNum).value;
								window.top.document.getElementById('QuestionPhoto_'+cardNum).innerHTML	= "<div align=center>"+data.msg+"<textarea name=question_photo_"+cardNum+" id=question_photo_"+cardNum+" class=templateTextArea style=\"height:22px;margin:2px;\" onclick=\"clearDefaultText('question_photo_"+cardNum+"','Enter question in text here');\" onblur=\"writeDefaultText('question_photo_"+cardNum+"','Enter question in text here');\"></textarea></div>";
								window.top.document.getElementById('question_photo_'+cardNum).value		= tempText;
								window.top.document.getElementById('question_photo_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
							if(formatType == 'VideoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('question_video_'+cardNum).value;
								window.top.document.getElementById('QuestionVideo_'+cardNum).innerHTML	= data.msg+"<div align=center><textarea name=question_video_"+cardNum+" id=question_video_"+cardNum+" class=templateTextArea style=\"height:25px;\" onclick=\"clearDefaultText('question_video_"+cardNum+"','Enter question in text here');\" onblur=\"writeDefaultText('question_video_"+cardNum+"','Enter question in text here');\"></textarea></div>";
								window.top.document.getElementById('question_video_'+cardNum).value		= tempText;
								window.top.document.getElementById('question_video_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
						break;
		
						case '3rdside':	
							if(formatType == 'photo')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var tText		= window.top.document.getElementById('TPhotoTexTTmp').value;
								
								var content	=	"<div align=\"center\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=photo&from=3rdside&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">"+tags[0]+"</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"TPhotoTexT\" name=\"TPhotoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Third Side in Text Here after Uploading Picture');\" onblur=\"writeDefaultText(this.id, 'Enter Third Side in Text Here after Uploading Picture');\">"+tText+"</textarea></span></div>";
								window.top.document.getElementById('TPhotoTemp').innerHTML	=	'';
								window.top.document.getElementById('TPhotoTemp').innerHTML	=	content;
								window.top.document.getElementById('m3rdsideTmp').value		=	tags[1];
								window.top.document.getElementById('TsetFmtTmp').value		=	'photo';
								window.top.openFaceBox(openURL);
							}
							if(formatType == 'video')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var TText		= window.top.document.getElementById('TVideoTexTTmp').value;
								
								var content	=	"<div align=\"center\">"+tags[0]+"</div><div align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=video&from=3rdside&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Video</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"TVideoTexT\" name=\"TVideoTexT\" onfocus=\"clearFlashText(this.id, 'Enter Third Side in Text Here after Uploading Video');\" onblur=\"writeDefaultText(this.id, 'Enter Third Side in Text Here after Uploading Video');\">"+TText+"</textarea></span><div align=\"center\">";
								window.top.document.getElementById('TVideoTemp').innerHTML	=	'';
								window.top.document.getElementById('TVideoTemp').innerHTML	=	content;
								window.top.document.getElementById('m3rdsideTmp').value		=	tags[1];
								window.top.document.getElementById('TsetFmtTmp').value		=	'video';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'audio')
							{
								var tags		= data.msg.split('~~~');
								var openURL		= _URL+'popBox.php?enc=n&height=392&width=895&url='+_URL+'popAddEditCard.php?'+window.top.urlToLoad;
								var TText		= window.top.document.getElementById('TAudioTexTTmp').value;
								
								var content	=	"<div align=\"center\">"+tags[0]+"</div><div align=\"left\"><a onclick=\"closeEditor();openFlashCardLink('"+_URL+"popBox.php?enc=n&height=125&width=320&url=popFormat.php?formatType=audio&from=3rdside&cardNum="+cardNum+"');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Audio</a></div><div align=\"center\"><span class=\"flsAddText\"><textarea class=\"flsTextBox\" cols=\"\" rows=\"\" id=\"TAudioTexT\" name=\"TAudioTexT\" onfocus=\"clearFlashText(this.id, 'Enter Third Side in Text Here after Uploading Audio');\" onblur=\"writeDefaultText(this.id, 'Enter Third Side in Text Here after Uploading Audio');\">"+TText+"</textarea></span></div>";
								window.top.document.getElementById('TAudioTemp').innerHTML	=	'';
								window.top.document.getElementById('TAudioTemp').innerHTML	=	content;
								window.top.document.getElementById('m3rdsideTmp').value		=	tags[1];
								window.top.document.getElementById('TsetFmtTmp').value		=	'audio';
								window.top.openFaceBox(openURL);
							}
	
							if(formatType == 'PhotoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('exp_photo_'+cardNum).value;
								window.top.document.getElementById('ExpPhoto_'+cardNum).innerHTML	= data.msg;
								window.top.document.getElementById('exp_photo_'+cardNum).value		= tempText;
								window.top.document.getElementById('exp_photo_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
							if(formatType == 'VideoList')
							{
								updateElementValue(cardNum);
								var tempText	= window.top.document.getElementById('exp_video_'+cardNum).value;
								window.top.document.getElementById('ExpVideo_'+cardNum).innerHTML	= data.msg;
								window.top.document.getElementById('exp_video_'+cardNum).value		= tempText;
								window.top.document.getElementById('exp_video_'+cardNum).style.textAlign	= 'center';
								window.top.closeFacebox();
							}
						break;
						
						case 'questionGF':
							if(formatType == 'photo')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'question';
								window.top.document.getElementById('format').value					=	'photo';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=question';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							if(formatType == 'audio')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'question';
								window.top.document.getElementById('format').value					=	'audio';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=question';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							if(formatType == 'video')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'question';
								window.top.document.getElementById('format').value					=	'video';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=question';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							window.top.openFaceBox(openURL);
						break;
						
						case 'answerGF':
							if(formatType == 'photo')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'answer';
								window.top.document.getElementById('format').value					=	'photo';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=answer';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							if(formatType == 'audio')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'answer';
								window.top.document.getElementById('format').value					=	'audio';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=answer';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							if(formatType == 'video')
							{
								window.top.document.getElementById('addEditFlag').value				=	1;
								window.top.document.getElementById('formattype').value				=	'answer';
								window.top.document.getElementById('format').value					=	'video';
								var deck_id	=	window.top.document.getElementById('deck_id').value;
								var openURL	=	_URL+'popBox.php?enc=n&height=360&width=416&url=popEditQuesAns.php?deck_id='+deck_id+'&fcid='+cardNum+'&editType=answer';
								window.top.document.getElementById('addEditLoadContent').innerHTML	=	data.msg;
							}
							window.top.openFaceBox(openURL);
						break;
					}
					
					pBar=document.getElementById('progressBar').style.width = "200px";
					percentLabel=document.getElementById('progressPercent').innerHTML = "100%";
					
					window.top.initFaceBox(_URL);
				}
			}
		} else {
			document.getElementById('fileUplodPop').innerHTML	= 'Please try smaller size file.';
		}
	} catch (ex) {
		document.getElementById('fileUplodPop').innerHTML	= 'Please try smaller size file.';
	}
}

function initializeSWFUpload(_URL,_JS,elemName,from,cardnum,format,buttonType) {
	
	var buttonURL = _JS + "swfupload/ButtonUploadText_61x22.png";
	
	if(buttonType == 'browse') {
		buttonURL = _JS + "swfupload/ButtonBrowseText_61x22.png";
	}
	
	var settings_object = {
			upload_url : _URL + "AJAX_FUNCTIONS/doajaxfileupload.php",
			flash_url : _JS + "swfupload/swfupload.swf",
			
			file_post_name : elemName,
			post_params : {
				"elementName" : elemName
			},
			
			assume_success_timeout: 0,
			file_size_limit : "100 MB",
			file_types : "*.*",
			file_types_description : "All Files",
			file_upload_limit : 0,
			file_queue_limit : 1,

			// Button settings
			button_image_url: buttonURL,
			button_width: "62",
			button_height: "22",
			button_placeholder_id: "uploadButtonPlaceHolder",

			file_dialog_complete_handler: function () {
				document.getElementById('progressBar').style.width = "0px";
				document.getElementById('progressPercent').innerHTML = "0%";
				sUpload = false;
				this.startUpload();
			},
			upload_start_handler : function (file) {
					this.setButtonDisabled(true);
					document.getElementById('spanFileName').innerHTML = "Filename : " + file.name;
			},
			upload_progress_handler : function (fileObject, bytesComplete, totalBytes) {
				
				if (sUpload == false) {
					document.getElementById('progressBar').style.width = fileObject.percentUploaded * 1.6 + "px";
					document.getElementById('progressPercent').innerHTML = parseInt(fileObject.percentUploaded * 0.8) + "%";
				}
				if (parseInt(fileObject.percentUploaded) >= 50) {
					document.getElementById('progressPercent').style.color = "#FFFFFF";
				}
				
				if (parseInt(fileObject.percentUploaded) == 100 && sUpload == false) {
					sUpload = true;
					secRem = Math.floor(totalBytes / sRate) + 2;
					
					sProgress();
				}
			},
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			
			// SWFObject settings
			minimum_flash_version : "9.0.28",
			swfupload_pre_load_handler : null,
			swfupload_load_failed_handler : function(){
				document.getElementById('fileUplodPop').innerHTML	= 'This feature needs flash plugin. Please install flash plugin to upload files.';				
			},
			
			custom_settings : {
				_URL		: _URL,
				sourcePage 	: from,
				cardNum 	: cardnum,
				formatType 	: format
			}
	};
		
	swfu = new SWFUpload(settings_object);
}

function sProgress() {
	 
	percentUploaded += (100 - percentUploaded) / secRem;
	if (percentUploaded >= 100) {
		percentUploaded = 99;
	}
	
	document.getElementById('progressBar').style.width = percentUploaded * 2 + "px";
	document.getElementById('progressPercent').innerHTML = parseInt(percentUploaded) + "%";
	
	secRem--;
	if (secRem > 0 || percentUploaded < 99) {
		setTimeout(sProgress, 1000);
	}
}

function saveEditCard(_URL, type, formatType, fcid, mid)
{
	closeEditor();
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/updateFlashcard.php";
	var deck_id	=	window.top.document.getElementById('deck_id').value;
	var text	=	'';
	var path	=	'';
	switch(type)
	{
		case 'question':	switch(formatType)
							{
								case 'text'		: 	text		=	encodeURIComponent(document.getElementById('qflash_text').innerHTML);
													path		=	'';
								break;
								case 'photo'	: 	text		=	encodeURIComponent(document.getElementById('pQuestion').value);
													path		=	document.getElementById('qphotofile').value;

								break;
								case 'audio'	:	text		=	encodeURIComponent(document.getElementById('aQuestion').value);
													path		=	document.getElementById('qaudiofile').value;
								break;
								case 'video'	:	text		=	encodeURIComponent(document.getElementById('vQuestion').value);
													path		=	document.getElementById('qvediofile').value;
								break;
								case 'math'		:	text		=	encodeURIComponent(document.getElementById('txt_QFrameMath').value);
													path		=	'';
								break;
							}
		break;
		case 'answer':	switch(formatType)
							{
								case 'text'		: 	text		=	encodeURIComponent(document.getElementById('aflash_text').innerHTML);
													path		=	'';
								break;
								case 'photo'	: 	text		=	encodeURIComponent(document.getElementById('pAnswer').value);
													path		=	document.getElementById('aphotofile').value;

								break;
								case 'audio'	:	text		=	encodeURIComponent(document.getElementById('aAnswer').value);
													path		=	document.getElementById('aaudiofile').value;
								break;
								case 'video'	:	text		=	encodeURIComponent(document.getElementById('vAnswer').value);
													path		=	document.getElementById('avediofile').value;
								break;
								case 'math'		:	text		=	encodeURIComponent(document.getElementById('txt_AFrameMath').value);
													path		=	'';
								break;
							}
		break;
		
	}
	
	var params = 'type='+type+'&text='+text+'&mid='+mid+'&fcid='+fcid+'&deck_id='+deck_id+'&formatType='+formatType+'&path='+path;

	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				if(req.responseText == 'Success')
				{
					window.top.location.href	=	_URL + "flashcardViewer.php?fcid="+ fcid;
				}
				else
				{
					alert('Error: Invalid parameters.');
				}
			}
		}
	}
	req.open('POST', url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function showHideFileUploaded(loading)
{
	if(loading == 'loading1')
	{
		$("#loading1")
		.ajaxStart(function(){
		$("#loading1").show();$("#loading2").hide();$("#loading3").hide();
		$("#loading4").hide();$("#loading5").hide();$("#loading6").hide();
		})
		.ajaxComplete(function(){
		$("#loading1").hide();
		});
	}
	else if(loading == 'loading2')
	{
		$("#loading2")
		.ajaxStart(function(){
		$("#loading2").show();$("#loading1").hide();$("#loading3").hide();
		$("#loading4").hide();$("#loading5").hide();$("#loading6").hide();
		})
		.ajaxComplete(function(){
		$("#loading2").hide();
		});
	}
	else if(loading == 'loading3')
	{
		$("#loading3")
		.ajaxStart(function(){
		$("#loading3").show();$("#loading1").hide();$("#loading2").hide();
		$("#loading4").hide();$("#loading5").hide();$("#loading6").hide();
		
		})
		.ajaxComplete(function(){
		$("#loading3").hide();
		});
	}
	
	else if(loading == 'loading4')
	{
		$("#loading4")
		.ajaxStart(function(){
		$("#loading4").show();$("#loading1").hide();$("#loading2").hide();
		$("#loading3").hide();$("#loading5").hide();$("#loading6").hide();
		
		})
		.ajaxComplete(function(){
		$("#loading4").hide();
		});
	}
	else if(loading == 'loading5')
	{
		$("#loading5")
		.ajaxStart(function(){
		$("#loading5").show();$("#loading1").hide();$("#loading2").hide();
		$("#loading3").hide();$("#loading4").hide();$("#loading6").hide();
		
		})
		.ajaxComplete(function(){
		$("#loading5").hide();
		});
	}
	else(loading == 'loading6')
	{
		$("#loading6")
		.ajaxStart(function(){
		$("#loading6").show();$("#loading1").hide();$("#loading2").hide();
		$("#loading3").hide();$("#loading4").hide();$("#loading5").hide();
		
		})
		.ajaxComplete(function(){
		$("#loading6").hide();
		});
	}
}

function deleteMediaFile(val)
{
	
	var req	   =	GetXmlHttpObject();
	var file	= val;

	var url	   =	_URL + "AJAX_FUNCTIONS/deleteMediaFiles.php?file=" + file + "&type=mediaFiles";
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if(req.responseText)
			{       }
		}
	}
		
	req.open("GET", url, true);
	req.send(null);
	return true;
}

function moreFlashcards(_URL, searchTxt)
{
	window.location.href	=	_URL + "searchResults.php?searchTxt=" + searchTxt + "&flashcard=true";
}

function moreComments(_URL, searchTxt)
{
	window.location.href	=	_URL + "searchResults.php?searchTxt=" + searchTxt + "&comments=true";
}

function moreGroups(_URL, searchTxt)
{
	window.location.href	=	_URL + "searchResults.php?searchTxt=" + searchTxt + "&groups=true";
}

function moreUsers(_URL, searchTxt)
{
	window.location.href	=	_URL + "searchResults.php?searchTxt=" + searchTxt + "&users=true";
}

function moreQuiz(_URL, searchTxt)
{
	window.location.href	=	_URL + "searchResults.php?searchTxt=" + searchTxt + "&quiz=true";
}

function populateGroups(_URL,school_id,action,gid,mode,uri)
{
	var selectMode	= mode;
	var	url	= get_cookie("urlString");
	if(!url)
	{
		document.cookie	= "urlString="+_URL;
		var url	=  get_cookie("urlString");
	}
	else
	{
		var url	=  get_cookie("urlString");	
	}
	
	var req	    =	GetXmlHttpObject();
	var url	       		=	url + "AJAX_FUNCTIONS/populateGroupList.php?school_id=" + school_id+"&listName="+action+"&gid="+gid+"&uri="+uri;
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{		
				document.getElementById('defaultGroup').innerHTML	= req.responseText;
				if(selectMode == 'edit')
				{
					document.getElementById('group').disabled	=true;
					document.getElementById('groupTxtDiv').style.visibility	='visible';
					document.getElementById('groupTxtDiv').style.display	='';
				}
		}
	}
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function populateDropDownList(_URL,val,listname)
{
	
	if(listname == 'stateList')	document.cookie	= "countryId="+val;
	if(listname == 'cityList') 	document.cookie	= "stateId="+val;
	if(listname == 'insList') 	document.cookie	= "cityId="+val;
	if(listname == 'noAction') 	document.cookie	= "insId="+val;
	
	document.cookie	="selectedVal="+val;
	var	url	= get_cookie("urlString");
	
		
		if(!url)
		{
			document.cookie	= "urlString="+_URL;
			var url	=  get_cookie("urlString");
		}
		else
		{
			var url	=  get_cookie("urlString");	
		}
			
			
		var req	    =	GetXmlHttpObject();
		//if(listname != 'noAction')
		//{
			var url	       		=	url + "AJAX_FUNCTIONS/populateGroupList.php?id=" + val+"&listName="+listname;
			
			req.onreadystatechange = function()
			{
				if(req.readyState==4)
				{
					
					if(listname == 'stateList')
					{
						
						document.getElementById(listname).innerHTML	= req.responseText;
						document.getElementById('defaultState').style.visibility	= "hidden";
						document.getElementById('defaultState').style.display	= "none";
					}
					if(listname == 'cityList')
					{
						
						document.getElementById(listname).innerHTML	= req.responseText;
						document.getElementById('defaultCity').style.visibility	= "hidden";
						document.getElementById('defaultCity').style.display	= "none";
					}
					if(listname == 'insList')
					{
						
						document.getElementById(listname).innerHTML	= req.responseText;
						document.getElementById('defaultIns').style.visibility	= "hidden";
						document.getElementById('defaultIns').style.display	= "none";
					}
					
				}
			}
			
		//}
		
		
		req.open("GET", url, true);
		req.send(null);
		return true;
}

function joinGroup(_URL,groupId,from,mid)
{
	
	if(groupId != 'join')
		document.cookie	= "groupid="+groupId;
	
	var grp_id	= get_cookie('groupid');
	
	if(grp_id == null)
		grp_id =0;
	
	if(groupId == 'join' && grp_id != 0)
	{
		var req	    =	GetXmlHttpObject();
		
		switch(from)
		{
			
			case 'popCreateDeck':
				var url	    =	_URL + "AJAX_FUNCTIONS/addGroupFilter.php?addKey=joinGroup&selectedId="+grp_id+"&from="+from;
				
				req.onreadystatechange = function()
				{
					if(req.readyState==4)
					{
						if(req.responseText.match('failed'))
						{
							delete_cookie('groupid');
							alert('You are already member of this group.\nPlease select another group to join');
						}
						else
						{
							window.top.document.getElementById('groupList').innerHTML	= req.responseText;
							window.top.closeFacebox();
							delete_cookie('groupid');
						}
					}
				}
			break;
			
			case 'memberProfile':
				var url	    =	_URL + "AJAX_FUNCTIONS/addGroupFilter.php?addKey=joinGroup&selectedId="+grp_id+"&from="+from+"&mid="+mid;
				
				req.onreadystatechange = function()
				{
					if(req.readyState==4)
					{		
						if(req.responseText.match('failed'))
						{
							delete_cookie('groupid');
							alert('You are already member of this group.\nPlease select another group to join');
						}
						else
						{
							window.top.document.getElementById('groupListEdit').innerHTML	= req.responseText;
							window.top.document.getElementById('div1').innerHTML	= req.responseText;
							window.top.document.getElementById('div2').innerHTML	= req.responseText;
							window.top.closeFacebox();
							delete_cookie('groupid');
						}
					}
				}
			break;
		} // End case
			
		req.open("GET", url, true);
		req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
		req.send(null);
		return true;
	} // End if
	else if (groupId == 'join')
		alert('Not a valid group');
}

function doSelectAll(form, chkField)
{
	//Try to get the form object in IE
	var frm		=	document.getElementById(form);
	
	//If not then try it for Mozilla Fire Fox
	if(!frm)
		var frm		=	document.forms[form];

	var el_cnt	=	frm.elements.length;

	for(i=0; i<el_cnt; i++)
	{
		var el	=	frm.elements[i].id;
		
		if(el.search(chkField) != -1)
		{
			document.getElementById(el).checked	=	true;
			//updateCount(el);
		}
	}
}

function doUnselectAll(form, chkField)
{
	//Try to get the form object in IE
	var frm		=	document.getElementById(form);
	
	//If not then try it for Mozilla Fire Fox
	if(!frm)
		var frm		=	document.forms[form];

	var el_cnt	=	frm.elements.length;

	for(i=0; i<el_cnt; i++)
	{
		var el	=	frm.elements[i].id;
		
		if(el.search(chkField) != -1)
		{
			document.getElementById(el).checked	=	false;
			//updateCount(el);
		}
	}
}

function addSelectedContacts(form, chkField)
{
	var chkedContacts	=	'';
	
	//Try to get the form object in IE
	var frm		=	document.getElementById(form);
	
	//If not then try it for Mozilla Fire Fox
	if(!frm)
		var frm		=	document.forms[form];

	var el_cnt	=	frm.elements.length;

	for(i=0; i<el_cnt; i++)
	{
		var el	=	frm.elements[i].id;
		
		if(el.search(chkField) != -1)
		{
			if(document.getElementById(el).checked	==	true)
			{
					if(chkedContacts == '')
						chkedContacts += document.getElementById(el).value;
					else
						chkedContacts += ', ' + document.getElementById(el).value;
			}
		}
	}

	var toText		=	window.top.document.getElementById('txtToMails');
	if(toText.value == '')
		toText.value 	=	chkedContacts;
	else
		toText.value 	+=	", " + chkedContacts;
	window.top.closeFacebox();
}

function populateTags(_URL,subTagId,parentTagId,parentTagName)
{
	
	var req	   	 =	GetXmlHttpObject();
	var url	   	 =	_URL + "AJAX_FUNCTIONS/subTags.php?sub_id=" + subTagId + "&parent_id=" + parentTagId;
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
				if(req.responseText != 'Invalid')
				{
						
					var checkTag	 = document.getElementById(parentTagName).value;
					if(checkTag != '')
					{
								document.getElementById(parentTagName).value	+= ',' + req.responseText; 
					}
					else
						document.getElementById(parentTagName).value	= req.responseText; 
				}
				else
					alert("Invalid tag selected");
		}
	}
		
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;	
}

function toggleDiv(id,flagit)
{
	if (flagit=="1")
	{
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
	}
	else if (flagit=="0")
	{
		if (document.layers) document.layers[''+id+''].visibility = "hide"
		else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}

function validateURL(action) 
{
	// if single card is added action will be singleCard 
	// for multiple card action will be another
	
	var urlStr	= document.getElementById('reading').value;
	var urlArr	= urlStr.split(',')
	
	if(urlStr !='')
	{
		for(var i=0;i<urlArr.length;i++)
		{
			var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
			var res = regexp.test(urlArr[i]);
			
			if(!res)
			{
				alert('Reading links must contain a valid URL\nExample: http://www.funnelbrain.com');
				document.getElementById('reading').focus();
				return false;
			}
		}
		if(action !='another')
			document.create_flashcard.submit();
		else
		{
			return action;
		}
	}
}

function toggleElements(el1, el2)
{
	var el_1 = document.getElementById(el1);
	var el_2 = document.getElementById(el2);
	
	if(el_1.style.display == 'block')
	{
		el_1.style.display = 'none';
		el_2.style.display = 'block';
	}
	else
	{
		el_1.style.display = 'block';
		el_2.style.display = 'none';
	}
}

function showMnemonics(cardNumber)
{
	document.getElementById('rdoLubeMne_' + cardNumber).checked = true;
	var mne = document.getElementById('mnemonicsContainer_' + cardNumber);
	var expl = document.getElementById('explanationContainer_' + cardNumber);
	
	mne.style.visibility = 'visible'
	mne.style.display = 'block'
	
	expl.style.visibility 	=	'hidden';
	expl.style.display 		=	'none';

	document.getElementById('ExpFormatChange_'+cardNumber).style.visibility = 'hidden';
	document.getElementById('ExpFormatChange_'+cardNumber).style.display = 'none';
	document.getElementById('MnemoFormatChange_'+cardNumber).style.visibility = 'visible';
	document.getElementById('MnemoFormatChange_'+cardNumber).style.display = '';
}

function showExplanation(cardNumber)
{
	document.getElementById('rdoLubeExp_' + cardNumber).checked = true;
	var mne = document.getElementById('mnemonicsContainer_' + cardNumber);
	var expl = document.getElementById('explanationContainer_' + cardNumber);
	
	mne.style.visibility = 'hidden'
	mne.style.display = 'none'
	
	expl.style.visibility 	=	'visible';
	expl.style.display 		=	'block';

	document.getElementById('ExpFormatChange_'+cardNumber).style.visibility = 'visible';
	document.getElementById('ExpFormatChange_'+cardNumber).style.display = '';
	document.getElementById('MnemoFormatChange_'+cardNumber).style.visibility = 'hidden';
	document.getElementById('MnemoFormatChange_'+cardNumber).style.display = 'none';
}
	
	
function groupDetails(url,groupId,action,uri, _IMAGES)
{
	
	var	url	= get_cookie("urlString");
	if(!url)
	{
		document.cookie	= "urlString="+_URL;
		var url	=  get_cookie("urlString");
	}
	else
	{
		var url	=  get_cookie("urlString");	
	}
	
	document.getElementById('desc').readOnly	= false;
	document.getElementById('desc').value		= '';
	document.getElementById('imageContainer').innerHTML	= '<a 	href='+_URL+'popBox.php?enc=n&height=125&width=320&url=popDeckPhoto.php?template=groups&fileType=groupImage&from=groups rel=facebox><img src='+_IMAGES+'defaultUploadPhoto.gif style=border:0px;></a>';
	window.top.initFaceBox(url);
	
	var schoolId	= document.getElementById('school').value;
	
	var req	    =	GetXmlHttpObject();
	var url	       		=	url + "AJAX_FUNCTIONS/getGroupDetails.php?action="+action+"&group_id=" + groupId+"&school_id="+schoolId+"&uri="+uri;	

	req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				if(req.responseText.match('Nodata'))
					return false;
				else
				{
					var res	= req.responseText.split('~~');
					document.getElementById('imageContainer').innerHTML	= res[0];
					document.getElementById('description').innerHTML	= res[1];
					document.getElementById('joinGroup').innerHTML	= res[2];
					document.getElementById('groupType').innerHTML	= res[6];
					document.getElementById('page_action').value	= res[3];
					document.getElementById('oldfile').value	= res[4];
					if(res[3] == 'editGroup')
					{
						document.getElementById('group_id').value	= res[5];
						document.getElementById('group').disabled	=true;
						document.getElementById('groupTxtDiv').style.visibility	='visible';
						document.getElementById('groupTxtDiv').style.display	='';
					}
					else
					{
						document.getElementById('groupText').value	='';
						document.getElementById('groupTxtDiv').style.visibility	='hidden';
						document.getElementById('groupTxtDiv').style.display	='none';
					}
				}
				window.top.initFaceBox(url);				
			}
		}
		req.open("GET", url, true);
		req.send(null);
		return true;
	
}
	
function toggleSelection(form, chkField, conditionalField)
{

            if(document.getElementById(conditionalField).checked == false)

                        doUnselectAll(form, chkField);

            else

                        doSelectAll(form, chkField);

}

//// PARAMETERS////////
// fronandback		- either front or back template
// showID			- template to been loaded
// hideID1,2,3		- templates to be hidden
// textID1,2		- templates text areas to be cleared
// hiddenShow		- setting hidden value for the loaded template
// hiddenHide1,2,3	- removing hidden values for unloaded templates

//frontback,showID,hideID1,hideID2,hideID3,textID1,textID2,hiddenShow,hiddenHide1,hiddenHide2,hiddenHide3
function getTemplate(frontFormat,backFormat,frontMedia,backMedia,frontText,backText)
{
	var frontback	= 'front';
	
	for(var i=0;i<2;i++)
	{
		switch(frontback)
		{
			case 'front':
				
					switch(frontFormat)
					{
							
							case 'text':
									var showID		= 'frontTextFormat';
									var textareaID	= 'fronttext0';
									var hideID1		= 'frontVideoFormat';
									var hideID2		= 'frontAudioFormat';
									var hideID3		= 'frontPhotoFormat';
									var hiddenID	= 'frontTemplate';
									var hiddenVal	= 'text';
									
							break;
							case 'video':
									var showID		= 'frontVideoFormat';
									var textareaID	= 'fronttext_video';
									var hideID1		= 'frontTextFormat';
									var hideID2		= 'frontAudioFormat';
									var hideID3		= 'frontPhotoFormat';
									var hiddenID	= 'frontTemplate';
									var hiddenVal	= 'video';
									
							break;
							case 'audio':
									var showID		= 'frontAudioFormat';
									var textareaID	= 'fronttext_audio';
									var hideID1		= 'frontTextFormat';
									var hideID2		= 'frontVideoFormat';
									var hideID3		= 'frontPhotoFormat';
									var hiddenID	= 'frontTemplate';
									var hiddenVal	= 'audio';
									
							break;
							case 'photo':
									var showID		= 'frontPhotoFormat';
									var textareaID	= 'fronttext_photo';
									var hideID1		= 'frontTextFormat';
									var hideID2		= 'frontVideoFormat';
									var hideID3		= 'frontAudioFormat';
									var hiddenID	= 'frontTemplate';
									var hiddenVal	= 'photo';
									
							break;
					}
						
						document.getElementById(showID).style.visibility		= "visible";
						document.getElementById(showID).style.display			= "";
						document.getElementById(textareaID).value				= frontText;
						
						document.getElementById(hiddenID).innerHTML			= "<input type=hidden name=frontTemplate value="+hiddenVal+">";
						
						document.getElementById(hideID1).style.visibility		= "hidden";
						document.getElementById(hideID1).style.display			= "none";
						document.getElementById(hideID2).style.visibility		= "hidden";
						document.getElementById(hideID2).style.display			= "none";
						document.getElementById(hideID3).value					= "";
						document.getElementById(hideID3).style.visibility		= "hidden";
						document.getElementById(hideID3).style.display			= "none";
				
			break;
			
			case 'back':
						switch(backFormat)
						{
								
								case 'text':
										var showID		= 'backTextFormat';
										var hideID1		= 'backVideoFormat';
										var textareaID	= 'backtext0';
										var hideID2		= 'backAudioFormat';
										var hideID3		= 'backPhotoFormat';
										var hiddenID	= 'backTemplate';
										var hiddenVal	= 'text';
										
								break;
								case 'video':
										var showID		= 'backVideoFormat';
										var textareaID	= 'backtext_video';
										var hideID1		= 'backTextFormat';
										var hideID2		= 'backAudioFormat';
										var hideID3		= 'backPhotoFormat';
										var hiddenID	= 'backTemplate';
										var hiddenVal	= 'video';
								break;
								case 'audio':
										var showID		= 'backAudioFormat';
										var textareaID	= 'backtext_audio';
										var hideID1		= 'backTextFormat';
										var hideID2		= 'backVideoFormat';
										var hideID3		= 'backPhotoFormat';
										var hiddenID	= 'backTemplate';
										var hiddenVal	= 'audio';
								break;
								case 'photo':
										var showID		= 'backPhotoFormat';
										var textareaID	= 'backtext_photo';
										var hideID1		= 'backTextFormat';
										var hideID2		= 'backVideoFormat';
										var hideID3		= 'backAudioFormat';
										var hiddenID	= 'backTemplate';
										var hiddenVal	= 'photo';
								break;
						}
						
						document.getElementById(showID).style.visibility		= "visible";
						document.getElementById(showID).style.display			= "";
						document.getElementById(textareaID).value				= backText;
						document.getElementById(hiddenID).innerHTML			= "<input type=hidden name=backTemplate value="+hiddenVal+">";
						document.getElementById(hideID1).style.visibility		= "hidden";
						document.getElementById(hideID1).style.display			= "none";
						document.getElementById(hideID2).style.visibility		= "hidden";
						document.getElementById(hideID2).style.display			= "none";
						document.getElementById(hideID3).value					= "";
						document.getElementById(hideID3).style.visibility		= "hidden";
						document.getElementById(hideID3).style.display			= "none";
			break;
			
		}
		frontback = 'back';
	}
}

function showAddThis(_URL)
{
	var req   =          GetXmlHttpObject();
	var url   =          _URL + "AJAX_FUNCTIONS/addThis.php";
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if(req.responseText)
			{
				document.getElementById('addThis').innerHTML    = req.responseText;
			}
		}
	}
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function clearDefaultText(id, val)
{
	if(document.getElementById(id).value == val)
		document.getElementById(id).value					=	"";
	if((val != "Enter question in text here") && (val != "Enter answer in text here"))
		document.getElementById(id).style.textAlign			=	'left';
	if((val == "Enter question in text here") || (val == "Enter answer in text here"))
		document.getElementById(id).style.textAlign			=	'center';
	//document.getElementById(id).style.lineHeight			=	'';
}
 
function writeDefaultText(id, val)
{
	if(document.getElementById(id).value == '')
	{
		document.getElementById(id).style.textAlign			=	'center';
		document.getElementById(id).value					=	val;
		//if(val = "Enter question/answer in text here")
			//document.getElementById(id).style.lineHeight	=	'75px';
	}
}

/*** Start Deck Rating ***/

function enableDeckRate()
{
	document.getElementById('yellowStar').style.visibility		=	'hidden';
	document.getElementById('yellowStar').style.display			=	'none';
	document.getElementById('rateDeck').style.visibility		=	'visible';
	document.getElementById('rateDeck').style.display			=	'';
	//document.getElementById('thanksMsg').style.visibility		=	'hidden';
	//document.getElementById('thanksMsg').style.display		=	'none';
	document.getElementById('showRateDeck').style.visibility	=	'visible';
	document.getElementById('showRateDeck').style.display		=	'';
	document.getElementById('hideRateDeck').style.visibility	=	'hidden';
	document.getElementById('hideRateDeck').style.display		=	'none';
}

function disableDeckRate()
{
	document.getElementById('hideRateDeck').style.visibility	=	'visible';
	document.getElementById('hideRateDeck').style.display		=	'';
	document.getElementById('yellowStar').style.visibility		=	'visible';
	document.getElementById('yellowStar').style.display			=	'';
	document.getElementById('showRateDeck').style.visibility	=	'hidden';
	document.getElementById('showRateDeck').style.display		=	'none';
	document.getElementById('rateDeck').style.visibility		=	'hidden';
	document.getElementById('rateDeck').style.display			=	'none';
}

/*** End Deck Rating ***/

/* Start join OR leave the group */
function joinTheGroup(_URL, mid, gid, type,from)
{
	var expan	= from;
	var req   	=		GetXmlHttpObject();
	var url   	=		_URL + "AJAX_FUNCTIONS/joinLeaveGroup.php?mid=" + mid + "&gid=" + gid + "&type=" + type;
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if(req.responseText)
			{
				
				if(type == 'join')
				{
					if (req.responseText != 'false') {
						
						if (from=='premierModal')
						{	
							window.top.closeFacebox();
							window.location.reload();
						}
						window.location.href	=	window.location.href;						
					} else {
						
						alert('You are already member of this group');
					}
				}
				if(type == 'leave')
				{
					if(from == 'rgroup')
						window.location.href	=	'addEditProfile.php?exp='+from;
					else
					{
						window.location.href	=	window.location.href;
					}
				}
			}
		}
	}
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function showJoinLink(_URL)
{
	document.getElementById('joinGroup').style.visibility				=	'visible';
	document.getElementById('joinGroup').style.display					=	'';
	document.getElementById('leaveGroup').style.display					=	'none';
}

function showJoinPrivateGroupLink(_URL)
{
	document.getElementById('joinPrivateGroup').style.visibility		=	'visible';
	document.getElementById('joinPrivateGroup').style.display			=	'';	
	document.getElementById('leaveGroup').style.display					=	'none';
}

function showJoinPremiumGroupLink(_URL)
{
	document.getElementById('joinPremiumGroup').style.visibility		=	'visible';
	document.getElementById('joinPremiumGroup').style.display			=	'';
	document.getElementById('leavePremiumGroup').style.display			=	'none';
}

function showLeaveLink(_URL)
{
	document.getElementById('leaveGroup').style.visibility				=	'visible';
	document.getElementById('leaveGroup').style.display					=	'';
	document.getElementById('joinGroup').style.display					=	'none';
}

function showLeavePremiumGroupLink(_URL)
{
	document.getElementById('leavePremiumGroup').style.visibility				=	'visible';
	document.getElementById('leavePremiumGroup').style.display					=	'';
	document.getElementById('joinPremiumGroup').style.display					=	'none';
}

function populateThread(_URL,groupId,forumTopic,minimise)
{
		
	var	url	= get_cookie("urlString");
	if(!url)
	{
		document.cookie	= "urlString="+_URL;
		var url	=  get_cookie("urlString");
	}
	else
	{
		var url	=  get_cookie("urlString");	
	}
	
	var req   	=		GetXmlHttpObject();
	var url   	=		_URL + "AJAX_FUNCTIONS/manageForumThread.php?gid=" + groupId + "&action=forumResponse";
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			
			var res	= req.responseText.split("~~");
			
			document.getElementById('responses').innerHTML	=	res[0];
			document.getElementById('minimise').innerHTML		=	res[1];
			
			if(document.getElementById('responses').style.display != 'block')
			{
				document.getElementById('responses').style.display = 'block';
				document.getElementById('minimise').style.display = 'block';
			}
			
				
		}
	}
	req.open("GET", url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return true;
}

function groupForumResponses(_URL, gid, pg, action)
{
	var req =		GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/manageForumThread.php";
	
	if(action != 'load')
	{
		var	replyMsg	=	window.top.document.getElementById('txtdiscussion').value;
		if(replyMsg == '' || replyMsg == 'Join the Discussion. Write Something...')
		{
			alert('No message to post');
			return false;
		}
		var params = "gid=" + gid + "&response="+encodeURIComponent(replyMsg)+'&action='+action+'&pg='+pg;
	}
	else
		var params = "gid=" + gid+'&action='+action+'&pg='+pg;

	waitboxStyle	=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
	waitcursor		=	getWaitCursor(_URL, waitboxStyle);
	window.top.document.getElementById('dispostBox').innerHTML	=	waitcursor;

	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if (req.responseText=='error')
			{
				alert('Error: Invalid parameters.');
			}
			else
			{
				res		=	req.responseText.split('~~~###disnum###~~~');
				window.top.document.getElementById('dispostBox').innerHTML	=	res[0];
				window.top.document.getElementById('displaynum').innerHTML	=	res[1];
				window.top.document.getElementById('txtdiscussion').value	=	'Join the Discussion. Write Something...';
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}


function toggleEditProfile(showId, hideIdFirst, hideIdSecond,_IMAGES)
{
		
	//alert(showId+'-----'+hideId)
	document.getElementById(showId).style.visibility	="visible";
	document.getElementById(showId).style.display	="";
	document.getElementById(hideIdFirst).style.visibility	="hidden";
	document.getElementById(hideIdFirst).style.display	="none";
	document.getElementById(hideIdSecond).style.visibility	="hidden";
	document.getElementById(hideIdSecond).style.display	="none";
	
	switch(showId)
	{
		case 'generalContent':
			document.getElementById('generalImg').innerHTML	= '<img src='+_IMAGES+'profileArrowDown.gif>';
			document.getElementById('groupImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
			document.getElementById('deckImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
		break;
		case 'groupContent':
			document.getElementById('groupImg').innerHTML	= '<img src='+_IMAGES+'profileArrowDown.gif>';
			document.getElementById('generalImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
			document.getElementById('deckImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
		break;
		case 'deckContent':
			document.getElementById('deckImg').innerHTML	= '<img src='+_IMAGES+'profileArrowDown.gif>';
			document.getElementById('groupImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
			document.getElementById('generalImg').innerHTML	= '<img src='+_IMAGES+'profileArrow.gif>';
		break;
	}
}

function enableAddMoreDeckTags()
{
	document.getElementById('tagSubmit').style.visibility	=	'visible';
	document.getElementById('tagSubmit').style.display		=	'';
}

/* functions supporting menu in add edit flashcard  */
function selectFormat(action,cardNum,format)
{
	//alert(action+'---'+cardNum+'---'+format);
	updateElementValue(cardNum);
	
	switch(action)
	{
		case 'question':
		
			switch(format)
			{
				case'text':	
				//Fix for IE
						document.getElementById('QuestionText_'+cardNum).style.visibility	=	'visible';
						document.getElementById('QuestionVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionPhoto_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.display		=	'none';
						
						document.getElementById('QuestionText_'+cardNum).style.display		=	'';
						document.getElementById('QuestionVideo_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionAudio_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
				case'audio':	
						//fix for IE
						document.getElementById('QuestionText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionAudio_'+cardNum).style.visibility	=	'visible';
						document.getElementById('QuestionPhoto_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.display		=	'none';

						document.getElementById('QuestionText_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionVideo_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionAudio_'+cardNum).style.display		=	'';
						document.getElementById('QuestionPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						//alert(document.getElementById('qhidfid_'+cardNum).value);
						
				break;
				case'video':	
						//fix for IE
						document.getElementById('QuestionText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionVideo_'+cardNum).style.visibility	=	'visible';
						document.getElementById('QuestionAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionPhoto_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.display		=	'none';
						
						document.getElementById('QuestionText_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionVideo_'+cardNum).style.display		=	'';
						document.getElementById('QuestionAudio_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
				
				
				case'math':	
					//fix for IE
					document.getElementById('QuestionText_'+cardNum).style.visibility	=	'hidden';
					document.getElementById('QuestionVideo_'+cardNum).style.visibility	=	'hidden';
					document.getElementById('QuestionAudio_'+cardNum).style.visibility	=	'hidden';
					document.getElementById('QuestionPhoto_'+cardNum).style.visibility	=	'hidden';
					
					document.getElementById('QuestionMath_'+cardNum).style.visibility	=	'visible';
					document.getElementById('QuestionMath_'+cardNum).style.display		=	'';

					document.getElementById('QuestionText_'+cardNum).style.display		=	'none';
					document.getElementById('QuestionVideo_'+cardNum).style.display		=	'none';
					document.getElementById('QuestionAudio_'+cardNum).style.display		=	'none';
					document.getElementById('QuestionPhoto_'+cardNum).style.display		=	'none';
					
					document.getElementById('qhidfid_'+cardNum).value					=	format;
					
			break;
				
				
				
				
				case'photo':	
						//fix for IE
						document.getElementById('QuestionText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionPhoto_'+cardNum).style.visibility	=	'visible';
						document.getElementById('QuestionMath_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('QuestionMath_'+cardNum).style.display		=	'none';
						
						document.getElementById('QuestionText_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionVideo_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionAudio_'+cardNum).style.display		=	'none';
						document.getElementById('QuestionPhoto_'+cardNum).style.display		=	'block';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
			}
			
			//alert(document.getElementById('qhidfid_'+card).value);
		break;
		
		case 'answer':
			switch(format)
			{
				case'text':	
						document.getElementById('AnswerText_'+cardNum).style.display		=	'block';
						document.getElementById('AnswerVideo_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerAudio_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerPhoto_'+cardNum).style.display		=	'none';
						document.getElementById('ahidfid_'+cardNum).value					=	format;
						document.getElementById('AnswerMath_'+cardNum).style.display		=	'none';
						
				break;
				case'audio':	
						document.getElementById('AnswerText_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerVideo_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerAudio_'+cardNum).style.display		=	'block';
						document.getElementById('AnswerPhoto_'+cardNum).style.display		=	'none';
						document.getElementById('ahidfid_'+cardNum).value					=	format;
						document.getElementById('AnswerMath_'+cardNum).style.display		=	'none';
						
				break;
				case'video':	
						document.getElementById('AnswerText_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerVideo_'+cardNum).style.display		=	'block';
						document.getElementById('AnswerAudio_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerPhoto_'+cardNum).style.display		=	'none';
						document.getElementById('ahidfid_'+cardNum).value					=	format;
						document.getElementById('AnswerMath_'+cardNum).style.display		=	'none';
						
				break;
				
				
				case'math':	
					document.getElementById('AnswerText_'+cardNum).style.display		=	'none';
					document.getElementById('AnswerVideo_'+cardNum).style.display		=	'none';
					document.getElementById('AnswerAudio_'+cardNum).style.display		=	'none';
					document.getElementById('AnswerPhoto_'+cardNum).style.display		=	'none';
					document.getElementById('ahidfid_'+cardNum).value					=	format;
					document.getElementById('AnswerMath_'+cardNum).style.display		=	'block';
					
				break;
				
				
				
				case'photo':	
						document.getElementById('AnswerText_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerVideo_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerAudio_'+cardNum).style.display		=	'none';
						document.getElementById('AnswerPhoto_'+cardNum).style.display		=	'block';
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						document.getElementById('AnswerMath_'+cardNum).style.display		=	'none';
						
				break;
			}
		break;

		case 'mnemonics':
			switch(format)
			{
				case'text':	

				//Fix for IE
						document.getElementById('MnemoText_'+cardNum).style.visibility	=	'visible';
						document.getElementById('MnemoVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoPhoto_'+cardNum).style.visibility	=	'hidden';
						
						document.getElementById('MnemoText_'+cardNum).style.display		=	'';
						document.getElementById('MnemoVideo_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoAudio_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
				case'audio':	
						//fix for IE
						document.getElementById('MnemoText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoAudio_'+cardNum).style.visibility	=	'visible';
						document.getElementById('MnemoPhoto_'+cardNum).style.visibility	=	'hidden';

						document.getElementById('MnemoText_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoVideo_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoAudio_'+cardNum).style.display		=	'';
						document.getElementById('MnemoPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						//alert(document.getElementById('qhidfid_'+cardNum).value);
						
				break;
				case'video':	
						//fix for IE
						document.getElementById('MnemoText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoVideo_'+cardNum).style.visibility	=	'visible';
						document.getElementById('MnemoAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoPhoto_'+cardNum).style.visibility	=	'hidden';
						
						document.getElementById('MnemoText_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoVideo_'+cardNum).style.display		=	'';
						document.getElementById('MnemoAudio_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
				case'photo':	
						//fix for IE
						document.getElementById('MnemoText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('MnemoPhoto_'+cardNum).style.visibility	=	'visible';
						
						document.getElementById('MnemoText_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoVideo_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoAudio_'+cardNum).style.display		=	'none';
						document.getElementById('MnemoPhoto_'+cardNum).style.display		=	'block';
						
						document.getElementById('qhidfid_'+cardNum).value					=	format;
						
				break;
			}
		break;

		case 'explanation':
			switch(format)
			{
				case'text':	
				//Fix for IE
						document.getElementById('ExpText_'+cardNum).style.visibility	=	'visible';
						document.getElementById('ExpVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpPhoto_'+cardNum).style.visibility	=	'hidden';
						
						document.getElementById('ExpText_'+cardNum).style.display		=	'';
						document.getElementById('ExpVideo_'+cardNum).style.display		=	'none';
						document.getElementById('ExpAudio_'+cardNum).style.display		=	'none';
						document.getElementById('ExpPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('ehidfid_'+cardNum).value					=	format;
						
				break;
				case'audio':	
						//fix for IE
						document.getElementById('ExpText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpAudio_'+cardNum).style.visibility	=	'visible';
						document.getElementById('ExpPhoto_'+cardNum).style.visibility	=	'hidden';

						document.getElementById('ExpText_'+cardNum).style.display		=	'none';
						document.getElementById('ExpVideo_'+cardNum).style.display		=	'none';
						document.getElementById('ExpAudio_'+cardNum).style.display		=	'';
						document.getElementById('ExpPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('ehidfid_'+cardNum).value					=	format;
						//alert(document.getElementById('qhidfid_'+cardNum).value);
						
				break;
				case'video':	
						//fix for IE
						document.getElementById('ExpText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpVideo_'+cardNum).style.visibility	=	'visible';
						document.getElementById('ExpAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpPhoto_'+cardNum).style.visibility	=	'hidden';
						
						document.getElementById('ExpText_'+cardNum).style.display		=	'none';
						document.getElementById('ExpVideo_'+cardNum).style.display		=	'';
						document.getElementById('ExpAudio_'+cardNum).style.display		=	'none';
						document.getElementById('ExpPhoto_'+cardNum).style.display		=	'none';
						
						document.getElementById('ehidfid_'+cardNum).value					=	format;
						
				break;
				case'photo':	
						//fix for IE
						document.getElementById('ExpText_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpVideo_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpAudio_'+cardNum).style.visibility	=	'hidden';
						document.getElementById('ExpPhoto_'+cardNum).style.visibility	=	'visible';
						
						document.getElementById('ExpText_'+cardNum).style.display		=	'none';
						document.getElementById('ExpVideo_'+cardNum).style.display		=	'none';
						document.getElementById('ExpAudio_'+cardNum).style.display		=	'none';
						document.getElementById('ExpPhoto_'+cardNum).style.display		=	'block';
						
						document.getElementById('ehidfid_'+cardNum).value					=	format;
						
				break;
			}
		break;
		
	}
}

function updateElementValue(cardNum)
{	
	window.top.document.getElementById('cardFlag_'+cardNum).value = 'yes';
}

function addGroups(_URL, type, from)
{
	var req =	GetXmlHttpObject();
	var url	=	_URL+"AJAX_FUNCTIONS/addGroups.php";
	var selectflag = false;
	
	var id			=	document.getElementById('id').value;
	var grpCount	=	document.getElementById('groupCount').value;
	var params		=	'type='+type+'&from='+from+'&grpCount='+grpCount+'&id='+id;
	
	for(var i=0; i<grpCount; i++)
	{
		var ele = document.getElementById('grp_'+i);

		if(ele.checked)
		{
			selectflag	=	true;
			params		=	params + '&grp_'+i+'='+ele.value;
		}
	}
	if (!selectflag)
	{
		document.getElementById('jserr').innerHTML	=	'Please select atleast one group.';
		return false;
	}
	else
	{
		req.onreadystatechange = function()
		{
			if(req.readyState==4) 
			{
				if (req.responseText=='failed')
				{
					document.getElementById('jserr').innerHTML	=	'Unable to add '+from+' to the selected groups.';
				}
				else {
					document.getElementById('jserr').innerHTML	=	from+' is added successfully.';
					window.top.location.reload(true);
				}
			}
		}
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}

function loadBottomRail(_URL, deck_id, currentCardId, action)
{
	var req 		=	initRequest();
	var url			=	_URL + "ajax_functions/getFlashcardBottomRail.php?deck_id=" + deck_id + "&currentCardId=" + currentCardId +"&action="+action+"&is_private_deck=" + get_is_private();
	
	req 			=	initRequest(url);

	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				document.getElementById('frontTextContainer').innerHTML	=	"";
				document.getElementById('frontTextContainer').innerHTML	=	req.responseText;
				document.getElementById('IKnowThis').focus();
				
			} else if (req.status == 204)
			{}
		}
	};
	req.open('POST', url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return false;
}

function loadBottomRailHistory(_URL, deck_id, page, action)
{
	var req 		=	initRequest();
	var url			=	_URL + "ajax_functions/getFlashcardBottomRailHistory.php?deck_id=" + deck_id + "&page=" + page +"&action"+action;
	req 			=	initRequest(url);
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				document.getElementById('Version').innerHTML	=	"";
				document.getElementById('Version').innerHTML	=	req.responseText;			
			} else if (req.status == 204)
			{}
		}
	};
	req.open('POST', url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return false;
}

onerror=handleErr;
var txt="";

function handleErr(msg,url,line)
{
	var req 		=	initRequest();
	var url			=	_URL_JS + "ajax_functions/logError.php?error=" + msg + "&url=" + url + "&line=" + line;
	req 			=	initRequest(url);
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{				
				
			} else if (req.status == 204)
			{}
		}
	};
	req.open('POST', url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);

	return true;
}

function addAsFriend(_URL, friendMemberId, divId)
{
	var url			=	_URL + "ajax_functions/addFriend.php?friendMemberId=" + friendMemberId;
 	var req 		=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
			    document.getElementById('addFriendActivityIndicator').style.display = 'none';
				if (divId!='')
				{
	                var addFriendLink = window.top.document.getElementById(divId);
    	            addFriendLink.innerHTML = "";
				}
            	window.parent.closeFacebox();
			} 
		}
	};
	req.open('POST', url, true);
	req.send(null);
	document.getElementById('addFriendActivityIndicator').style.display = 'inline';
}

function updateFriendRequest(_URL, friendMemberId, status)
{
	var url			=	_URL + "ajax_functions/updateFriendRequest.php?friendMemberId=" + friendMemberId + "&Status=" + status;
	var req 		=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
			    incrementCount("inboxCount", -1);
			    incrementCount("friendRequestsCount", -1);
			    incrementCount("nCount", -1);
				incrementCount("msgCount", -1);

			    if(status == "C")
			        incrementCount("friendsCount", 1);

        	    document.getElementById("friendRequestActivityIndicator_" + friendMemberId).style.display =	'none';
				document.getElementById("request_" + friendMemberId).innerHTML	=	req.responseText;
				var cnt	=	document.getElementById('msgCount').innerHTML;
				if (parseInt(cnt)==1){
					document.getElementById('msgs').innerHTML = 'Message';
				}
		    } 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	document.getElementById("friendRequestActivityIndicator_" + friendMemberId).style.display =	'inline';
	return false;
}

function incrementCount(elementId, increment) 
{
	var element = document.getElementById(elementId);
    if(element)
        element.innerHTML = parseInt(element.innerHTML) + increment;
}

function removeFromPage(cardNum)
{
	var el = document.getElementById(cardNum);
	var parent = document.getElementById('flashcardsContainer');
	parent.removeChild(el);
	
}

function get_is_private()
{
	return document.getElementById("is_private_deck").value;
}

function DeleteCard(_URL, deckId,view, cardNum, flashcardId, is_private_deck )
{
	
	
	if((view == 'cards') || (view == 'gallery') || (view =='list')) {
		var url			=	_URL + "ajax_functions/delete.php?type=flashcard&id=" + flashcardId + "&is_private_deck=" + is_private_deck;
		var req 		=	initRequest();	
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					//loadFlashcards(_URL, deckId, view,pageNumber);
					removeFromPage(cardNum);
				} 
			}
		};	
		req.open('POST', url, true); 
		req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
		req.send(null); 
		return false;
	}
	else if(view == 'display') {
		removeFromPage(cardNum);
	}
	
	
}

//var newIndex;

function InsertCard(_URL, deckId, newCardIndex,view, currId, is_private_deck )
{
		document.getElementById('msgDiv').style.display				=	'block';
		var req 	=	initRequest();

		var newIndex = document.getElementById('newcard_index').value;
		
		switch(view)
		{
			case 'cards': // last param - fix for deck without cards in edit mode
				var url		=	_URL + "addNewCardCardsView.php?newCardIndex=" + newIndex+"&pR=no&mode=insert&deck_id="+deckId + "&is_private_deck=" +is_private_deck;
				
				break;
			
			case 'gallery':
				var url		=	_URL + "addNewCardGalleryView.php?newCardIndex=" + newIndex+"&pR=no&mode=insert&deck_id="+deckId+ "&is_private_deck=" +is_private_deck;
				
				break;

			case 'list':
				var url		=	_URL + "addNewCardListView.php?newCardIndex=" + newIndex+"&pR=no&mode=insert&deck_id="+deckId+ "&is_private_deck=" +is_private_deck;
				
				break;

			default:
				var url		=	_URL + "addNewCardCardsView.php?newCardIndex=" + newIndex+"&mode=insert&deck_id="+deckId+ "&is_private_deck=" +is_private_deck;
		}

		req 		=	initRequest(url);
		
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					var newChild		=	document.createElement("div");
					newChild.setAttribute("id", "cardNum_" + newIndex);
					
					if(view == 'cards') {
						newChild.setAttribute("style", "float:left; border:#0066FF solid 0px; margin:5px; width:496px;" );
					}
					else if ( view == 'gallery') {
						newChild.setAttribute("style","border:0px #000000 solid; float:left; width:100%; margin-left:5px;");
					}
					else if ( view == 'list') {
						newChild.setAttribute("style","border:0px #000000 solid; float:left; width:100%; margin-left:5px;");
					}
					newChild.innerHTML	=	req.responseText;
					var parentElement	=	document.getElementById('flashcardsContainer');
					if(parentElement.hasChildNodes)
					{
						var el = document.getElementById(currId);
						if(el) {
							parentElement.insertBefore(newChild, el);
							newIndex = parseInt(newIndex) + 1;
							document.getElementById('newcard_index').value = newIndex;
						}
					}
					//document.getElementById('flashcardsContainer').innerHTML	+=	req.responseText;
					window.top.initFaceBox(_URL);
					document.getElementById('msgDiv').style.display				=	'none';
					if(timerRunning == false)
						StartTheTimer();
					
				} else if (req.status == 204)
				{}
			}
		};
		req.open('POST', url, true);
		req.send(null);
		return false;

}

function makeDeckPrivate(_URL, deck_id, flag, needLeitner, fc_id)
{
	var req 	=	initRequest();
	var url		=	_URL + "includes/controllers/privateDeckController.php?action=makePrivate&deck_id=" + deck_id;
	
	var publicDeckId = deck_id;
	req 		=	initRequest(url);
	
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				//deck_id = req.responseText;
				fcid = req.responseText;
				//if(deck_id != '') {
				if(fcid != '') {
					document.getElementById("is_private_deck").value= 'Y';
					window.location.href	=	_URL + "flashcardViewer.php?fcid=" + fcid +"&is_private_deck=Y&needLietner=" + needLeitner +"&action=update";
				}
			}
		}
	};
	req.open('POST', url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return false;
}

function SynchronizePrivateDeck(_URL, deck_id, fc_id)
{
	
	var url		=	_URL + "includes/controllers/privateDeckController.php?action=synchronize&deck_id=" + deck_id + "fcid=" + fc_id;
	var req 		=	initRequest();
	
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				deck_id = req.responseText;
				if(deck_id != 0) {
					document.getElementById("is_private_deck").value= 'N';

					window.location.href	=	_URL + "flashcardViewer.php?fcid=" + fc_id;
				}
			}
		}
	};
	req.open('POST', url, true);
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null);
	return false;
}

//Private Group Non-Ajax Functions
function privateGroupMemberEvent(_URL,type, mid, gid)
{
	var redirect = window.location.href;
	if (type == 'deleteMember')
		ans = confirm("WARNING !!\n\nAre you sure, You want to delete this member permanently? \nDo you want to continue?");
	if (type == 'addAsAdmin')
		ans = confirm("WARNING !!\n\nAre you sure, You want to provide Administrative access to this member? \nDo you want to continue?");
	if(ans)
	{
		var url	=	_URL + "AJAX_FUNCTIONS/privateGroupMemberAdmin.php?type="+type+"&gid="+gid+"&mid="+mid+"&redirect="+encodeURIComponent(redirect);

		var req 		=	initRequest();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					document.getElementById('PrivateGroupMainContainer').innerHTML	=	req.responseText;
				}
			}
		}
		req.open('GET', url, true); 
		req.send(null); 
		return false; 
	}
}

function updateNotificationStatus(_URL, notificationsId, status, notificationType)
{
	var url			=	_URL + "ajax_functions/updateNotificationStatus.php?notificationsId=" + notificationsId + "&Status=" + status + "&notificationType=" + notificationType;

	var req 		=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
			    incrementCount("inboxCount", -1);
			    incrementCount("notificationCount", -1);
			    incrementCount("nCount", -1);
				incrementCount("msgCount", -1);
				if (parseInt(document.getElementById("nCount").innerHTML)==0){
					document.getElementById("zerocount").innerHTML	=	"<hr class='friendRequestSeparator'/><br />You don't have any Notifications";
				}
				
        	    document.getElementById("InboxNotificationIndicator_" + notificationsId).style.display 	=	'none';
				document.getElementById("notification_" + notificationsId).innerHTML					=	req.responseText;
				document.getElementById("notification_" + notificationsId).style.display 				=	'none';
				var cnt	=	document.getElementById('msgCount').innerHTML;
				if (parseInt(cnt)==1){
					document.getElementById('msgs').innerHTML = 'Message';
				}
		    } 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	document.getElementById("InboxNotificationIndicator_" + notificationsId).style.display =	'inline';
	return false; 
}

function showLoadingImage()
{
	document.getElementById("Loading").style.display =	'inline';
}

/* Quiz Based JS Functions */
function QuizLoad(_URL, quizId, startIndex, quesLimit, page_id, db)
{
	document.getElementById("quizTitle").focus();
	var	quesset_index	=	document.getElementById("quesset_index").value;
	var url			=	_URL + "ajax_functions/getQuizQuesAnswer.php?quesset_index="+quesset_index+"&quizId="+quizId+"&startIndex="+startIndex+"&quesLimit="+quesLimit+"&page_id="+page_id+'&db='+db;
	var req 		=	initRequest();

	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				document.getElementById("QuizSet").innerHTML		= req.responseText;
				document.getElementById("quesset_index").value		= document.getElementById("quesset_index_temp").value;
				window.top.initFaceBox(_URL);
			} 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	return false; 
}

function addNewQuizAnswer(_URL, quesNum, ansNum)
{
	closeEditor();
	var ansset_index	=	document.getElementById("ansset_index_"+quesNum).value;
	var url				=	_URL + "ajax_functions/addNewQuizAnswer.php?quesNum="+quesNum+"&ansNum="+ansset_index;
	var req 			=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				var ansNum_next	=	parseInt(ansset_index);
				var divTag = document.createElement("div");
				divTag.id = "answer_"+quesNum+"_"+ansNum_next;
				document.getElementById("quizAnsContainer_"+quesNum).appendChild(divTag);
				document.getElementById("answer_"+quesNum+"_"+ansNum_next).innerHTML	=	req.responseText;
				document.getElementById("ansadd_"+quesNum+"_"+ansNum).className			=	'delhidden';
				document.getElementById("ansdelete_"+quesNum+"_"+ansNum).className		=	'delvisible';
				document.getElementById("ansset_index_"+quesNum).value					=	parseInt(parseInt(ansset_index) + 1);
				var acount	=	parseInt(document.getElementById("acount_"+quesNum).value)+1;
				document.getElementById("acount_"+quesNum).value	=	acount;
				Reordering(quesNum, 'answer');
				window.top.initFaceBox(_URL);
			} 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	return false; 
}

function addNewQuizQuesAnsSet(_URL)
{
	closeEditor();
	var	quesset_index	=	document.getElementById("quesset_index").value;
	var page_id			=	document.getElementById('page_id').value;
	var quesIndexNext	=	parseInt(quesset_index) + 1;

	var url				=	_URL + "ajax_functions/addNewQuizQuesAnsSet.php?quesset_index="+quesset_index+"&page_id="+page_id;
	var req 			=	initRequest();

	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				document.getElementById("QuesAnsMainContainer_"+quesset_index).innerHTML	= req.responseText;
				document.getElementById("quesset_index").value								= parseInt(quesIndexNext);	
				var divTag 			= document.createElement("div");
				divTag.id 			= "QuesAnsMainContainer_"+quesIndexNext;
				divTag.className 	= "QuesAnsMainContainer";
				document.getElementById("QuizSet").appendChild(divTag);
				var qcount	=	parseInt(document.getElementById("qcount").value)+1;
				document.getElementById("qcount").value		=	qcount;
				Reordering('', 'question');
				window.top.initFaceBox(_URL);
		    } 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	return false; 
}

function SelectFormatTemp(forTemp, quesAnsNum, blockType)
{
	
	closeEditor();
	document.getElementById(blockType.toLowerCase()+'TempType_'+quesAnsNum).value	=	forTemp;
	document.getElementById(blockType+forTemp+'_'+quesAnsNum).className				=	'quizTextHolder';
	if (blockType=='Ques')
		document.getElementById('quesFlag_'+quesAnsNum).value	=	'yes';
	else if(blockType=='Ans')
		document.getElementById('ansFlag_'+quesAnsNum).value	=	'yes';
	if (forTemp)
	{
		switch (forTemp)
		{
			case 'Text':
						document.getElementById(blockType+'Photo_'+quesAnsNum).className				=	'quizTextHolderHidden';
						document.getElementById(blockType+'Math_'+quesAnsNum).className					=	'quizTextHolderHidden';
						document.getElementById(blockType+'MathDialog_'+quesAnsNum).style.visibility	=	'hidden';
			break;
			case 'Photo':
						document.getElementById(blockType+'Text_'+quesAnsNum).className					=	'quizTextHolderHidden';
						document.getElementById(blockType+'Math_'+quesAnsNum).className					=	'quizTextHolderHidden';
						document.getElementById(blockType+'MathDialog_'+quesAnsNum).style.visibility	=	'hidden';
			break;
			case 'Math':
						document.getElementById(blockType+'Text_'+quesAnsNum).className					=	'quizTextHolderHidden';
						document.getElementById(blockType+'Photo_'+quesAnsNum).className				=	'quizTextHolderHidden';
						document.getElementById(blockType+'MathDialog_'+quesAnsNum).style.visibility	=	'visible';
			break;
		}
	}
}

function removeQuesAns(_URL,Id,type,divId)
{
	closeEditor();
	if (type=='answer')	
	{
		var el 		= document.getElementById("answer_"+divId);
		var cont	= divId.split("_");
		document.getElementById('quizAnsContainer_'+cont[0]).removeChild(el);
		var acount	=	parseInt(document.getElementById("acount_"+cont[0]).value)-1;
		document.getElementById("acount_"+cont[0]).value	=	acount;
		Reordering(cont[0], 'answer');
	}
	else 
	{
		var el = document.getElementById("QuesAnsMainContainer_"+divId);
		document.getElementById('QuizSet').removeChild(el);
		var qcount	=	parseInt(document.getElementById("qcount").value)-1;
		document.getElementById("qcount").value		=	qcount;
		if ((document.getElementById("qcount").value==0) && document.getElementById('page_id').value>1)
			window.location.reload(true);
		Reordering('', 'question');
	}
	window.top.initFaceBox(_URL);
}

function Reordering(divId, type)
{
	switch(type)
	{
		case 'answer':
			var ansset_index	=	document.getElementById('ansset_index_'+divId).value;
			var no	=	1;
			for (i=0; i<parseInt(ansset_index); i++)
			{
				if (document.getElementById('answer_'+divId+'_'+i)!=null || document.getElementById('answer_'+divId+'_'+i)!='undefined')
				{
					var e2	=	'an_'+divId+'_'+(i+1);
					if (document.getElementById(e2)!=null)
					{
						document.getElementById(e2).innerHTML	=	no;
						no	=	parseInt(no) + 1;
					}
				}
			}
		break;
		case 'question':
			var queset_index	=	document.getElementById('quesset_index').value;
			var page_id			=	document.getElementById('page_id').value;
			var no	=	1+((parseInt(page_id)-1)*10);
			for (i=0; i<parseInt(queset_index); i++)
			{
				if (document.getElementById('QuesAnsMainContainer_'+i)!=null || document.getElementById('QuesAnsMainContainer_'+i)!='undefined')
				{
					if (document.getElementById('question_'+i)!=null)
					{
						var e2	=	'qn_'+((parseInt(i)+1)+((parseInt(page_id)-1)*10));
						
						if (document.getElementById(e2)!=null)
						{
							document.getElementById(e2).innerHTML	=	no;
							no	=	parseInt(no) + 1;
						}
					}
				}
			}
		break;
	}
}

function deleteQuizQuesAnswer(_URL,Id,type,divId)
{
	if (type=='answer')
	{
		var cont	= divId.split("_");
			deleteQuesAns(_URL,Id,type,divId);	
	}
	else
	{
		if ((document.getElementById("qcount").value==1) || (document.getElementById("totQuesCount").value==1))
		{
			if (document.getElementById('page_id').value==1)
			{
				if (document.getElementById("totQuesCount").value>10 && (document.getElementById("qcount").value==1))
				{
					deleteQuesAns(_URL,Id,type,divId);
					window.location.reload(true);
				}
				else
					alert('Quiz must have at least one Question/Answer Set.');
			}
			else
			{
				deleteQuesAns(_URL,Id,type,divId);
				window.location.reload(true);
			}
		}
		else			
			deleteQuesAns(_URL,Id,type,divId);	
	}
	window.top.initFaceBox(_URL);
}

function deleteQuesAns (_URL, quizId, quesId, pg, order, lastaction, from)
{
	var url		=	_URL + "ajax_functions/delete.php?type="+"quizquestion&id="+quesId;
	var req 			=	initRequest();
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				if (from=='modal') {
					window.top.closeFacebox();
				}
				getQuizQuesList(_URL, quizId, pg, order, lastaction);
			}
		}
	}
	req.open('GET', url, true); 
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.send(null); 
	return false; 
}

function showFormCheckError(err, id)
{
	alert(err);
	if (id!='') {
		document.getElementById(id).focus();
	}
	errflag	=	false;
}	

function addNewSchool(_URL, newVal, addKey)
{
	if (newVal==''){
		alert('Empty field!!!');
		return false;
	}
	else
	{
		var req	    =	GetXmlHttpObject();
		var url	       		=	_URL + "AJAX_FUNCTIONS/addGroupFilter.php?addKey=" + addKey + "&addVal=" + newVal;
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				if (req.responseText.match('failed')) {
					alert('Item Already exists');
				}
				else {
					document.getElementById('schoolList').innerHTML	=	req.responseText;
				}
				showHide('newSchool','saveSchool');
				window.top.initFaceBox(_URL);
			}
		}
		req.open("GET", url, true);
		req.send(null);
		return true;
	}
}

function showHide(Show, hide)
{
	document.getElementById(Show).className	=	'delvisible';
	document.getElementById(hide).className	=	'delhidden';
}

// Remove leading & trailing whitespaces
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { 
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function getBulkStudent(_URL,n)
{
	document.getElementById('addmore').innerHTML = '<a class="cancelButton" onclick="addOne('+ n +');">Add</a>';
	document.bulkRegister.num.value	=	n;
	var req	    =	GetXmlHttpObject();
	var url	       		=	_URL + "AJAX_FUNCTIONS/getBulkStudent.php?num="+n;
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			document.getElementById('bulkStudent').innerHTML	=	req.responseText;
		}
	}
	req.open("GET", url, true);
	req.send(null);
	return true;
}

function getHomePageHeader(_URL, pfile)
{
	var req	    =	GetXmlHttpObject();
	var url	    =	_URL + "AJAX_FUNCTIONS/getHomePageHeader.php?pfile="+encodeURIComponent(pfile);
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			document.getElementById('topHead').innerHTML	=	req.responseText;
			window.top.initFaceBox(_URL);


			$('#topHead a').bind('click', function() {

			if ($(this).attr('rel') != 'facebox') {
				var msg	=	'You are currently participating in a quiz. If you wish to view other questions while taking the quiz or navigate away from this page, you would have to start all over again. Would you want to leave the Quiz?';

		    if (window.top.document.getElementById('sponsored_warning') !=  undefined && window.top.document.getElementById('sponsored_warning') != null) {
				if (readCookie('FBQS') != null) 
				{
				    
					confirmation=confirm(msg);
					if(!confirmation) 
					{	return false;	}
				}
		    }			
			}			
			});

		}
	}
	req.open("GET", url, true);
	req.send(null);
	return true;
}

function getWhatYourFriendUpto(_URL, pfile)
{
	var req	    =	GetXmlHttpObject();
	var url	    =	_URL + "AJAX_FUNCTIONS/whatYourFriendUpto.php?pfile="+encodeURIComponent(pfile);
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			document.getElementById('whatYourFriendUpto').innerHTML	=	req.responseText;
			window.top.initFaceBox(_URL);
		}
	}
	req.open("GET", url, true);
	req.send(null);
	return true;
}

function showSubtTag(type, totalPages)
{   
	var curr		=	parseInt(document.getElementById('sh1').value);
	if (type.match('next') && curr<totalPages) {
		var ele		=	'subtag_'+curr;
		document.getElementById(ele).style.display 	= 'none';
		var ele		=	'subtag_'+(parseInt(curr)+1);
		document.getElementById(ele).style.display 	= 'block';
		document.getElementById('sh1').value		=	parseInt(curr)+1;
	}
	if (type.match('prev') && curr>1) {
		var ele		=	'subtag_'+curr;
		document.getElementById(ele).style.display 	= 'none';
		var ele		=	'subtag_'+(parseInt(curr)-1);
		document.getElementById(ele).style.display 	= 'block';
		document.getElementById('sh1').value		=	parseInt(curr)-1;
	}
}

function userSignIn(_URL)
{
	var email	=	trim(document.loginForm.username.value);
	var pass	=	trim(document.loginForm.password.value);
	
	if (!email){
		document.getElementById('errmsg').innerHTML	=	'  Please enter your email.';
		return false;
	}
	if(!checkEmail(email)){
		document.getElementById('errmsg').innerHTML	=	'  Please enter valid email.';
		return false;
	}
	if (!pass){
		document.getElementById('errmsg').innerHTML	=	'  Please enter your password.';
		return false;
	}
	return true;
}

function getCss(id, op)
{
	var ele	=	'awr'+id;
	if (op.match('in')){
		document.getElementById(ele).className	=	'HomePageTop arwmenu2';
	}
	else {
		document.getElementById(ele).className	=	'HomePageTop arwmenu1';
	}
}

function selectGroupTab(id)
{
	for (i=1; i<=7; i++)
	{
		liEle	=	'grp'+i;
		aEle	=	'grkln'+i;	
		boxEle	=	'grpBox'+i;

		if (parseInt(id)==7)
		{
			if (window.top.document.getElementById(liEle)!=null && window.top.document.getElementById(liEle)!='undefined')	
			{
				window.top.document.getElementById('grpExtra').style.display	=	'none';
			}
		}
		else
		{
			window.top.document.getElementById('grpExtra').style.display	=	'block';
		}

		if (i==parseInt(id))
		{
			if (window.top.document.getElementById(liEle)!=null && window.top.document.getElementById(liEle)!='undefined')
			{
				window.top.document.getElementById(liEle).className		=	'current';
				window.top.document.getElementById(aEle).className		=	'here';
				window.top.document.getElementById(boxEle).className	=	'delvisible';
			}
		}
		else
		{
			if (window.top.document.getElementById(liEle)!=null && window.top.document.getElementById(liEle)!='undefined')
			{
				window.top.document.getElementById(liEle).className		=	'';
				window.top.document.getElementById(aEle).className		=	'';
				window.top.document.getElementById(boxEle).className	=	'delhidden';
			}
		}	
	}
}

function getWaitCursor(_URL, style)
{
	var imgURL	=	window.top._IMAGE_URL;
	var msg		=	'<div '+ style +'><div>Please wait while loading...</div><br /><div><img src="'+imgURL+'loading.gif"></div></div>';
	return msg;
}

function getGroupTabSets(_URL, gid, pg, type, lastaction)
{
	var url			=	null;
	var ele			=	null;
	var waitboxStyle=	null;
	var	params		=	"gid=" + gid + "&pg=" + pg +"&lastaction=" + lastaction;
	switch(type)
	{
		case 'overmem':	url		=	_URL + "ajax_functions/getGroupMemberOverview.php";
						ele		=	'memOver';
						waitboxStyle=	'style="width:368px; height:240px; padding:70px 12px 12px 0px; text-align:center; font-weight:bold;"';
		break;
		case 'decks':	url	=	_URL + "ajax_functions/getGroupDecks.php";
						ele	=	'grpdecks';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'overdeck':	url	=	_URL + "ajax_functions/getGroupDeckOverview.php";
						ele	=	'overDecks';
						waitboxStyle=	'style="width:368px; height:240px; padding:70px 12px 12px 0px; text-align:center; font-weight:bold;"';
		break;
		case 'quizzes':	url	=	_URL + "ajax_functions/getGroupQuizzes.php";
						ele	=	'grpquizzes';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'members':	url	=	_URL + "ajax_functions/getGroupMembers.php";
						ele	=	'grpmembers';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'blogs':	url	=	_URL + "ajax_functions/getGroupBlogs.php";
						ele	=	'grpblogs';
						waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'admins':	url	=	_URL + "ajax_functions/getGroupAdmins.php";
						ele	=	'grpadmin';
						waitboxStyle=	'style="width:140px; height:70px; padding:12px 0px 0px 0px; text-align:left; font-weight:bold; font-size:11px;"';
		break;
		case 'documents':url=	_URL + "ajax_functions/getGroupDocuments.php";
						ele	=	'grpdocuments';
						waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
	}
	if (url!=null)
	{
		waitcursor		=	getWaitCursor(_URL, waitboxStyle);
		window.top.document.getElementById(ele).innerHTML	=	waitcursor;
		
		var req 		=	initRequest();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					switch (type)
					{
						case 'overmem':
						if (req.responseText!='') {
							var res	=	req.responseText.split('~~~###memnum###~~~');
							window.top.document.getElementById(ele).innerHTML	=	res[0];
							window.top.document.getElementById('memCnt').innerHTML	=	res[1];
						}
						break;
						case 'overdeck':
						if (req.responseText!='') {
							var res	=	req.responseText.split('~~~###decknum###~~~');
							window.top.document.getElementById(ele).innerHTML	=	res[0];
							window.top.document.getElementById('decknum').innerHTML	=	res[1];
						}
						break;
						default:
							window.top.document.getElementById(ele).innerHTML	=	req.responseText;
					}
					window.top.initFaceBox(_URL);
				} 
			}
		};	
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}

function getGroupDocuments(_URL, gid, pg, type, lastaction)
{
	var url			=	null;
	var ele			=	null;
	var waitboxStyle=	null;
	var	params		=	"gid=" + gid + "&pg=" + pg +"&lastaction=" + lastaction;
	
	url=	_URL + "ajax_functions/getGroupDocuments.php";
	ele	=	'grpdocuments';
	waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';	

	if (url!=null)
	{
		waitcursor		=	getWaitCursor(_URL, waitboxStyle);
		window.top.document.getElementById(ele).innerHTML	=	waitcursor;
		
		var req 		=	initRequest();
		req.open("POST", url, false);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		
		window.top.document.getElementById(ele).innerHTML	=	req.responseText;
		window.top.initFaceBox(_URL);
	}
}

function showgroups(id,action)
{
	if (action) {
		document.getElementById(id).style.visibility=	'visible';
	}
	else{
		document.getElementById(id).style.visibility=	'hidden';
	}					
					
}

function getAllGroupTabConatin(_URL, gid, lastaction)
{
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'overdeck', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'overmem', ''+lastaction+'');
	groupForumResponses(''+_URL+'', ''+gid+'', 1, 'load', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'decks', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'quizzes', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'members', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'blogs', ''+lastaction+'');
	getGroupTabSets(''+_URL+'', ''+gid+'', 1, 'documents', ''+lastaction+'');
}

function showCompleteBlog(_URL, bid)
{
	var ele	=	'blog'+bid;
	document.getElementById('grpblogs').innerHTML	=	document.getElementById(ele).innerHTML;
	window.top.initFaceBox(_URL);
}

function discussionText(flag, ele)
{
	var val	=	trim(window.top.document.getElementById(ele).value);
	if (flag=='cleartxt')
	{
		if(val=='Join the Discussion. Write Something...')
		{
			window.top.document.getElementById(ele).value	=	'';
		}
	}
	else
	{
		if(val=='')
		{
			window.top.document.getElementById(ele).value	=	'Join the Discussion. Write Something...';
		}
	}
}

function updateMessageStatus(_URL, msgId, status)
{
	var url	    =	_URL + "ajax_functions/updateMessageStatus.php?messageId="+msgId+"&Status="+status;
	var req 	=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			window.location.reload();
			if (req.status == 200)
			{
				incrementCount("inboxCount", -1);
				incrementCount("memberMessageCount", -1);
				incrementCount("mCount", -1);
				incrementCount("msgCount", -1);
				if (parseInt(document.getElementById("mCount").innerHTML)==0){
					document.getElementById("mzerocount").innerHTML	=	"<hr class='friendRequestSeparator'/><br />You don't have any messages.";
				}
				document.getElementById("memberMessageActivityIndicator_" + msgId).style.display =	'none';
				document.getElementById("message_" + Id).innerHTML	=	req.responseText;
				document.getElementById("message_" + Id).style.display 				=	'none';
				var cnt	=	document.getElementById('msgCount').innerHTML;
				if (parseInt(cnt)==1){
					document.getElementById('msgs').innerHTML = 'Message';
				}
				window.top.initFaceBox(_URL);
			} 
		}
	};	
	req.open('POST', url, true); 
	req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
	req.send(null); 
	document.getElementById("memberMessageActivityIndicator_" + msgId).style.display =	'inline';
	return false; 
}

function showModalDialog(urlLink, Title)
{
	
	tb_show(""+Title+"",""+urlLink+"", "");
}

function gotoBlog(_URL, id, from, pg)
{
	switch(from)
	{
		case 'profile'	:	window.top.selectMemberTab(5);
							window.top.getMemberTabSets(''+_URL+'', ''+id+'', ''+pg+'', 'blogs', 'get');
		break;
		default			:	window.top.selectGroupTab(5);
							window.top.getGroupTabSets(''+_URL+'', ''+id+'', ''+pg+'', 'blogs', 'get');
		break;
	}
}

function flashcardQuestions(_URL, deck_id, fcid, pg)
{
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getFlashcardQuestions.php";

	var params = "deck_id=" + deck_id+'&fcid='+fcid+'&pg='+pg;

	req.onreadystatechange = function()
	{
		if(req.readyState==4) {
			if (req.status == 200)
			{
				if (req.responseText == 'error')
				{
					alert('Error: Invalid parameters.');
					window.location.href = _URL + "404.php";					
				}
				window.top.document.getElementById('flashQuestions').innerHTML	=	req.responseText;	
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function getDeckHistory(_URL, deckId, pg, lastaction)
{
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getDeckHistory.php";
	var params = "deck_id="+deckId+'&pg='+pg+'&action='+lastaction;
	var waitboxStyle	=	'style="width:400px; height:200px; padding:60px 0px 0px 0px; text-align:center; font-weight:bold;"';

	waitcursor			=	getWaitCursor(_URL, waitboxStyle);
	document.getElementById('getHistory').innerHTML	=	waitcursor;

	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				if (req.responseText == 'error')
				{
					alert('Error: Invalid parameters.');
					window.location.href = _URL + "404.php";					
				}

				document.getElementById('getHistory').innerHTML	=	req.responseText;
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function getAvgTime()
{
	var avgTime		=	'';
	var correct		=	parseInt(document.getElementById('correct').value);
	var totalTime	=	document.getElementById('txtTime').innerHTML;

	if (correct>0)
		avgTime		=	Math.floor(timeToSeconds(totalTime)/correct);
	else
		avgTime		=	totalTime;
	
	obj	=	secondsToTime(avgTime);
	var	avgTime		=	obj.h+':'+obj.m+':'+obj.s;

	if (avgTime.indexOf("NaN")!=-1)
		avgTime	=	'00:00:00'
	document.getElementById('avgTime').innerHTML	=	avgTime;
}

function secondsToTime(secs)
{
    var hours = Math.floor(secs / (60 * 60));
    var divisor_for_minutes = secs % (60 * 60);
    var minutes = Math.floor(divisor_for_minutes / 60);
    var divisor_for_seconds = divisor_for_minutes % 60;
    var seconds = Math.ceil(divisor_for_seconds);
	
	if(secs <= 9)
		var hours	=	'0' + hours;
	
	if(mins < 9)
		var minutes	=	'0' + minutes;
	
	if(hr < 9)
		var seconds	=	'0' + seconds;

	var obj = {
        "h": hours,
        "m": minutes,
        "s": seconds
    };
    return obj;
}

function timeToSeconds(time)
{
	var	totalTime	=	0;
	var	tTime		=	time.split(":");
	
	if (tTime.length>2)
	{
		totalTime	=	parseInt(totalTime) + parseInt(tTime[0]*3600);
		totalTime	=	parseInt(totalTime) + parseInt(tTime[1]*60);
		totalTime	=	parseInt(totalTime) + parseInt(tTime[2]);
	}
	else
	{
		totalTime	=	parseInt(totalTime) + parseInt(tTime[0]*60);
		totalTime	=	parseInt(totalTime) + parseInt(tTime[1]);
	}
	
	return totalTime;
}

function formatToggle(formatType, type)
{
	var ele		=	((type=='question')?'q':'a');
	var	divId	=	ele+formatType;
	if (formatType!='')	
	{
		document.getElementById(ele+'format').value			= 	formatType;
		switch(formatType)
		{
			case 'text':	document.getElementById(ele+'text').className			=	'delvisible';
							document.getElementById(ele+'audio').className			=	'delhidden';
							document.getElementById(ele+'video').className			=	'delhidden';
							document.getElementById(ele+'photo').className			=	'delhidden';
							document.getElementById(ele+'math').className			=	'delhidden';
							document.getElementById(type+'Math').className			=	'delhidden';

			break;
			case 'audio':	document.getElementById(ele+'text').className			=	'delhidden';
							document.getElementById(ele+'audio').className			=	'delvisible';
							document.getElementById(ele+'video').className			=	'delhidden';
							document.getElementById(ele+'photo').className			=	'delhidden';
							document.getElementById(ele+'math').className			=	'delhidden';
							document.getElementById(type+'Math').className			=	'delhidden';

			break;
			case 'video':	document.getElementById(ele+'text').className			=	'delhidden';
							document.getElementById(ele+'audio').className			=	'delhidden';
							document.getElementById(ele+'video').className			=	'delvisible';
							document.getElementById(ele+'photo').className			=	'delhidden';
							document.getElementById(ele+'math').className			=	'delhidden';
							document.getElementById(type+'Math').className			=	'delhidden';

			break;
			case 'photo':	document.getElementById(ele+'text').className			=	'delhidden';
							document.getElementById(ele+'audio').className			=	'delhidden';
							document.getElementById(ele+'video').className			=	'delhidden';
							document.getElementById(ele+'photo').className			=	'delvisible';
							document.getElementById(ele+'math').className			=	'delhidden';
							document.getElementById(type+'Math').className			=	'delhidden';

			break;
			case 'math':	document.getElementById(ele+'text').className			=	'delhidden';
							document.getElementById(ele+'audio').className			=	'delhidden';
							document.getElementById(ele+'video').className			=	'delhidden';
							document.getElementById(ele+'photo').className			=	'delhidden';
							document.getElementById(ele+'math').className			=	'delvisible';
							document.getElementById(type+'Math').className			=	'delvisible';
			break;
		}
	}
}

function cropUploadImage(_URL, imgType)
{
	document.getElementById('btnSubmit').disabled		= 	true;
	document.getElementById('loading').style.display=	'block';
	
	var imageWidth	=	document.getElementById('imageWidth').value;
	var imageHeight	=	document.getElementById('imageHeight').value;
	var fileName	=	document.getElementById('fileName').value;
	var cropHeight	=	document.getElementById('cropHeight').value;
	var cropWidth	=	document.getElementById('cropWidth').value;
	var cropY		=	document.getElementById('cropY').value;
	var cropX		=	document.getElementById('cropX').value;	
	
	var params	=	'imgType='+imgType+'&imageWidth='+imageWidth+'&imageHeight='+imageHeight+'&fileName='+fileName+'&cropHeight='+cropHeight+'&cropWidth='+cropWidth+'&cropY='+cropY+'&cropX='+cropX;
	
	var req 	=	initRequest();
	var url		=	_URL + "ajax_functions/imageUploader.php"
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			switch(imgType)
			{
				case 'profilePhoto':	window.top.document.getElementById('mainPPicture').innerHTML	= 	req.responseText;
										window.top.document.getElementById('mainPPicture2').innerHTML	= 	req.responseText;
										window.top.closeFacebox();
										window.top.initFaceBox(_URL);
				break;
				default:				var data	= req.responseText.split("~~~");
										window.top.document.getElementById('imageContainer').innerHTML	= 	data[0];
										window.top.document.getElementById('imgPath').value		=	data[1];
										window.top.closeFacebox();
										window.top.initFaceBox(_URL);
				break;
			}
		}
	};
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function setClickEvent()
{
	levelClicked	=	true;
}

function loadDocument(_URL, id, from, action)
{
	var pgToload	=	1;
	if (window.top.document.getElementById('blogpg')!=null && window.top.document.getElementById('blogpg')!='undefined')
	{	pgToload	=	window.top.document.getElementById('blogpg').value;	}
	
	if (action!='edit')
	{	pgToload	=	1;	}
	
	if (from.match('group'))
	{
		selectGroupTab(5);
		getGroupTabSets(''+_URL+'', ''+id+'', pgToload, 'blogs', 'add');
	}
	else
	{
		selectMemberTab(5);
		getMemberTabSets(''+_URL+'', ''+id+'', pgToload, 'blogs', 'add');
	}

	var action	=	window.top.document.getElementById('curBlog').value;
	if (action.match('add'))
	{
		var num	=	window.top.document.getElementById('blognum').innerHTML;
		window.top.document.getElementById('blognum').innerHTML	=	parseInt(num) + 1;
	}
	window.top.closeFacebox();
	window.top.initFaceBox(_URL);
}

function sendMessage(_URL)
{
	var req 	=	GetXmlHttpObject();
	var url		=	_URL + "AJAX_FUNCTIONS/sendMessage.php";
	
	document.getElementById('loading').className	=	'delvisible';
	document.getElementById('submit').disabled	= true;

	var page_action		=	document.getElementById('page_action').value;
	var params 			=	"page_action="+page_action;
	
	if (page_action.match('group'))
	{
		var gid	=	document.getElementById('gid').value;
		params	=	params+'&gid='+gid;
	}
	var mid		=	document.getElementById('member_id_to').value;
	var txtMsg	=	 encodeURIComponent(document.getElementById('message_text').value);
	params		=	params+"&mid="+mid+'&message_text='+txtMsg;

	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			document.getElementById('loading').className	=	'delhidden';
			document.getElementById('submit').disabled		= 	false;
			if ((req.responseText)=='success')
			{	window.top.closeFacebox();	}
			else
			{	document.getElementById('msgerr').innerHTML	=	'Error: Invalid parameters.';	}
			window.top.initFaceBox(_URL);
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}


function getStockImages(_URL, filter, pg, _IMAGES)
{
	document.getElementById('stockImgs').innerHTML	=	'<div style="width:430px; height:100px; font-weight:bold; text-align:center;"><div>Please wait while loading...</div><br /><div><img src="'+_IMAGES+'loading.gif"></div></div>';

	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getStockImages.php";
	var params = 'filter='+filter+'&pg='+pg;
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				document.getElementById('stockImgs').innerHTML	=	req.responseText;
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function setAndUseStockImage(_URL, id, imgPath, imgURL)
{
	setImg(id, imgPath);
	useStockImage(_URL,imgURL);
}

function setImg(id, imgPath)
{
	document.getElementById('selImg').value	=	imgPath;
	var imgCnt	=	document.getElementById('imgCount').value;
	for (i=1; i<=imgCnt; i++)
	{	
		var ele	=	'stk_img_'+i;
		document.getElementById(ele).className	=	'StockImageBoxGray';	
	}
	document.getElementById(id).className	=	'StockImageBoxBlue';
}

function useStockImage(_URL, imgURL)
{
	if (trim(document.getElementById('selImg').value)=='')		
	{
		alert('Please select the an image.');
		return false;
	}
	else
	{
		var imgType		=	document.getElementById('imgType').value+'Stock';
		var fileName	=	document.getElementById('selImg').value;
		
		document.getElementById('stockImgs').innerHTML	=	'<div style="width:430px; height:100px; font-weight:bold; text-align:center;"><div>Please wait while loading...</div><br /><div><img src="'+imgURL+'loading.gif"></div></div>';
		var req =	GetXmlHttpObject();
		var url	=	_URL + "AJAX_FUNCTIONS/imageUploader.php";
		var params = 'imgType='+imgType+'&fileName='+fileName;
		req.onreadystatechange = function()
		{
			if(req.readyState==4) 
			{
				if (req.status == 200)
				{
					if(req.responseText=='failed')
					{
						alert('Unable to upload this stock image!!! Please try again.');	
					}
					else
					{
						var cat	= req.responseText.split("~~~");
						window.top.document.getElementById('imageContainer').innerHTML	= 	cat[0];
						window.top.document.getElementById('imgPath').value				=	cat[1];
						window.top.closeFacebox();
						window.top.initFaceBox(_URL);
					}
				}
			}
		}
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}


function submitContestant(_URL)
{
	document.getElementById('Loading').style.display		=	'block';
	
	var email		=	(document.getElementById('email')!=null && document.getElementById('email')!='undefined')?encodeURIComponent(document.getElementById('email').value):'';
	var contestID	=	(document.getElementById('contestID')!=null && document.getElementById('contestID')!='undefined')?encodeURIComponent(document.getElementById('contestID').value):'';
	var payRequired	=	(document.getElementById('payRequired')!=null && document.getElementById('payRequired')!='undefined')?encodeURIComponent(document.getElementById('payRequired').value):'';
	var name		=	(document.getElementById('name')!=null && document.getElementById('name')!='undefined')?encodeURIComponent(document.getElementById('name').value):'';
	var dob			=	(document.getElementById('dob')!=null && document.getElementById('dob')!='undefined')?encodeURIComponent(document.getElementById('dob').value):'';
	var streetAdd	=	(document.getElementById('streetAdd')!=null && document.getElementById('streetAdd')!='undefined')?encodeURIComponent(document.getElementById('streetAdd').value):'';
	var city		=	(document.getElementById('city')!=null && document.getElementById('city')!='undefined')?encodeURIComponent(document.getElementById('city').value):'';
	var State		=	(document.getElementById('State')!=null && document.getElementById('State')!='undefined')?encodeURIComponent(document.getElementById('State').value):'';
	var zip			=	(document.getElementById('zip')!=null && document.getElementById('zip')!='undefined')?encodeURIComponent(document.getElementById('zip').value):'';
	var phoneno		=	(document.getElementById('phoneno')!=null && document.getElementById('phoneno')!='undefined')?(document.getElementById('phoneno').value).replace(/[^0-9]+/g,''):'';
	var school		=	(document.getElementById('school')!=null && document.getElementById('school')!='undefined')?encodeURIComponent(document.getElementById('school').value):'';
	var deckUrl		=	(document.getElementById('deckUrl')!=null && document.getElementById('deckUrl')!='undefined')?encodeURIComponent(document.getElementById('deckUrl').value):'';

	var degreeId	=	(document.getElementById('degreeId')!=null && document.getElementById('degreeId')!='undefined')?encodeURIComponent(document.getElementById('degreeId').value):'';
	var highEducation=	(document.getElementById('highEducation')!=null && document.getElementById('highEducation')!='undefined')?encodeURIComponent(document.getElementById('highEducation').value):'';
	var yearGrad	=	(document.getElementById('yearGrad')!=null && document.getElementById('yearGrad')!='undefined')?encodeURIComponent(document.getElementById('yearGrad').value):'';
	var gpa			=	(document.getElementById('gpa')!=null && document.getElementById('gpa')!='undefined')?encodeURIComponent(document.getElementById('gpa').value):'';
	
	

	studCategory	=	'';
	if (document.getElementsByName('studCategory')!=null && document.getElementsByName('studCategory')!='undefined')
	{
		var len		=	document.getElementsByName('studCategory').length;
		if (len>0)
		{
			for (var i=0; i<3; i++) 
			{
				if (document.formRegisContest.elements['stc'+i].checked)
				{
					var studCategory=	encodeURIComponent(document.formRegisContest.elements['stc'+i].value);
					break;
				}
				else
					continue;
			}
		}
	}
	
	var optText		=	(document.getElementById('optText')!=null && document.getElementById('optText')!='undefined')?encodeURIComponent(document.formRegisContest.elements['optText'].checked):'';
	
	var params = 'email='+email+'&contestID='+contestID+'&name='+name+'&dob='+dob+'&streetAdd='+streetAdd+'&city='+city+'&State='+State+'&zip='+zip+'&phoneno='+phoneno+'&school='+school+'&deckUrl='+deckUrl+'&studCategory='+studCategory+'&optText='+optText+'&degreeId='+degreeId+'&highEducation='+highEducation+'&yearGrad='+yearGrad+'&gpa='+gpa;
	if (payRequired!='')
		params = params+'&payRequired='+payRequired;

	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/submitContestant.php";
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				switch(req.responseText)
				{
					case 'payreq'	:	window.top.openFaceBox(_URL+'popBox.php?enc=n&height=300&width=400&url=popContestSubs.php?cid='+contestID);
					break;
					case 'success'	:	window.top.openFaceBox(_URL+'contestRegistration.php?cid='+contestID+'&open=Y');
					break;
					case 'error'	:	document.getElementById('modalerr').innerHTML		=	'Error: Invalid parameter.';
					break;
					default			:	document.getElementById('modalerr').innerHTML		=	req.responseText;
										document.getElementById('Loading').style.display	=	'none';
				}
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function getFlashCardList(_URL, deckId, pg, order, lastaction)
{	
	var imgURL	=	window.top._IMAGE_URL;
	document.getElementById('cardList').innerHTML	=	'';
	document.getElementById('cardList').innerHTML	=	'<div align="center" style="width:980px;text-align:center;"><img src="' + imgURL + 'loading.gif" border="0" style="margin:50px 0px;" /> <br /><br />Please wait while processing...</div>';

	var	params		=	"deck_id=" + deckId + "&pg=" + pg +"&lastaction=" + lastaction+'&order='+order;
	
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getFlashCardList.php";
		
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				document.getElementById('cardList').innerHTML		=	req.responseText;
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function getQuizQuesList(_URL, quizId, pg, order, lastaction)
{	
	var imgURL	=	window.top._IMAGE_URL;
	document.getElementById('cardList').innerHTML	=	'';
	document.getElementById('cardList').innerHTML	=	'<div align="center" style="width:980px;text-align:center;"><img src="' + imgURL + 'loading.gif" border="0" style="margin:50px 0px;" /> <br /><br />Please wait while processing...</div>';

	var	params		=	"quizId=" + quizId + "&pg=" + pg +"&lastaction=" + lastaction+'&order='+order;
	
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getQuizQuesList.php";
		
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				document.getElementById('cardList').innerHTML		=	req.responseText;
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function showHide3rdSide()
{
	closeEditor();
	var vis		=	document.getElementById('sideVisibility').value;
	
	if (vis==0)
	{
		document.getElementById('sideVisibility').value			=	1;
		document.getElementById('blk3rdSide').style.display		=	'block';
		document.getElementById('blk3rdSide').style.visibility	=	'visible';
		document.getElementById('thirdSidearw').className		=	'crtDeckNoRepeat pop3rdOpen';
		window.top.doIframe(600);
	}
	else
	{
		document.getElementById('sideVisibility').value			=	0;
		document.getElementById('blk3rdSide').style.display		=	'none';
		document.getElementById('blk3rdSide').style.visibility	=	'hidden';
		document.getElementById('thirdSidearw').className		=	'crtDeckNoRepeat pop3rdClose';
		window.top.doIframe(410);
	}	
}

function deleteFlashCard(_URL, deckId, fcid, pg, order, lastaction, from)
{
	var imgURL	=	window.top._IMAGE_URL;
	document.getElementById('cardList').innerHTML	=	'';
	document.getElementById('cardList').innerHTML	=	'<div align="center" style="width:980px;text-align:center;"><img src="' + imgURL + 'loading.gif" border="0" style="margin:50px 0px;" /> <br /><br />Please wait while processing...</div>';

	var	params		=	'deck_id='+deckId+'&fcid='+fcid+'&type=delete&pg='+pg+'&order='+order+'&lastaction='+lastaction;
	
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/updateFlashcard.php";
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				if (req.responseText=='Success')
				{
					if (from=='modal') {
						window.top.closeFacebox();
					}
					getFlashCardList(_URL, deckId, pg, order, lastaction);
				}
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}


function setFlashFormat(action, format)
{
	switch(action)
	{
		case 'question'	:	showHideFlashFormat('Q', format);
		break;
		
		case 'answer'	:	showHideFlashFormat('A', format);
		break;
		
		case '3rdSide'	:	showHideFlashFormat('T', format);
		break;
	}
}

function showHideFlashFormat(preFix, format)
{
	switch(format)
	{
		case'text':	
				document.getElementById(preFix+'Text').style.visibility		=	'visible';
				document.getElementById(preFix+'Video').style.visibility	=	'hidden';
				document.getElementById(preFix+'Audio').style.visibility	=	'hidden';
				document.getElementById(preFix+'Photo').style.visibility	=	'hidden';
				document.getElementById(preFix+'Text').style.display		=	'';
				document.getElementById(preFix+'Video').style.display		=	'none';
				document.getElementById(preFix+'Audio').style.display		=	'none';
				document.getElementById(preFix+'Photo').style.display		=	'none';
				
				if (preFix!='T') {
					document.getElementById(preFix+'Math').style.visibility		=	'hidden';
					document.getElementById(preFix+'Math').style.display		=	'none';
				}
		break;
		case'audio':	
				document.getElementById(preFix+'Text').style.visibility		=	'hidden';
				document.getElementById(preFix+'Video').style.visibility	=	'hidden';
				document.getElementById(preFix+'Audio').style.visibility	=	'visible';
				document.getElementById(preFix+'Photo').style.visibility	=	'hidden';
				document.getElementById(preFix+'Text').style.display		=	'none';
				document.getElementById(preFix+'Video').style.display		=	'none';
				document.getElementById(preFix+'Audio').style.display		=	'';
				document.getElementById(preFix+'Photo').style.display		=	'none';

				if (preFix!='T') {
					document.getElementById(preFix+'Math').style.visibility		=	'hidden';
					document.getElementById(preFix+'Math').style.display		=	'none';
				}
		break;
		case'video':	
				document.getElementById(preFix+'Text').style.visibility		=	'hidden';
				document.getElementById(preFix+'Video').style.visibility	=	'visible';
				document.getElementById(preFix+'Audio').style.visibility	=	'hidden';
				document.getElementById(preFix+'Photo').style.visibility	=	'hidden';
				document.getElementById(preFix+'Text').style.display		=	'none';
				document.getElementById(preFix+'Video').style.display		=	'';
				document.getElementById(preFix+'Audio').style.display		=	'none';
				document.getElementById(preFix+'Photo').style.display		=	'none';

				if (preFix!='T') {
					document.getElementById(preFix+'Math').style.visibility		=	'hidden';
					document.getElementById(preFix+'Math').style.display		=	'none';
				}
		break;
		case'math':	
				document.getElementById(preFix+'Text').style.visibility		=	'hidden';
				document.getElementById(preFix+'Video').style.visibility	=	'hidden';
				document.getElementById(preFix+'Audio').style.visibility	=	'hidden';
				document.getElementById(preFix+'Photo').style.visibility	=	'hidden';
				document.getElementById(preFix+'Text').style.display		=	'none';
				document.getElementById(preFix+'Video').style.display		=	'none';
				document.getElementById(preFix+'Audio').style.display		=	'none';
				document.getElementById(preFix+'Photo').style.display		=	'none';

				if (preFix!='T') {
					document.getElementById(preFix+'Math').style.visibility		=	'visible';
					document.getElementById(preFix+'Math').style.display		=	'';
				}
	break;
		case'photo':	
				document.getElementById(preFix+'Text').style.visibility		=	'hidden';
				document.getElementById(preFix+'Video').style.visibility	=	'hidden';
				document.getElementById(preFix+'Audio').style.visibility	=	'hidden';
				document.getElementById(preFix+'Photo').style.visibility	=	'visible';
				document.getElementById(preFix+'Text').style.display		=	'none';
				document.getElementById(preFix+'Video').style.display		=	'none';
				document.getElementById(preFix+'Audio').style.display		=	'none';
				document.getElementById(preFix+'Photo').style.display		=	'';

				if (preFix!='T') {
					document.getElementById(preFix+'Math').style.visibility		=	'hidden';
					document.getElementById(preFix+'Math').style.display		=	'none';
				}
		break;
	}
	document.getElementById(preFix+'setFmt').value				=	format;
}

function openFlashCardLink(urlToOpen)
{
	closeEditor();
	// Update Parent with Current modal content
	window.top.document.getElementById('cardCountTmp').value		=	window.top.document.getElementById('cardCount').value;
	window.top.document.getElementById('page_actionTmp').value		=	document.getElementById('page_action').value;
	window.top.document.getElementById('deck_idTmp').value			=	document.getElementById('deck_id').value;
	window.top.document.getElementById('posTmp').value				=	document.getElementById('pos').value;
	window.top.document.getElementById('QsetFmtTmp').value			=	document.getElementById('QsetFmt').value;
	window.top.document.getElementById('AsetFmtTmp').value			=	document.getElementById('AsetFmt').value;
	window.top.document.getElementById('TsetFmtTmp').value			=	document.getElementById('TsetFmt').value;
	window.top.document.getElementById('mfrontTmp').value			=	document.getElementById('mfront').value;
	window.top.document.getElementById('mbackTmp').value			=	document.getElementById('mback').value;
	window.top.document.getElementById('m3rdsideTmp').value			=	document.getElementById('m3rdside').value;
	window.top.document.getElementById('globalTagsTmp').value		=	document.getElementById('globalTags').value;
	window.top.document.getElementById('fronttextTmp').value		=	document.frmFlashcard.elements['fronttext'].value;
	window.top.document.getElementById('QVideoTexTTmp').value		=	document.frmFlashcard.elements['QVideoTexT'].value;
	window.top.document.getElementById('QAudioTexTTmp').value		=	document.frmFlashcard.elements['QAudioTexT'].value;
	window.top.document.getElementById('QPhotoTexTTmp').value		=	document.frmFlashcard.elements['QPhotoTexT'].value;
	window.top.document.getElementById('txt_QMathTmp').value		=	document.getElementById('txt_QMath').value;
	window.top.document.getElementById('backtextTmp').value			=	document.frmFlashcard.elements['backtext'].value;
	window.top.document.getElementById('AVideoTexTTmp').value		=	document.frmFlashcard.elements['AVideoTexT'].value;
	window.top.document.getElementById('AAudioTexTTmp').value		=	document.frmFlashcard.elements['AAudioTexT'].value;
	window.top.document.getElementById('APhotoTexTTmp').value		=	document.frmFlashcard.elements['APhotoTexT'].value;
	window.top.document.getElementById('txt_AMathTmp').value		=	document.getElementById('txt_AMath').value;
	window.top.document.getElementById('thirdtextTmp').value		=	document.frmFlashcard.elements['thirdtext'].value;
	window.top.document.getElementById('TVideoTexTTmp').value		=	document.frmFlashcard.elements['TVideoTexT'].value;
	window.top.document.getElementById('TAudioTexTTmp').value		=	document.frmFlashcard.elements['TAudioTexT'].value;
	window.top.document.getElementById('TPhotoTexTTmp').value		=	document.frmFlashcard.elements['TPhotoTexT'].value;

	if(document.getElementById('page_action').value=='edit') {
		window.top.document.getElementById('fcidTmp').value		=	document.getElementById('fcid').value;
	}
	window.top.popCntFlag	=	true;
	// Open new Modal Operation
	window.top.openFaceBox(urlToOpen);
}

function setContentAfterUpload()
{
	var url					=	window.top.document.getElementById('URL').value;
	var QsetFmtTmp			=	window.top.document.getElementById('QsetFmtTmp').value;
	var AsetFmtTmp			=	window.top.document.getElementById('AsetFmtTmp').value;
	var TsetFmtTmp			=	window.top.document.getElementById('TsetFmtTmp').value;
	var mfrontTmp			=	window.top.document.getElementById('mfrontTmp').value;
	var mbackTmp			=	window.top.document.getElementById('mbackTmp').value;
	var m3rdsideTmp			=	window.top.document.getElementById('m3rdsideTmp').value;
	var globalTagsTmp		=	window.top.document.getElementById('globalTagsTmp').value;

	var fronttextTmp		=	window.top.document.getElementById('fronttextTmp').value;

	var QVideoTexTTmp		=	window.top.document.getElementById('QVideoTexTTmp').value;
	var QAudioTexTTmp		=	window.top.document.getElementById('QAudioTexTTmp').value;
	var QPhotoTexTTmp		=	window.top.document.getElementById('QPhotoTexTTmp').value;

	var txt_QMathTmp		=	window.top.document.getElementById('txt_QMathTmp').value;

	var backtextTmp			=	window.top.document.getElementById('backtextTmp').value;
	var AVideoTexTTmp		=	window.top.document.getElementById('AVideoTexTTmp').value;
	var AAudioTexTTmp		=	window.top.document.getElementById('AAudioTexTTmp').value;
	var APhotoTexTTmp		=	window.top.document.getElementById('APhotoTexTTmp').value;

	var txt_AMathTmp		=	window.top.document.getElementById('txt_AMathTmp').value;

	var thirdtextTmp		=	window.top.document.getElementById('thirdtextTmp').value;
	var TVideoTexTTmp		=	window.top.document.getElementById('TVideoTexTTmp').value;
	var TAudioTexTTmp		=	window.top.document.getElementById('TAudioTexTTmp').value;
	var TPhotoTexTTmp		=	window.top.document.getElementById('TPhotoTexTTmp').value;
	
	switch(QsetFmtTmp)
	{
		case 'video':	document.getElementById('QVideo').innerHTML	= window.top.document.getElementById('QVideoTemp').innerHTML;
						document.frmFlashcard.Qformat[2].selected	=	'1';
						setFlashFormat('question', 'video');
		break;
		case 'audio':	document.getElementById('QAudio').innerHTML	= window.top.document.getElementById('QAudioTemp').innerHTML;
						document.frmFlashcard.Qformat[1].selected	=	'1';
						setFlashFormat('question', 'audio');
		break;
		case 'math'	:	
						document.getElementById('QMath').innerHTML		=	"<iframe id=\"QMath\" src=\""+txt_QMathTmp+"\"  width=\"415\" align=\"middle\" height=\"145\" marginwidth=\"50%\" style=\"align:center;\" frameborder=\"0\"></iframe><br><a onclick=\"closeEditor();openFlashCardLink('"+url+"popBox.php?enc=n&height=338&width=520&url=popMath.php?formatType=math&divID1=QFrameMath&divID2=txt_QMathTmp&from=question');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Equation</a>";
						document.frmFlashcard.Qformat[4].selected	=	'1';
						setFlashFormat('question', 'math');
		break;
		case 'photo':	document.getElementById('QPhoto').innerHTML	= window.top.document.getElementById('QPhotoTemp').innerHTML;
						document.frmFlashcard.Qformat[3].selected	=	'1';
						setFlashFormat('question', 'photo');
		break;
		default		:	document.frmFlashcard.Qformat[0].selected	=	'1';
						setFlashFormat('question', 'text');
	}	
	switch(AsetFmtTmp)
	{
		case 'video':	document.getElementById('AVideo').innerHTML	= window.top.document.getElementById('AVideoTemp').innerHTML;
						document.frmFlashcard.Aformat[2].selected	=	'1';
						setFlashFormat('answer', 'video');
		break;
		case 'audio':	document.getElementById('AAudio').innerHTML	= window.top.document.getElementById('AAudioTemp').innerHTML;
						document.frmFlashcard.Aformat[1].selected	=	'1';
						setFlashFormat('answer', 'audio');
		break;
		case 'math'	:	document.getElementById('AMath').innerHTML		=	"<iframe id=\"AMath\" src=\""+txt_AMathTmp+"\"  width=\"415\" align=\"middle\" height=\"145\" marginwidth=\"50%\" style=\"align:center;\" frameborder=\"0\"></iframe><br><a onclick=\"closeEditor();openFlashCardLink('"+url+"popBox.php?enc=n&height=338&width=520&url=popMath.php?formatType=math&divID1=AFrameMath&divID2=txt_AMathTmp&from=answer');\" rel=\"facebox\" href=\"javascript:void(0);\">Change Equation</a>";
						document.frmFlashcard.Aformat[4].selected	=	'1';
						setFlashFormat('answer', 'math');
		break;
		case 'photo':	document.getElementById('APhoto').innerHTML	= window.top.document.getElementById('APhotoTemp').innerHTML;
						document.frmFlashcard.Aformat[3].selected	=	'1';
						setFlashFormat('answer', 'photo');
		break;
		default		:	document.frmFlashcard.Aformat[0].selected	=	'1';
						setFlashFormat('answer', 'text');
	}	
	switch(TsetFmtTmp)
	{
		case 'video':	document.getElementById('TVideo').innerHTML	= window.top.document.getElementById('TVideoTemp').innerHTML;
						document.frmFlashcard.Tformat[2].selected	=	'1';
						setFlashFormat('3rdSide', 'video');
		break;
		case 'audio':	document.getElementById('TAudio').innerHTML	= window.top.document.getElementById('TAudioTemp').innerHTML;
						document.frmFlashcard.Tformat[1].selected	=	'1';
						setFlashFormat('3rdSide', 'audio');
		break;
		case 'math'	:	document.frmFlashcard.Tformat[4].selected	=	'1';
						setFlashFormat('3rdSide', 'math');
		break;
		case 'photo':	document.getElementById('TPhoto').innerHTML	= window.top.document.getElementById('TPhotoTemp').innerHTML;
						document.frmFlashcard.Tformat[3].selected	=	'1';
						setFlashFormat('3rdSide', 'photo');
		break;
		default		:	document.frmFlashcard.Tformat[0].selected	=	'1';
						setFlashFormat('3rdSide', 'text');
	}	
	
	document.getElementById('QsetFmt').value			=	QsetFmtTmp;
	document.getElementById('AsetFmt').value			=	AsetFmtTmp;
	document.getElementById('TsetFmt').value			=	TsetFmtTmp;
	document.getElementById('mfront').value				=	mfrontTmp;
	document.getElementById('mback').value				=	mbackTmp;
	document.getElementById('m3rdside').value			=	m3rdsideTmp;
	document.getElementById('globalTags').value			=	globalTagsTmp;

	document.getElementById('fronttext').innerHTML		=	fronttextTmp;
	document.frmFlashcard.elements['fronttext'].value	=	fronttextTmp;

	document.frmFlashcard.elements['QVideoTexT'].value	=	QVideoTexTTmp;
	document.frmFlashcard.elements['QAudioTexT'].value	=	QAudioTexTTmp;
	document.frmFlashcard.elements['QPhotoTexT'].value	=	QPhotoTexTTmp;

	document.getElementById('txt_QMath').value			=	txt_QMathTmp;

	document.getElementById('backtext').innerHTML		=	backtextTmp;
	document.frmFlashcard.elements['backtext'].value	=	backtextTmp;
	document.frmFlashcard.elements['AVideoTexT'].value	=	AVideoTexTTmp;
	document.frmFlashcard.elements['AAudioTexT'].value	=	AAudioTexTTmp;
	document.frmFlashcard.elements['APhotoTexT'].value	=	APhotoTexTTmp;
	
	document.getElementById('txt_AMath').value			=	txt_AMathTmp;

	document.getElementById('thirdtext').innerHTML		=	thirdtextTmp;
	document.frmFlashcard.elements['thirdtext'].value	=	thirdtextTmp;
	document.frmFlashcard.elements['TVideoTexT'].value	=	TVideoTexTTmp;
	document.frmFlashcard.elements['TAudioTexT'].value	=	TAudioTexTTmp;
	document.frmFlashcard.elements['TPhotoTexT'].value	=	TPhotoTexTTmp;
}

function setContentBeforeUpload()
{
	if (window.top.document.getElementById('QVideoTemp')!=null)
		window.top.document.getElementById('QVideoTemp').innerHTML	= document.getElementById('QVideo').innerHTML;
	if (window.top.document.getElementById('QAudioTemp')!=null)
		window.top.document.getElementById('QAudioTemp').innerHTML	= document.getElementById('QAudio').innerHTML;
	if (window.top.document.getElementById('QPhotoTemp')!=null)
		window.top.document.getElementById('QPhotoTemp').innerHTML	= document.getElementById('QPhoto').innerHTML;

	if (window.top.document.getElementById('AVideoTemp')!=null)
		window.top.document.getElementById('AVideoTemp').innerHTML	= document.getElementById('AVideo').innerHTML;
	if (window.top.document.getElementById('AAudioTemp')!=null)
		window.top.document.getElementById('AAudioTemp').innerHTML	= document.getElementById('AAudio').innerHTML;
	if (window.top.document.getElementById('APhotoTemp')!=null)
		window.top.document.getElementById('APhotoTemp').innerHTML	= document.getElementById('APhoto').innerHTML;

	if (window.top.document.getElementById('TVideoTemp')!=null)
		window.top.document.getElementById('TVideoTemp').innerHTML	= document.getElementById('TVideo').innerHTML;
	if (window.top.document.getElementById('TAudioTemp')!=null)
		window.top.document.getElementById('TAudioTemp').innerHTML	= document.getElementById('TAudio').innerHTML;
	if (window.top.document.getElementById('TPhotoTemp')!=null)
		window.top.document.getElementById('TPhotoTemp').innerHTML	= document.getElementById('TPhoto').innerHTML;
	
	if (window.top.document.getElementById('txt_QMathTmp')!=null)
		window.top.document.getElementById('txt_QMathTmp').value	= document.frmFlashcard.elements['txt_QMath'].value;
	if (window.top.document.getElementById('txt_AMathTmp')!=null)
		window.top.document.getElementById('txt_AMathTmp').value	= document.frmFlashcard.elements['txt_AMath'].value;
}

function checkContentByFormat(format)
{
	var ele		=	format+'setFmt';
	var	rtnFlag	=	true;
	var ftext	= '';
	switch(ele)
	{
		case	'QsetFmt'	:	var QsetFmt	=	document.getElementById('QsetFmt').value;
								switch(QsetFmt)
								{
									case 'text'	:	var ftext	=	trim(document.frmFlashcard.elements['fronttext'].value);
													ftext	=	trim(Encoder.htmlDecode(ftext));
													if (rtnFlag &&  (Encoder.isEmpty(ftext)))
														rtnFlag	=	false;
														
									break;
									case 'video':	if (rtnFlag && document.frmFlashcard.elements['mfront'].value=='')
														rtnFlag	=	false;
									break;
									case 'audio':	if (rtnFlag && document.frmFlashcard.elements['mfront'].value=='')
														rtnFlag	=	false;
									break;
									case 'photo':	if (rtnFlag && document.frmFlashcard.elements['mfront'].value=='')
														rtnFlag	=	false;
									break;
									case 'math':	if (rtnFlag && document.frmFlashcard.elements['txt_QMath'].value=='')
														rtnFlag	=	false;
									break;
								}
								
		break;
		case	'AsetFmt'	:	var AsetFmt	=	document.getElementById('AsetFmt').value;
								switch(AsetFmt)
								{
									case 'text'	:	var fatext	=	trim(document.frmFlashcard.elements['backtext'].value);
													fatext	=	trim(Encoder.htmlDecode(fatext));
													if (rtnFlag && (Encoder.isEmpty(fatext)))
														rtnFlag	=	false;
									break;
									case 'video':	if (rtnFlag && document.frmFlashcard.elements['mback'].value=='')
														rtnFlag	=	false;
									break;
									case 'audio':	if (rtnFlag && document.frmFlashcard.elements['mback'].value=='')
														rtnFlag	=	false;
									break;
									case 'photo':	if (rtnFlag && document.frmFlashcard.elements['mback'].value=='')
														rtnFlag	=	false;
									break;
									case 'math':	if (rtnFlag && document.frmFlashcard.element['txt_AMath'].value=='')
														rtnFlag	=	false;
									break;
								}
		break;
	}
	return rtnFlag;
}

function resetFlashContain()
{
	window.top.document.getElementById('QPhotoTemp').innerHTML	=	'';
	window.top.document.getElementById('QAudioTemp').innerHTML	=	'';
	window.top.document.getElementById('QVideoTemp').innerHTML	=	'';
	window.top.document.getElementById('APhotoTemp').innerHTML	=	'';
	window.top.document.getElementById('AAudioTemp').innerHTML	=	'';
	window.top.document.getElementById('AVideoTemp').innerHTML	=	'';
	window.top.document.getElementById('TPhotoTemp').innerHTML	=	'';
	window.top.document.getElementById('TAudioTemp').innerHTML	=	'';
	window.top.document.getElementById('TVideoTemp').innerHTML	=	'';
}

function submitFlashCard(_URL, action)
{
	closeEditor();
	resetFlashContain();
	var QsetFmt				=	'text';
	var AsetFmt				=	'text';
	var TsetFmt				=	'text';

	var cardCount			=	window.top.document.getElementById('cardCount').value;
	var page_action			=	document.getElementById('page_action').value;
	var deck_id				=	document.getElementById('deck_id').value;
	var pos					=	document.getElementById('pos').value;
	QsetFmt					=	document.getElementById('QsetFmt').value;
	AsetFmt					=	document.getElementById('AsetFmt').value;
	TsetFmt					=	document.getElementById('TsetFmt').value;
	var mfront				=	document.getElementById('mfront').value;
	var mback				=	document.getElementById('mback').value;
	var m3rdside			=	document.getElementById('m3rdside').value;
	var globalTags			=	encodeURIComponent(document.getElementById('globalTags').value);
	var fronttext			=	encodeURIComponent(document.frmFlashcard.elements['fronttext'].value);
	var QVideoTexT			=	encodeURIComponent(document.getElementById('QVideoTexT').value);
	var QAudioTexT			=	encodeURIComponent(document.getElementById('QAudioTexT').value);
	var	QPhotoTexT			=	encodeURIComponent(document.getElementById('QPhotoTexT').value);
	var txt_QMath			=	encodeURIComponent(document.getElementById('txt_QMath').value);
	var backtext			=	encodeURIComponent(document.frmFlashcard.elements['backtext'].value);
	var AVideoTexT			=	encodeURIComponent(document.getElementById('AVideoTexT').value);
	var AAudioTexT			=	encodeURIComponent(document.getElementById('AAudioTexT').value);
	var APhotoTexT			=	encodeURIComponent(document.getElementById('APhotoTexT').value);
	var txt_AMath			=	encodeURIComponent(document.getElementById('txt_AMath').value);
	var thirdtext			=	encodeURIComponent(document.frmFlashcard.elements['thirdtext'].value);
	var TVideoTexT			=	encodeURIComponent(document.getElementById('TVideoTexT').value);
	var TAudioTexT			=	encodeURIComponent(document.getElementById('TAudioTexT').value);
	var TPhotoTexT			=	encodeURIComponent(document.getElementById('TPhotoTexT').value);
	
	var params			=	'cardCount='+cardCount+'&page_action='+page_action+'&deck_id='+deck_id+'&pos='+pos+'&QsetFmt='+QsetFmt+'&AsetFmt='+AsetFmt+'&TsetFmt='+TsetFmt+'&mfront='+mfront+'&mback='+mback+'&m3rdside='+m3rdside+'&globalTags='+globalTags+'&fronttext='+fronttext+'&QVideoTexT='+QVideoTexT+'&QAudioTexT='+QAudioTexT+'&QPhotoTexT='+QPhotoTexT+'&txt_QMath='+txt_QMath+'&backtext='+backtext+'&AVideoTexT='+AVideoTexT+'&AAudioTexT='+AAudioTexT+'&APhotoTexT='+APhotoTexT+'&txt_AMath='+txt_AMath+'&thirdtext='+thirdtext+'&TVideoTexT='+TVideoTexT+'&TAudioTexT='+TAudioTexT+'&TPhotoTexT='+TPhotoTexT;
	
	if(action=='edit') {
		var fcid			=	document.getElementById('fcid').value;
		params			=	params+'&fcid='+fcid;
	}
	
	var req =	GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/submitFlashCard.php";
	
	req.onreadystatechange = function()
	{
		if(req.readyState==4) 
		{
			if (req.status == 200)
			{
				if (req.responseText=='error')
				{
					alert('Error: Invalid parameters.')
				}
				else if (req.responseText=='success')
				{
					var pg		=	window.top.document.getElementById('pg').value;
					var order	=	window.top.document.getElementById('order').value;
					window.top.getFlashCardList(_URL, deck_id, pg, order, 'add');
					window.top.popCntFlag	=	false;
					window.top.urlToLoad	=	'';
					window.top.closeFacebox();
				}
				else {
					alert(req.responseText);
				}
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}


function clearFlashText(id, val)
{
	if(document.frmFlashcard.elements[id].value==val)
		document.frmFlashcard.elements[id].value	= '';
}
 
function writeDefaultText(id, val)
{
	if(document.frmFlashcard.elements[id].value=='')
		document.frmFlashcard.elements[id].value	= val;
}

function submitSearchPage(_URL, sortOn)
{
	var selectText 	= 	window.top.document.getElementById('selectText').value;
	var searchText	=	window.top.document.getElementById('searchText').value;
	var rURL		=	_URL+'searchResults.php?searchTxt=' + encodeURIComponent(searchText);
	
	switch(selectText)
	{
		case 'Study Teams'	:	rURL	=	rURL+'&groups=true';
		break;
		case 'People'		:	rURL	=	rURL+'&users=true';
		break;
		case 'Quizzes'		:	rURL	=	rURL+'&quiz=true';
		break;
		default				:	rURL	=	rURL+'&decks=true';
	}
	window.location.href 	=	rURL+'&sortOn='+sortOn;
}

function doIframe(hght){
	var o = document.getElementsByTagName('iframe');
	for(var i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i], hght);
		}
	}
}

function setHeight(e, hght){
	e.height	= hght;
}

function validatePhoneNumber(elementValue)
{
	var phoneNumberPattern1 = /^\(?(\d{3})\)?[-]?(\d{3})[-]?(\d{4})$/;
	var phoneNumberPattern2 = /^\(?(\d{3})\)?[ ]?(\d{3})[ ]?(\d{4})$/;
	var phoneNumberPattern3 = /^\(?(\d{3})\)?[.]?(\d{3})[.]?(\d{4})$/;
	if( phoneNumberPattern1.test(elementValue) || phoneNumberPattern2.test(elementValue) || phoneNumberPattern3.test(elementValue))
		return true;
	else
		return false;
}

function loadInviteBox(_URL, urlToOpen, gid)
{
	var rtn	=	createCookie('opModal',urlToOpen,1);
	if (rtn)
		window.location.href	=	_URL+'InviteFriends.php?gid='+gid;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
	if (readCookie(name))
		return true;
	else
		return false;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setQuizQuesFormat(format)
{
	switch(format)
	{
		case'Photo'	:	document.getElementById('qPhoto').style.visibility	=	'visible';
						document.getElementById('qPhoto').style.display		=	'block';
						document.getElementById('qText').style.visibility	=	'hidden';
						document.getElementById('qText').style.display		=	'none';
		break;
		default 	:	document.getElementById('qPhoto').style.visibility	=	'hidden';
						document.getElementById('qPhoto').style.display		=	'none';
						document.getElementById('qText').style.visibility	=	'visible';
						document.getElementById('qText').style.display		=	'block';
	}
}

function setQuizQuesContent(urlToOpen)
{
	closeEditor();
	window.top.popCntFlag	=	true;
	var rtn		=	setQuizQuesContentBeforeUpload();	

	if (rtn)
	{	window.top.openFaceBox(urlToOpen);	}
}

function setQuizQuesContentBeforeUpload()
{
	var frm					=	document.frmFlashcard;

	var t_ansCnt		=	frm.ansCnt.value;
	var t_page_action	=	frm.page_action.value;
	var t_quizId		=	frm.quizId.value;
	var t_quesId		=	frm.quesId.value;
	
	var t_Qformat		=	frm.Qformat.value;
	var t_quiz_text		=	frm.quiz_text.value;
	var t_qImgPath		=	frm.qImgPath.value;
	var t_qImg			=	document.getElementById('qImg').innerHTML;
	var t_ques_ptext	=	frm.ques_ptext.value;
	var t_globalTags	=	frm.globalTags.value;
	
	var innerhtml 	= '	<input type="hidden" name="t_ansCnt" id="t_ansCnt" value="'+t_ansCnt+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_page_action" id="t_page_action" value="'+t_page_action+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_quizId" id="t_quizId" value="'+t_quizId+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_quesId" id="t_quesId" value="'+t_quesId+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_Qformat" id="t_Qformat" value="'+t_Qformat+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_quiz_text" id="t_quiz_text" value="'+t_quiz_text+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_qImgPath" id="t_qImgPath" value="'+t_qImgPath+'" />';
    innerhtml 		= innerhtml + '	<span id="t_qImg">'+t_qImg+'</span>';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_ques_ptext" id="t_ques_ptext" value="'+t_ques_ptext+'" />';
    innerhtml 		= innerhtml + '	<input type="hidden" name="t_globalTags" id="t_globalTags" value="'+t_globalTags+'" />';

//	t_ansCnt		=	(t_page_action=='add')?(parseInt(t_ansCnt)-1):t_ansCnt;
	t_ansCnt		=	(t_ansCnt<=2)?3:t_ansCnt;
	// Set Answer Real Data
	if (t_ansCnt>0)
	{	
		for (i=0; i<t_ansCnt; i++)
		{
			if (frm.elements['ansId_'+i]!='undefined' && frm.elements['ansId_'+i]!=null)
			{
				var t_ansId		=	frm.elements['ansId_'+i].value;
				var t_aFormat		=	frm.elements['aFormat_'+i].value;
				var t_aImgPath		=	frm.elements['aImgPath_'+i].value;
				var t_aImg			=	document.getElementById('aImg_'+i).innerHTML;
				var t_ans_action	=	frm.elements['ans_action_'+i].value;
				var t_anstext		=	frm.elements['anstext_'+i].value;
				var t_ansCorrect	=	(frm.elements['ansCorrect_'+i].checked)?1:0;
				
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_ansId_'+i+'" id="t_ansId_'+i+'" value="'+t_ansId+'" />';
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_aFormat_'+i+'" id="t_aFormat_'+i+'" value="'+t_aFormat+'" />';
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_aImgPath_'+i+'" id="t_aImgPath_'+i+'" value="'+t_aImgPath+'" />';
				innerhtml 	= innerhtml + '	<span id="t_aImg_'+i+'">'+t_aImg+'</span>';
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_ans_action_'+i+'" id="t_ans_action_'+i+'" value="'+t_ans_action+'" />';
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_anstext_'+i+'" id="t_anstext_'+i+'" value="'+t_anstext+'" />';
				innerhtml 	= innerhtml + '	<input type="hidden" name="t_ansCorrect_'+i+'" id="t_ansCorrect_'+i+'" value="'+t_ansCorrect+'" />';
			}
		}
	}

	window.top.document.getElementById("QuizModalContent").innerHTML	=	'';
	window.top.document.getElementById("QuizModalContent").innerHTML	=	innerhtml;	
	return true;
}

function setQuizQuesContentAfterUpload(_URL)
{
	window.top.popCntFlag	=	false;

	var frm					=	document.frmFlashcard;
	var xTop				=	window.top.document;
	
	frm.ansCnt.value		=	xTop.getElementById('t_ansCnt').value;
	frm.page_action.value	=	xTop.getElementById('t_page_action').value;
	frm.quizId.value		=	xTop.getElementById('t_quizId').value;
	frm.quesId.value		=	xTop.getElementById('t_quesId').value;
	
	frm.Qformat.value								=	xTop.getElementById('t_Qformat').value;
	
	frm.quiz_text.value								=	xTop.getElementById('t_quiz_text').value;
	document.getElementById('quiz_text').innerHTML	=	frm.quiz_text.value;
	frm.qImgPath.value								=	xTop.getElementById('t_qImgPath').value;
	document.getElementById('qImg').innerHTML		=	xTop.getElementById('t_qImg').innerHTML;
	frm.ques_ptext.value							=	xTop.getElementById('t_ques_ptext').value;
	frm.globalTags.value							=	xTop.getElementById('t_globalTags').value;

	var cnt		=	frm.ansCnt.value;
	var ihtml	=	'';
	cnt			=	(cnt<=2)?3:cnt;
	if (cnt>0)
	{	
		for (i=0; i<cnt; i++)
		{
			var ansId					=	null;
			var aFormat					=	null;
			var aImgPath				=	null;
			var aImg					=	null;
			var ans_action				=	null;
			var anstext					=	null;
			var ansCorrect				=	false;
			var imgUpload				=	null;
			
			var ansId				=	xTop.getElementById('t_ansId_'+i).value;
			var aFormat				=	xTop.getElementById('t_aFormat_'+i).value;
			var aImgPath			=	xTop.getElementById('t_aImgPath_'+i).value;
			var aImg				=	xTop.getElementById('t_aImg_'+i).innerHTML;
			var ans_action			=	xTop.getElementById('t_ans_action_'+i).value;
			var anstext				=	xTop.getElementById('t_anstext_'+i).value;
			var ansCorrect			=	(xTop.getElementById('t_ansCorrect_'+i).value==1)?true:false;
			
			var imgUpload			=	_URL+'popBox.php?enc=n&height=125&width=320&url=popQuizPhoto.php?num='+i+'&fileType=quizAnsImage&from=quiz';
			
            ihtml 	= ihtml + '<div id="popAns_'+i+'">';
			ihtml 	= ihtml + '	<input type="hidden" name="ansId_'+i+'" id="ansId_'+i+'" value="'+ansId+'" />';
			ihtml 	= ihtml + '	<input type="hidden" name="aFormat_'+i+'" id="aFormat_'+i+'" value="'+aFormat+'" />';
			ihtml 	= ihtml + '	<input type="hidden" name="aImgPath_'+i+'" id="aImgPath_'+i+'" value="'+aImgPath+'" />';
			ihtml 	= ihtml + '	<input type="hidden" name="ans_action_'+i+'" id="ans_action_'+i+'" value="'+ans_action+'" />';
			ihtml 	= ihtml + '	<div class="popAns">';
			ihtml 	= ihtml + '	<table cellpadding="0" cellspacing="0" border="0">';
			ihtml 	= ihtml + '	<tr>';
			ihtml 	= ihtml + '	<td valign="top"><div class="ansImgBox">';
			ihtml 	= ihtml + '	<a href="javascript:void(0);" onclick="closeEditor();setQuizQuesContent(\''+imgUpload+'\');" class="facebox">';
			ihtml 	= ihtml + '	<table cellpadding="0" cellspacing="0" border="0">';
			ihtml 	= ihtml + '	<tr><td id="aImg_'+i+'" valign="middle" align="center" width="56" height="56">'+aImg+'</td></tr></table></a></div></td>';
			ihtml 	= ihtml + '	<td valign="top"><div class="ansTextBox"><textarea name="anstext_'+i+'" id="anstext_'+i+'" onfocus="closeEditor();clearFlashText(this.id, \'Enter Answer Here\');" onblur="writeDefaultText(this.id, \'Enter Answer Here\');">'+anstext+'</textarea></div></td>';
			ihtml 	= ihtml + '	<td valign="top"><div class="ansOption"><input onfocus="closeEditor();" type="checkbox" name="ansCorrect_'+i+'" id="ansCorrect_'+i+'" ';
			
			ihtml 	= ihtml + ((ansCorrect)?' checked ' : '');
			ihtml 	= ihtml + '	/></div></td></tr></table></div></div>';
		}
	}
	var hght		=	window.top.document.getElementById('fHeight').value;
	if (hght<428 || cnt<=3)
		hght	=	448;
	else {
		hght	=	448 + ((parseInt(cnt)-3)*68);
	}
	
	window.top.doIframe(hght);
	setQuizQuesFormat(frm.Qformat.value);
	document.getElementById('QuizQuesAns').innerHTML					=	ihtml;
	window.top.initFaceBox(_URL);
	//window.top.document.getElementById("QuizModalContent").innerHTML	=	'';
}

function cleanAndClose()
{
	window.top.document.getElementById('QuizModalContent').innerHTML	=	'';
	window.top.document.getElementById('fHeight').value					=	'';
	window.top.closeFacebox();
}

function selectMemberTab(id)
{
	for (i=1; i<=9; i++)
	{
		var liEle	=	'grp'+i;
		var aEle	=	'grkln'+i;	
		var boxEle	=	'grpBox'+i;

		if (parseInt(id)>6)
		{
			window.top.document.getElementById('commonBox').className	=	'grpTabContent delhidden';
			if (window.top.document.getElementById('extraBox')!=null && window.top.document.getElementById('extraBox')!='undefined')
			{	window.top.document.getElementById('extraBox').className	=	'delvisible';	}
		}
		else
		{
			window.top.document.getElementById('commonBox').className	=	'grpTabContent delvisible';
			if (window.top.document.getElementById('extraBox')!=null && window.top.document.getElementById('extraBox')!='undefined')
			{	window.top.document.getElementById('extraBox').className	=	'delhidden';	}
		}

		if (i==parseInt(id))
		{
			if (window.top.document.getElementById(liEle)!=null && window.top.document.getElementById(liEle)!='undefined')
			{
				window.top.document.getElementById(liEle).className		=	'current';
				window.top.document.getElementById(aEle).className		=	'here';
				window.top.document.getElementById(boxEle).className	=	'delvisible';
				
				if (id==7)
				{	window.top.document.getElementById(liEle).style.backgroundColor		=	'#FFFFFF';	}
				else
				{
					if (window.top.document.getElementById('memInboxCount')!=null && window.top.document.getElementById('memInboxCount')!='undefined')	
					{
						if (parseInt(window.top.document.getElementById('memInboxCount').innerHTML)>0)
						{
							window.top.document.getElementById('grp7').style.backgroundColor		=	'#FFCC66';
							window.top.document.getElementById('grkln7').style.backgroundColor		=	'#FFCC66';
						}
						if (parseInt(window.top.document.getElementById('memInboxCount').innerHTML)==0)
						{
							window.top.document.getElementById('grp7').style.backgroundColor		=	'#F6F6F6';
							window.top.document.getElementById('grkln7').style.backgroundColor		=	'#F6F6F6';
						}	
					}
				}
			}
		}
		else
		{
			if (window.top.document.getElementById(liEle)!=null && window.top.document.getElementById(liEle)!='undefined')
			{
				window.top.document.getElementById(liEle).className		=	'';
				if (window.top.document.getElementById(aEle)!=null && window.top.document.getElementById(aEle)!='undefined')
				{	window.top.document.getElementById(aEle).className		=	'';	}
				if (window.top.document.getElementById(boxEle)!=null && window.top.document.getElementById(boxEle)!='undefined')
				{	window.top.document.getElementById(boxEle).className	=	'delhidden';	}
			}
		}	
	}
}


function getMemberWhiteBoard(_URL, mid, pg, action)
{
	var req =		GetXmlHttpObject();
	var url	=	_URL + "AJAX_FUNCTIONS/getMemberWhiteboard.php";
	
	if(action != 'load')
	{
		var	replyMsg	=	window.top.document.getElementById('txtdiscussion').value;
		if(replyMsg == '' || replyMsg == 'Join the Discussion. Write Something...')
		{
			alert('No message to post');
			return false;
		}
		var params = "mid="+mid+"&response="+encodeURIComponent(replyMsg)+'&action='+action+'&pg='+pg;
	}
	else
		var params = "mid="+mid+'&action='+action+'&pg='+pg;
		

	var waitboxStyle	=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
	var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
	window.top.document.getElementById('dispostBox').innerHTML	=	waitcursor;

	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if (req.responseText=='error')
			{
				alert('Error: Invalid parameters.');
			}
			else
			{
				var res		=	req.responseText.split('~~~###disnum###~~~');
				window.top.document.getElementById('dispostBox').innerHTML	=	res[0];
				window.top.document.getElementById('displaynum').innerHTML	=	res[1];
				window.top.document.getElementById('txtdiscussion').value	=	'Join the Discussion. Write Something...';
				window.top.initFaceBox(_URL);
			}
		}
	}
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function getAllMemberTabConatin(_URL, mid, lastaction)
{
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'hfriend', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'deckQuiz', ''+lastaction+'');
	getMemberWhiteBoard(''+_URL+'', ''+mid+'', 1, 'load', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'decks', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'quizzes', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'friends', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'blogs', ''+lastaction+'');
	getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'documents', ''+lastaction+'');
}

function getMemberTabSets(_URL, mid, pg, type, lastaction)
{
	var url			=	null;
	var ele			=	null;
	var waitboxStyle=	null;
	var	params		=	"mid="+mid+"&pg="+pg+"&lastaction="+lastaction+"&type="+type;
	switch(type)
	{
		case 'hfriend':	url		=	_URL + "ajax_functions/getFriends.php";
						ele		=	'memOver';
						waitboxStyle=	'style="width:368px; height:240px; padding:70px 12px 12px 0px; text-align:center; font-weight:bold;"';
		break;
		case 'decks':	url	=	_URL + "ajax_functions/getMemberDeckQuiz.php";
						ele	=	'grpdecks';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'deckQuiz':	url	=	_URL + "ajax_functions/getMemberDeckQuiz.php";
						ele	=	'overDecks';
						waitboxStyle=	'style="width:368px; height:240px; padding:70px 12px 12px 0px; text-align:center; font-weight:bold;"';
		break;
		case 'quizzes':	url	=	_URL + "ajax_functions/getMemberDeckQuiz.php";
						ele	=	'grpquizzes';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'friends':	url	=	_URL + "ajax_functions/getFriends.php";
						ele	=	'grpmembers';
						waitboxStyle=	'style="width:200px; height:100px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'blogs':	url	=	_URL + "ajax_functions/getMemberBlogs.php";
						ele	=	'grpblogs';
						waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
		case 'admins':	url	=	_URL + "ajax_functions/getGroupAdmins.php";
						ele	=	'grpadmin';
						waitboxStyle=	'style="width:140px; height:70px; padding:12px 0px 0px 0px; text-align:left; font-weight:bold; font-size:11px;"';
		break;
		case 'documents':url=	_URL + "ajax_functions/getMemberDocuments.php";
						ele	=	'grpdocuments';
						waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
		break;
	}
	if (url!=null)
	{
		var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
		window.top.document.getElementById(ele).innerHTML	=	waitcursor;
		
		var req 		=	initRequest();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					switch (type)
					{
						case 'hfriend':
						if (req.responseText!='') {
							var res	=	req.responseText.split('~~~###memnum###~~~');
							window.top.document.getElementById(ele).innerHTML	=	res[0];
							window.top.document.getElementById('memCnt').innerHTML	=	res[1];
						}
						break;
						case 'deckQuiz':
						if (req.responseText!='') {
							var res	=	req.responseText.split('~~~###decknum###~~~');
							window.top.document.getElementById(ele).innerHTML	=	res[0];
							window.top.document.getElementById('decknum').innerHTML	=	res[1];
						}
						break;
						default:
							window.top.document.getElementById(ele).innerHTML	=	req.responseText;
					}
					window.top.initFaceBox(_URL);
				} 
			}
		};	
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}

function getDeckSlideShow(_URL, type, did, cId, divId, lastaction)
{
	var url				=	_URL + "ajax_functions/getDeckSlideShow.php";
	var	params			=	"type=" + type + "&did=" + did + "&cId=" + cId +"&lastaction=" + lastaction;
	var waitboxStyle	=	'style="width:368px; height:240px; padding:60px 12px 12px 0px; text-align:center; font-weight:bold;"';
	var waitcursor			=	getWaitCursor(_URL, waitboxStyle);
	
	window.top.document.getElementById(divId).innerHTML	=	waitcursor;
		
	var req 		=	initRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) 
		{
			if (req.status == 200)
			{
				window.top.document.getElementById(divId).innerHTML	=	req.responseText;
				window.top.initFaceBox(_URL);
			} 
		}
	};	
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	return true;
}

function memberInboxVisibilty(id)
{
	id	=	(id>3)?3:((id<1)?1:id);
	var ele		=	'mIBox'+id;
	var mEle	=	'inb'+id;
	
	for (i=1; i<=3; i++)
	{
		if (window.top.document.getElementById(ele)!=null && window.top.document.getElementById(ele)!='undefined')
		{
			if (parseInt(id)==i)
			{	
				window.top.document.getElementById(ele).className	=	'delvisible';
				window.top.document.getElementById(mEle).className	=	'commonLink clsBlack';
				
			}
			else
			{	
				window.top.document.getElementById('mIBox'+i).className	=	'delhidden';	
				window.top.document.getElementById('inb'+i).className	=	'commonLink'
			}
		}
	}
}

function getMemberInbox(_URL, mid, pg, type, lastaction)
{
	var ele			=	null;
	var waitboxStyle=	'style="width:200px; height:200px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
	var url	=	_URL + "ajax_functions/getMemberInbox.php";
	var	params		=	"mid="+mid+"&pg="+pg+"&lastaction="+lastaction+"&type="+type;
	switch(type)
	{
		case 'frequest'	:	ele	=	'memFRequest';
		break;
		case 'fnotify'	:	ele	=	'memNotif';
		break;
		case 'fmessage'	:	ele	=	'memMsg';
		break;
	}
	
	if (url!=null)
	{
		var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
		window.top.document.getElementById(ele).innerHTML	=	waitcursor;
		
		var req 		=	initRequest();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
					window.top.document.getElementById(ele).innerHTML	=	req.responseText;
					window.top.initFaceBox(_URL);
				} 
			}
		};	
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}

function setInboxTabColor(evt)
{
	if (evt.match('in'))
	{
		var oldColor	=	window.top.document.getElementById('grp7').style.backgroundColor;
		window.top.document.getElementById('inboxTabColor').value	=	oldColor;
		
		window.top.document.getElementById('grp7').style.backgroundColor	=	'#FFFFFF';
		window.top.document.getElementById('grkln7').style.backgroundColor	=	'#FFFFFF';
	}
	else
	{
		var oldColor	=	window.top.document.getElementById('inboxTabColor').value;
		window.top.document.getElementById('inboxTabColor').value	=	'#FFFFFF';
		
		if (window.top.document.getElementById('grkln7').className!='here')
		{
			window.top.document.getElementById('grp7').style.backgroundColor	=	oldColor;
			window.top.document.getElementById('grkln7').style.backgroundColor	=	oldColor;
		}
	}
}


function updateMemberMessageStatus(_URL, Id, status, nType, type)
{
	switch(type)
	{
		case 'notification':
			var pg	=	window.top.document.getElementById('fnPg').value;
			var waitboxStyle=	'style="width:200px; height:200px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
			var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
			window.top.document.getElementById('memNotif').innerHTML	=	waitcursor;

			var url			=	_URL + "ajax_functions/updateNotificationStatus.php";
			var params		=	"notificationsId="+Id+"&Status="+status+"&notificationType="+nType;
	
			var req 		=	initRequest();
			req.onreadystatechange = function()
			{
				if(req.readyState==4) 
				{
					if (req.status == 200)
					{
						incrementCount("msgCount", -1);
						incrementCount("memInboxCount", -1);
						incrementCount("inbCnt2", -1);
						var mid	=	window.top.document.getElementById('profileId').value;
						window.top.getMemberInbox(_URL, mid, pg, 'fnotify', 'update');
					}
				}
			}
			req.open("POST", url, true);
			req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			req.setRequestHeader("Content-length", params.length);
			req.setRequestHeader("Connection", "close");
			req.send(params);
			return true;
		break;
		
		case 'frequest':
			var pg	=	window.top.document.getElementById('frPg').value;
			var waitboxStyle=	'style="width:200px; height:200px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
			var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
			window.top.document.getElementById('memFRequest').innerHTML	=	waitcursor;

			var url			=	_URL + "ajax_functions/updateFriendRequest.php";
			var params		=	"friendMemberId="+Id+"&Status="+status;
			var req 		=	initRequest();

			req.onreadystatechange = function()
			{
				if(req.readyState==4) 
				{
					if (req.status == 200)
					{
						incrementCount("msgCount", -1);
						incrementCount("memInboxCount", -1);
						incrementCount("inbCnt1", -1);
						
						var fcount	=	window.top.document.getElementById('mfcnt').innerHTML;
						if (status.match('C'))
						{	window.top.document.getElementById('mfcnt').innerHTML	=	parseInt(fcount)+1;	}
						
						var mid	=	window.top.document.getElementById('profileId').value;
						window.top.getMemberInbox(_URL, mid, pg, 'frequest', 'update');
						window.top.getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'hfriend', 'get');
						window.top.getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'friends', 'get');
					}
				}
			}
			
			req.open("POST", url, true);
			req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			req.setRequestHeader("Content-length", params.length);
			req.setRequestHeader("Connection", "close");
			req.send(params);
			return true;
		break;
		
		case 'mMessage':
			var pg	=	window.top.document.getElementById('fmPg').value;
			var waitboxStyle=	'style="width:200px; height:200px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
			var waitcursor		=	getWaitCursor(_URL, waitboxStyle);
			window.top.document.getElementById('memMsg').innerHTML	=	waitcursor;

			var url	    =	_URL + "ajax_functions/updateMessageStatus.php";
			var params	=	"messageId="+Id+"&Status="+status;
			var req 		=	initRequest();

			req.onreadystatechange = function()
			{
				if(req.readyState==4) 
				{
					if (req.status == 200)
					{
						incrementCount("msgCount", -1);
						incrementCount("memInboxCount", -1);
						incrementCount("inbCnt3", -1);
						var mid	=	window.top.document.getElementById('profileId').value;
						window.top.getMemberInbox(_URL, mid, pg, 'fmessage', 'update');
					}
				}
			}
			req.open("POST", url, true);
			req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			req.setRequestHeader("Content-length", params.length);
			req.setRequestHeader("Connection", "close");
			req.send(params);
			return true;
		break;
	}
}

function replyMessage(_URL, id)
{
	var ele		=	'message_text_'+id;
	var errEle	=	'errMsg_'+id;
	if (trim(window.top.document.getElementById(ele).value)=='')
	{
		window.top.document.getElementById(ele).focus();
		for (i=0; i<5; i++)
		{
			if (window.top.document.getElementById('errMsg_'+i)!=null && window.top.document.getElementById('errMsg_'+i)!='undefined')
			{	window.top.document.getElementById('errMsg_'+i).innerHTML	=	((i==id)?'Please enter your message.':''); }
		}
		return false;
	}
	else 
	{	
		var req 	=	GetXmlHttpObject();
		var url		=	_URL + "AJAX_FUNCTIONS/sendMessage.php";
		
		window.top.document.getElementById('loading_'+id).className	=	'delvisible';
		
		var mid		=	window.top.document.getElementById('member_id_to_'+id).value;
		var txtMsg	=	encodeURIComponent(window.top.document.getElementById('message_text_'+id).value);
		var params		=	"page_action=single&mid="+mid+'&message_text='+txtMsg;
	
		req.onreadystatechange = function()
		{
			if(req.readyState==4) 
			{
				window.top.document.getElementById('loading_'+id).className		=	'delhidden';
				if ((req.responseText)=='success')
				{	
					window.top.document.getElementById('message_text_'+id).value	=	'';
					window.top.document.getElementById('errMsg_'+id).innerHTML		=	'Your message has been sent.';
				}
				else
				{	document.getElementById('errMsg_'+id).innerHTML	=	'Error: Invalid parameters.';	}
			}
		}
		req.open("POST", url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
		return true;
	}
}


function memberDeleteType(_URL, type, id, mid, page_id, limit)
{
	var urlString	= _URL;
	switch(type)
	{
		case 'blog':	var ans = confirm("WARNING !!\n\nAre you sure, you want to delete this Blog?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=memberBlog&blog_id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
								   incrementCount("blognum", -1);
   								   window.top.getMemberTabSets(''+_URL+'', ''+mid+'', ''+page_id+'', 'blogs', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
		break;
		case 'deck':	var ans = confirm("WARNING !!\n\nAre you sure, you want to delete this deck?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=deckMember&id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
									incrementCount("totDecks", -1);
								    window.top.getMemberTabSets(''+_URL+'', ''+mid+'', ''+page_id+'', 'decks', 'add');
									window.top.getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'deckQuiz', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
		break;
		case 'quiz':	var ans = confirm("WARNING !!\n\nAre you sure, you want to delete this quiz?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=memberQuiz&id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
									incrementCount("totQuizzes", -1);
									window.top.getMemberTabSets(''+_URL+'', ''+mid+'', ''+page_id+'', 'quizzes', 'add');
									window.top.getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'deckQuiz', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
		break;
		case 'friend':	var ans = confirm("WARNING !!\n\nAre you sure, you want to delete this friend?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=memberfriend&id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
									incrementCount("mfcnt", -1);
									window.top.getMemberTabSets(''+_URL+'', ''+mid+'', ''+page_id+'', 'friends', 'add');
									window.top.getMemberTabSets(''+_URL+'', ''+mid+'', 1, 'hfriend', 'add');
								}
							}							
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
		break;
		case 'doc':	var ans = confirm("WARNING !!\n\nAre you sure, you want to delete this Document?");
						if(ans)
						{
							var url			=	_URL + "AJAX_FUNCTIONS/delete.php?type=memberDoc&doc_id="+id;
							var req =	GetXmlHttpObject();		
							var waitboxStyle=	'style="width:200px; height:70px; padding:12px 12px 12px 0px; text-align:left; font-weight:bold;"';
				
							req.onreadystatechange = function()
							{
								if(req.readyState==4)
								{
								   incrementCount("docnum", -1);
   								   window.top.getMemberTabSets(''+_URL+'', ''+mid+'', ''+page_id+'', 'documents', 'add');
								}
							}
							req.open("GET", url, true);
							req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
							req.send(null);
							return true;
						}
		break;
	}
}

function ClickToPostBlog(_BLOG_POST_URL)
{
	selectGroupTab(5);
	window.top.openFaceBox(_BLOG_POST_URL);
}


function checkStrippedText(_URL, text, type)
{
	var req 	=	GetXmlHttpObject();
	var url		=	_URL + "AJAX_FUNCTIONS/commonOperation.php";
	
	var params		=	'type='+type+'&text='+text;

	req.open("POST", url, false);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	req.send(params);
	if (req.responseText=='')
	{	return false;	}
	else
	{	return true;	}
}

function textCounter(textElement, counterElement, maxLimit, dontAlert) {
    if (textElement.value.length > maxLimit) {
	textElement.value = textElement.value.substring(0, maxLimit);
	counterElement.innerHTML = 0;
	counterElement.style.color='#FF0000';

	if (dontAlert != true)
	    alert('You have reached the maximum limit of characters allowed.');
    } else {
	charactersRemaining = maxLimit - textElement.value.length
	counterElement.innerHTML = charactersRemaining;

	if (charactersRemaining == 0) 
	    counterElement.style.color='#FF0000';
	else
	    counterElement.style.color='#000000';
    }
}

