// JavaScript Document
function doLogin(){
		$.get(base_url + 'slpw/apa_login.php?page='+$("#page").val()+'&username='+$("#username").val()+'&password='+$("#password").val()+'&remember='+$("#remember").val()+'&turing='+$("#turing").val()+'&login='+$("#login").val(), function(data) {
		  if(data==true){
			  document.log = true;
			  setupCopy();
	          DetectSection();
			  sec = getSectionName();
			  fireAjaxRequest("students/scripts/showAlldatabase.php","","formatHL="+sec,"c8Content","");
			  refreshMenu();
			  getACButton();
			  return rigtTabContent('b4');
		  }else{
		  	//alert(data);
			if(data==MSG_DISABLED){
			   $.ajax({
				   type: 'GET',
				   url: base_url+'expired.php?ajax=Yes',
				   success: function(data){
				   		//alert(data);
						$('#b8').html(data);
			     	}
		   		});
				return false;
			}else{
				$('#errPL').html(data);
			}
		  }
		  //alert('Load was performed.');
		});
		return false;
}	
	
function LogoutHandler(){
	
	//jConfirmMod("Your citations and notes will be stored for 1 year from today.", 'Logout' ,'&nbsp;OK&nbsp;',function(c1) {
		//if(c1){
			if (document.log==true && document.fblog==true){
				FB.getLoginStatus(function(response) {
						 if(response.status === 'connected'){
							 FB.logout(function() {
					 			window.location = siteloklogout;
							});
						 }
					});
 				return false;
				
			}else{
				window.location = siteloklogout;
			}
		//}
	//});
}



function makeLink(){
	if(document.all)
	window.external.AddFavorite(url,title)
}

function ReloadTextDiv2(textName,divName,other)	{ 
//alert('111');
	if($("#aWorldcatSearch").hasClass("active")==true){
		if($('#HIDEIN').html()!='WORLDCAT'){
			$("#preview").click();
		}
	}else{
		$("#preview").click();
	}
	$("#t1").click();
	FormatCitation(textName,divName,other);
	setInText(textName,divName,other);
}

function getCitation(p){
	secName = getSectionName();
	$('#main').html('');$('#HIDEVAR').html('');$('#HIDEVAL').html('');$('#HIDEIN').html('');
	strData = "secName="+secName+"&p=" + p + "&txtSearch1="+jQuery("#txtSearch1").val() + "&drpSearch1="+jQuery("#drpSearch1").val() + "&txtSearch2="+jQuery("#txtSearch2").val() + "&drpSearch2="+jQuery("#drpSearch2").val();
	jQuery("#main").html("<center><img src='"+base_url+"students/images/loading_bar.gif' align='center'></center>");
	jQuery.ajax({
		type: "POST",
		url: base_url+"worldcat.php",
		data: strData,
		success: function(msg){
			//alert(msg);
			jQuery("#main").html(msg);
		}
	});
	return false;
}

function locateNear(id){
	//alert($('#TD'+id).html());
	//window.open("http://worldcat.org/oclc/"+id);
	
	//jQuery('#aLocateNear').attr("href",'http://worldcat.org/oclc/'+id);
	//jQuery('#aLocateNear').attr("target","_blank");
	jQuery('#HIDEVAR').html("http://worldcat.org/oclc/"+id);
	jQuery('#HIDEVAL').html(id);
	//jQuery('#hidehref').value="http://worldcat.org/oclc/"+id;
	//document.getElementById('#HIDEVAR').innerHTML=";
	
	return true;
}
function getSectionColor(){
	section4css = getSectionName();
	color_ = '';
	if(section4css == 'apa'){
		color_ = '#FF00FF';
	}
	else if(section4css == 'harvard'){
		color_ = '#C80000';
	}
	else if(section4css == 'mla'){
		color_ = '#3333CC';
	}
	return color_;
}

function SaveSearch(){
	var hrefs='';
	hrefs = $('#HIDEVAR').html();
	if(hrefs=='') {
		HIDEIN = $('#HIDEIN').html();
		var nwc = $('#chkResultsWCS:checked').length;
		if(nwc==0 && HIDEIN=='WORLDCAT'){
			$("#worldcatMsg").html('Click Citation to proceed with your request');
		}else{
			if(($("#txtSearch1").val()!="") || ($("#txtSearch2").val()!="")){
				msgH1 = 'Click WorldCat search button first';
			}else{
				msgH1 = 'Please enter search criteria';
			}
			$("#main").html('<h1 style="color:#C80000;margin-top:10px;margin-bottom:10px;text-align:center;">'+msgH1+'</h1>');
		}
	}
	else {
		id = $('#HIDEVAL').html();
		preval = $('#TD'+id).html();
		$('#preview').click();
		$("#worldcatMsg").html('');

		if(menuActive=="Books"){document.log=true;}
	
		preval =preval.replace('<p class="citation_style_APA">','');
		preval =preval.replace('<p class="citation_style_HARVARD">','');
		preval =preval.replace('<p class="citation_style_MLA">','');
		preval =preval.replace('<P class=citation_style_APA>','');
		preval =preval.replace('<P class=citation_style_HARVARD>','');
		preval =preval.replace('<P class=citation_style_MLA>','');
		
		preval =preval.replace('</p>','');
		preval =preval.replace('</P>','');
		
		preval = $.trim(preval);
		//preval = '<div id="citation1" class="citation"><input id="ckbcitation1" class="deletecitation" type="checkbox">'+preval+'</div>';
		
		savePrevPanl1WordCat('bookPanel' , 'svPnl', document.log,preval);

		//$('#svPnl').html(preval);
	}
	return false;
}

function savePrevPanl1WordCat(srcPnlID , destPnlID, log,preval){
	preval = jQuery.trim(preval);

 sectionCat=getSectionName();
  var sortedArr = new Array();
	
        citationCount=0;
        $('.citation').each(function(index)
        {
			
            $("#ckb"+$(this).attr("id")).remove();
            sortedArr[citationCount]= new Array(3);
            sortedArr[citationCount][1] = $(this).html();
			//if(sortedArr[citationCount][1] ==''){sortedArr[citationCount][1]=preval;} 
            sortedArr[citationCount][0] = $(this).text().trim();
            sortedArr[citationCount][2]=  "citation"+parseInt(citationCount+1);
            citationCount++;
      
        });
		
        var cnt=parseInt(sortedArr.length);

        sortedArr[cnt]= new Array(3);
        sortedArr[cnt][1] = getText(srcPnlID);
		if(sortedArr[cnt][1] == ''){
			sortedArr[cnt][1]=preval;
			sortedArr[cnt][0] = preval.trim();
		}else{
        sortedArr[cnt][0] = $("#"+srcPnlID).text().trim();
		}
        sortedArr[cnt][2]="citation"+sortedArr.length;

	   
        citationCount++;

        sortedArr.multiSort(0);
		

        var temp = "";

        
		if(sectionCat=='mla'){
			for (i=0 ; i <= sortedArr.length - 1 ; i++){
          	 temp = temp + "<div style='text-align: left; text-indent: -30px; padding-left: 0px; width: 337px; word-wrap: break-word; white-space: normal; height: auto;' class='citation' id='"+ sortedArr[i][2] +"' ><input type='checkbox' class='deletecitation' id=ckb"+sortedArr[i][2] +" />" + sortedArr[i][1] +"</div>";
		
        	}
		}else{
			for (i=0 ; i <= sortedArr.length - 1 ; i++){
            temp = temp + "<div class='citation' id='"+ sortedArr[i][2] +"' ><input type='checkbox' class='deletecitation' id=ckb"+sortedArr[i][2] +" />" + sortedArr[i][1] +"</div>" ;
			
       		}
		}
	
		
        $("#"+destPnlID).html(temp);

        var resetVar = "reset11";

        if($.trim($("#svPnl").text())!=""){

		var content=temp;
		
      
		content=content.replace(/&nbsp;/g , " ");
		content=content.replace(/&/g , "##");

		
		
            
			$.ajax({
			  type: 'POST',
			  url: base_url+ 'students/scripts/savesession.php',
			  context: document.body,
			  data: "html="+content
			});
			
			try{
				$(".cssform input").spellchecker("remove");
			}
			catch(e){
			}
	
        }
}

function LibraryFind(){
	var hrefs='';
	hrefs = $('#HIDEVAR').html();
	if(hrefs=='') {
		HIDEIN = $('#HIDEIN').html();
		var nwc = $('#chkResultsWCS:checked').length;
		if(nwc==0 && HIDEIN=='WORLDCAT'){
			$("#worldcatMsg").html('Click Citation to proceed with your request');
		}else{
			if(($("#txtSearch1").val()!="") || ($("#txtSearch2").val()!="")){
				msgH1 = 'Click WorldCat search button first';
			}else{
				msgH1 = 'Please enter search criteria';
			}
			$("#main").html('<h1 style="color:#C80000;margin-top:10px;margin-bottom:10px;text-align:center;">'+msgH1+'</h1>');
		}
	}
	else {
		$("#worldcatMsg").html('');
		window.open(hrefs);
	}
	return false;
}



function change_class(obj) {	
	document.getElementById(obj).className ='';
	document.getElementById(obj).className = 'sub current';
	for(k=3;k<=9;k++){
		if(obj!="sub"+k+""){
			$("#typetabs_"+(k-1)+"").css({'display':'none'});
		}else if(obj=="sub"+k){
			$("#typetabs_"+(k-1)+"").css({'display':'block'});
		}
	}
	if(obj!="sub0"){
		$("#typetabs_9").css({'display':'none'});
	}else if(obj=="sub0"){
		$("#typetabs_9").css({'display':'block'});
	}
	
	if(obj!="sub2"){
		$("#typetabs_0").css({'display':'none'});
	}else if(obj=="sub2"){
		$("#typetabs_0").css({'display':'block'});
	}
	//obj.style.className = 'sub active';
}

function default_class(obj) {
	//alert(obj);
	document.getElementById(obj).className = 'sub';
	
	for(vr=0;vr<=9;vr++){
		$("#typetabs_"+vr+"").css({'display':'block'});
	}
	//obj.style.className = 'sub active';
}

function close_div(){
	document.getElementById("amazonadd").style.display="none";
}

function menu_submenu(){
	typetab = document.getElementById("menu_submenu").value;
	if(typetab){
		typetabs = typetab;
	}else{
		typetabs='typetabs_'+0;
	}
	passId(typetabs);
}

function setId(str){
	document.getElementById('menu_submenu').value=str;
	var tid=document.getElementById(str);
	var tabs=tid.getElementsByTagName('a');		
	for (var i=0; i<tabs.length; i++){ 
			tabs[i].className="";
	}
	//alert('2->'+str);
	//passId(str);
	//menu_submenu();
}

function setId2(str,menu,id){
	document.getElementById(selectedid).className='';
	selectedid = menu;
	document.getElementById(menu).className='active';
	document.getElementById("menu_submenu").value=str;
	//menu_submenu();
}

function setId5(){
	document.getElementById(selectedid).className='';
	selectedid = prev_id;
	document.getElementById(prev_id).className='active';
}

var tabmenuid=0;
function setId3(obj,str,menu,id){
	var target=$(obj).find("a").attr("href");
	if($.trim($('#bookPanel').text()) != "")
    {
			jConfirmMod('Do you want to save your current citation?', 'Save Citation','&nbsp;Proceed&nbsp;', function(r7) {
			if(r7) {
				
				var log=document.log;
				if(menuActive=="Books"){
					document.log=true;
				}
				savePrevPanl1('bookPanel' , 'svPnl',document.log);
				if(document.log==true){
					jAlert("Your info has been saved","Alert");						
				}else{
					if(menuActive!="Books"){
						clearPanel('bookPanel');
					}						
				}
				document.log=log;
			}
			else
			{
				clearPanel('bookPanel');
			}
			menuActive=$('.topnav ul .active span').text();						
			$("#previewText").html("");
			var previewText="Your "+menuActive+" sources will be listed below in APA"+
			"(6th Ed.) style as you complete the form fields in the left hand panel.";
			$("#previewText").html(previewText);
		});
	}else{
		menuActive=$('.topnav ul .active span').text();						
		$("#previewText").html("");
		
		var secName4pre = getSectionName();
		var  previewText;
		if(secName4pre == 'apa'){
			 previewText="Your citations with be formatted below in APA (6th Ed.) style as you complete the form fields in the left hand panel.";
		}else if(secName4pre == 'harvard'){
			  previewText="Your citations with be formatted below in Harvard Chicago style as you complete the form fields in the left hand panel.";
		}else if(secName4pre == 'mla'){
			 previewText="Your citations with be formatted below in MLA (7th Ed.) style as you complete the form fields in the left hand panel.";
		}
		//var previewText="Your "+menuActive+" sources will be listed below in APA"+
		//"(6th Ed.) style as you complete the form fields in the left hand panel.";
		
		$("#previewText").html(previewText);
		$("#previewText").removeClass('text');
		$("#previewText").addClass('textP');
	}
	tabmenuid=id;
	document.getElementById(prev_id).className='';
	document.getElementById(selectedid).className='';
	selectedid = menu;
	prev_id=menu;
	document.getElementById(menu).className='active';
	
	document.getElementById("menu_submenu").value=str;
	
	passId(str);	
			
	rigtTabContent('b4');
	return false;
	//menu_submenu();
}

function setId4(str,menu,id){	
	var tabs=document.getElementById(str).getElementsByTagName("a");
	for (var i=0; i<tabs.length; i++){ 
		if(i==id){
			tabs[i].className="selected";
		}
		else
		{
			tabs[i].className="";
		}
	}
	
}

function showHideTab(arrTab, whichShow){
	for (i=0;i<arrTab.length;i++){
		$("#"+arrTab[i]).hide();
	}
	$("#"+arrTab[whichShow]).show();
}

function savenoteseession(){
	theForm=document.forms['quicknotes'];
	if(theForm){
	notegroup = theForm.filename.value;
	notename  = theForm.tagname.value;
	noteurl = theForm.url.value;
	notetext = theForm.text.value;
	
	notegroup=notegroup.replace(/&/g , "@@@");
	notename=notename.replace(/&/g , "@@@");
	noteurl=noteurl.replace(/&/g , "@@@");
	notetext=notetext.replace(/&/g , "@@@");
	//notetext=notetext.replace(/\n/g , "");
	
		
	jQuery.ajax({
			type: "POST",
			url: base_url+"ajax.php",
			data: "type=saveNoteSession&notegroup="+notegroup+"&notename="+notename+"&noteurl="+noteurl+"&notetext="+notetext,
			success: function(msg){
				//jQuery("#b11").html(msg);
			}
		});
	
	}
}
function rigtTabContent(divId){
	//=========
	//alert(divId);
	var args = rigtTabContent.arguments;
	pageURL='';
	tabCaption='';
	exData = '';
	if(args.length==2){
		if(args[1] == 'paypal'){
			exData = "&paypalstatus=Yes";
		}
	}
	
	
	if(args.length==3){
		pageURL = base_url+args[1];
		tabCaption = args[2];
	}
	
	var divIdArr=document.location.href.split("#");
	var hrfId = document.getElementById('tabs1').getElementsByTagName("a");
	arrTab = Array('start','end1','end2','contact','subscribe','expired','profile','footerPagesSpan','feed','thanks');
	if(divId == 'b8'){
		showHideTab(arrTab,1);
		window.scrollTo(0,0);
		savenoteseession();
	}
	else if(divId == 'b9'){
		showHideTab(arrTab,2);
		window.scrollTo(0,0);
		savenoteseession();
	}
	else if(divId == 'b10'){
		showHideTab(arrTab,6);
		var data = msg4Data;
		jQuery.ajax({
			type: "POST",
			url: base_url+"profile.php",
			data: "msg="+data,
			success: function(msg){
				//alert(msg);
				jQuery("#b10").html(msg);
			}
		});
	}
	else if(divId == 'b11'){
		showHideTab(arrTab,3);
		var data = msg4Data;
		jQuery.ajax({
			type: "POST",
			url: pageURL,
			data: "permission=Yes&msg="+data,
			success: function(msg){
				jQuery("#b11").html(msg);
				refreshMenu();
			}
		});
		$("#contact a").html("<span>"+tabCaption+"</span>");
		//return false;
	}
	else if(divId == 'b12'){
		showHideTab(arrTab,4);
		var data = msg4Data;
		jQuery.ajax({
			type: "POST",
			url: base_url+"subscribe.php",
			data: "permission=Yes&msg="+data+""+exData,
			success: function(msg){
				jQuery("#b12").html(msg);
				refreshMenu();
			}
		});
	}
	else if(divId == 'b13'){
		showHideTab(arrTab,5);
		jQuery.ajax({
			type: "POST",
			url: base_url+"expired.php",
			data: "msg=msg",
			success: function(msg){
				jQuery("#b13").html(msg);
			}
		});
	}
	else if(divId == 'b14'){
		showHideTab(arrTab,7);
	}
	else if(divId == 'b15'){
		showHideTab(arrTab,8);
		jQuery.ajax({
			type: "POST",
			url: base_url+"feed.php",
			data: "",
			success: function(data){
				//alert(data);
				jQuery("#b15").html(data);
			}
		});
	}
	else if(divId == 'b16'){
		showHideTab(arrTab,9);
		jQuery.ajax({
			type: "POST",
			url: base_url+"thanks.php",
			data: "",
			success: function(data){
				//alert(data);
				jQuery("#b16").html(data);
			}
		});
	}
	else {
		showHideTab(arrTab,0);
	}
	//=========
	
	//alert(divIdArr+'===='+hrfId); 
	
	for(var i=0; i < hrfId.length; i++)
	{
		//alert(hrfId[i]);
		hrefIdArr=hrfId[i].href.split("#");
		
		if(hrefIdArr[1]==divId)
		{
			//alert(hrefIdArr[1]);
			hrfId[i].className="active";
			//$("#"+hrefIdArr[1]).addClass('tabContent');
			document.getElementById(hrefIdArr[1]).className="tabContent";
			//alert(hrefIdArr[1]);
		}
		else
		{
			//alert('nt-'+hrefIdArr[1]);
			hrfId[i].className=" ";
			$("#"+hrefIdArr[1]).addClass('tabContent');
			$("#"+hrefIdArr[1]).addClass('hide');
			//document.getElementById(hrefIdArr[1]).className="tabContent hide";
		}
	}
	if(divId=="b6"){
		$("#b6 .content-bottom").css("padding-left","20px");		
	}else{
		makeULCenter(divId);
	}
	
	
	if(divId=='b5'){
		document.getElementById('ifrmid').src = document.getElementById('ifrmid').src;
	}
	return false;
}

function rigtTabContentLower(divId){
	//=========
	var divIdArr=document.location.href.split("#");
	var hrfId = document.getElementById('tabs2').getElementsByTagName("a");
	//=========
	
	for(var i=0; i < hrfId.length; i++)
	{
		hrefIdArr=hrfId[i].href.split("#");
		//alert(hrefIdArr[1]);
		if(hrefIdArr[1]==divId)
		{
			//alert(hrefIdArr[1]);
			hrfId[i].className="active";
			document.getElementById(hrefIdArr[1]).className="tabContent";
		}
		else
		{
			//alert('nt-'+hrefIdArr[1]);
			hrfId[i].className=" ";
			document.getElementById(hrefIdArr[1]).className="tabContent hide";
		}
	}
	
	return false;
}

function prevMenu(menu){
	document.getElementById(menu).className='';
	document.getElementById(prev_id).className='active';
}

var selectedid ='menu';
var prev_id=selectedid;

function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function randomVideo(){
	//format for calling pop up window

	var totalArgs = randomVideo.arguments;
	
	videos = new Array(2);
	/*videos[0] = 'pH6OrkOH8Y8';
	videos[1] = 'CUpDNxEXd7s';
	videos[2] = 'pcbQpi97XHs';
	videos[3] = 'pcbQpi97XHs';
	videos[0] = 'pcbQpi97XHs';
	videos[1] = 'pcbQpi97XHs';*/
	
	var ranNum = Math.floor(Math.random());
	//alert(ranNum)
	if(totalArgs.length == 1){
		if(totalArgs[0] == ranNum){
			if(ranNum == 0 ) ranNum = ranNum +1;		
		}
	}
//alert(ranNum)
	/*var movielink;
	movielink = "http://www.youtube.com/v/" + videos[ranNum] + "&rel=0";
	
	var mainlink = "";
	mainlink = "<object width='360' height='290'>";
	mainlink = mainlink + "<param name='wmode' value='transparent'></param>";
	
	mainlink = mainlink + "<embed src='" + movielink + "' type='application/x-shockwave-flash' wmode='transparent' width='360' height='290'>";
	mainlink = mainlink + "</embed>";
	mainlink = mainlink + "</object>";*/

	if(ranNum == 0){
			mainlink= '<iframe src="http://www.slideshare.net/slideshow/embed_code/11167684" class="inline14" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" id="ifrmid"></iframe>';	
	}
	
	if(ranNum == 1){
		mainlink= '<iframe src="http://www.slideshare.net/slideshow/embed_code/521977" class="inline14" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>';	
	}
	
	mainlink = mainlink + '<p style="padding-bottom:0px; display:none"><a id="nextbtn" href="#" onclick="return nextVideo('+ranNum+');">Next</a></p>';
	document.getElementById('movietext').innerHTML = mainlink;
	
	return false;
}

function nextVideo(lastVid){
	randomVideo(lastVid);
	return false;
}

function updateProfile(){
	$.ajax({
		type: "POST",
		url: base_url+"profile.php",
		data: getFormData("sitelokmodify"),
		success: function(data){
			//alert(data);
			$("#pProfileUpdate").html(data);
		}
	});
	return false;
}

function afterRegister(data){
	//alert(data);
	//alert(document.fblog + "\n"+document.log);
	if(document.fblog==true){
		alert(data);
		window.location.reload();
	}else{
		if(data == 'Registration Successful'){
			alert(data + "\n" + "Please check your email for Password");
			rigtTabContent('b8');
		}else{
			alert(data);
			return false;
		}
		
		
		
	}
}

function afterMail(data){
	alert(data);
	$("#errPL").html(data);
	//$("#b8 .text").html(data);
	//dhtml ='<ul class="buttnav inline27" style="padding-left: 141px;"><li><a onclick="return backLoginContent();" href="#b5"><span>Back</span></a></li></ul>';
	//$("#b8 .content-bottom").html(dhtml);

return false;
}

function backLoginContent(){
	$("#b8 .text").html('');
	dhtml ='<ul class="buttnav inline27" style="padding-left: 141px;"><li class="active"><a class="inline4" onclick="submitLoginPanel();"><span>Login</span></a></li><li><a class="inline4" onclick="return resetLoginPanel(\'siteloklogin\');"><span>Reset</span></a></li><li><a onclick="return rigtTabContent(\'b5\');" href="#b5"><span>Back</span></a></li></ul>';
	$("#b8 .content-bottom").html(dhtml);
	return false;
}

function refreshMenu(){
	$.ajax({
		type: "POST",
		url: base_url+"ajax.php",
		data: "type=islogin",
		success: function(data){
			$("#islogin").html(data);
			$("#SearchheadLog").html(data);
			$("#StyleheadLog").html(data);
			$("#InsHeadLog").html(data);
			$("#LibHeadLog").html(data);
			$("#SubHeadLog").html(data);
			
		}
	});
	
	$.ajax({
		type: "POST",
		url: base_url+"ajax.php",
		data: "type=menu",
		success: function(data){
			$("#divMainMenu").html(data);
		}
	});	
	
}

function resetLoginPanel(formid){
	
	$('#'+formid).each(function(){			
			this.reset();
	});
	return false;
}

function submitLoginPanel(){
	var a = validatelogin();
	if(a==true){
		return doLogin();
	}else{
		return false;
	}
}

function setupCopy(){
	clip22 = new ZeroClipboard.Client();
	clip22.setHandCursor( true );
	clip22.glue( 'd_clip_button1', 'd_clip_container1');
	
	clip22.addEventListener('mouseOut', function (client) {
		//alert('111');
		$("#dummyHTML").css( { "left": "0px", "top":"0px" } );
		$("#copyLi").removeClass("active");
	});
}

function savePrevPanl(srcPnlID , destPnlID,obj){
	
	var log=document.log;
	if(menuActive=="Books")
	{
		document.log=true;
	}
	
	savePrevPanl1(srcPnlID , destPnlID, document.log);
	
	saveIntextpreview(srcPnlID,destPnlID,document.log);
	
	if(document.log==true){
		jAlert("Your info has been saved","Alert");	
		if($("#aWorldcatSearch").hasClass("active")==true){
			$("#preview").click();
		}
		//if($('.topnav ul .active span').text()=="Books"){
			document.publication.reset();
			window.location.href=obj.href;	
		//}
	}
	
	document.log=log;
}

function CopyToClipBoard(whatToCopy,OverOut){
	
	//alert(OverOut);
	if(whatToCopy==2){
		if(OverOut == "Over"){
			//$("#copyLi").html($("#dummyHTML").html());
			$("#copyLi").addClass("active");
			var pos = $("#copyLi").offset();  
  			var width = $("#copyLi").width();
			var height = $("#copyLi").height();
			
			$("#dummyHTML").css( { "left": (pos.left) + "px", "top":pos.top + "px" , "width":width + "px" , "height":height + "px" } );
 			$("#d_clip_button1 span").hide();
			
			var n = $('.deletecitationbody:checked').length;
			if(n>0) {
			var content="";
			$('.deletecitationbody:checked').parent().each(function(index){
																	
			//$('#c8Content .citation').each(function(index)
			//{
					content=content+$.trim($(this).text())+"\r\n \r\n";
			//});
			
			})
			clip22.setText(content);
			}else{
				var contents = '';
				clip22.setText(contents);
				clip22.addEventListener('Complete', function () {
					if($('.deletecitationbody:checked').length <= 0){
							jAlertMod("Click the checkbox alongside citations before using Copy.","Alert","&nbsp;OK&nbsp;",null);
					}
				});
				return false;
			}
		}
		
	}
}

function ask4save(target){	
	//alert('111');
	if($.trim($('#bookPanel').text()) != "")
    {
			jConfirmMod('Do you want to save your current citation?', 'Save Citation','&nbsp;Proceed&nbsp;', function(r7) {
			if(r7){	
					var log=document.log;
					if(menuActive=="Books")
					{
						document.log=true;
					}
					
					savePrevPanl1('bookPanel' , 'svPnl',document.log);
					
					saveIntextpreview('bookPanel','svPnl',document.log);
					
					if(document.log==true){
						jAlert("Your info has been saved","Alert");
					}else{
						if(menuActive!="Books"){
							clearPanel('bookPanel');
						}					
					}
					document.log=log;
					
					window.location.href=target;    
					return true;
				}
				else {
		            clearPanel('bookPanel');			
					window.location.href=target;    
					return true;
				}
			});		
	}
	
	if($.trim($('#bookPanel').text()) == "")
	{
		window.location.href=target;    
		return true;
	}
	return false;	
}

function randomAd(){
	//format for calling pop up window
	arrAd = new Array(2);
	arrAd[0] = '<a href="http://itunes.apple.com/app/icite-apa/id429178021?mt=8" target="_blank"><img src="'+base_url+'students/images/banner.jpg"  alt="" style="margin-left:5px;"/></a>';
	arrAd[1] = '<a href="https://market.android.com/details?id=com.icite.writecite&feature" target="_blank"><img src="'+base_url+'students/images/i-cite_ad.jpg"  alt="" style="margin-left:5px;"/></a>';
	$('#divAds').html(arrAd[Math.floor(Math.random()*arrAd.length)]);
	return false;
}

function funcTranslate(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	if (browser=="Microsoft Internet Explorer")
	{
		document.write ('<div id="MicrosoftTranslatorWidget" style="margin-left:5px;width: 400px; height: 57px; border: 0; background-color: #78ADD0;">');
		document.write ('<noscript>');
		document.write ('<a href="http://www.microsofttranslator.com/BV.aspx?a=http%3a%2f%2fwww.writecite.com%2f">');
								
		document.write ('Translate this page</a><br />Powered by ');
		document.write ('<a href="http://www.microsofttranslator.com">Microsoft® Translator</a></noscript></div>');
		document.write ('<script id="MicrosoftTranslatorWidgetScript" type="text/javascript" src="http://api.microsofttranslator.com/V1/Widget.svc/Embed?appId=XrWFbhuPPC9Gar00TJ32Pth03oW2jLad&amp;from=en&amp;layout=ts"></script>');
	
	}
	else
	{
		document.write ('<div id="google_translate_element" style="margin-left:5px;width: 400px; height: 53px; border: 0; background-color: #78ADD0; text-align:center;"></div><script>');
		document.write ('function googleTranslateElementInit() {');
		document.write ('  new google.translate.TranslateElement({');
		document.write ("    pageLanguage: 'en'");
		document.write ("  }, 'google_translate_element');");
		document.write ('}');
		document.write ('</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>');
	}
}

function passId(typetabs){
	//typetab = typetabs;
	//alert(typetabs);
		//typetab=typetabs1;
	//alert('3->'+typetabs);
	var countries=new ddajaxtabs(typetabs, "publicationtype");
	countries.setpersist(false);
	countries.setselectedClassTarget("link"); //"link" or "linkparent"
	countries.init();
}

function showPage(pageName)
{
	if(pageName=="registerusages")
	{
		var onclick_var="return rigtTabContent('b9');";
		pageName="Usage";
	}
	else
	{
		var onclick_var="return rigtTabContent('b4');";
	}
	
	//return fireAjaxRequest('scripts/showAllNotes_test.php','','formatHL=apa','aa1','','CN');
	rigtTabContent('b14');
	fireAjaxRequest('pages/'+pageName+'.txt','','','b14 .text','','');
	$('#b14 .content-bottom').html("<ul class='buttnav'><li class='active1'><a onclick=\""+onclick_var+" \" href=\"#\" class=\"active\" id=\"citenotes\"><span>Back</span></a></li></ul>");
	$('#footerPagesSpan a span').html(pageName);
	$('#footerPagesSpan').show();
	$('#footerPagesSpan').focus();
	makeULCenter('b14');
	return false;
	//return false;
}


$(document).ready(function(){
						   
			  
	$('.sub a').hover(function()
  {			
   clicked = $(this);
   //var default=null;
   //var cust_id=$(this).parent().parent().attr('id');
     if(!clicked.hasClass('selected'))
     {
	 $(this).addClass('customized');
     }
   },function()
  {
 	    $(this).removeClass('customized');
  });
  
	var menuid=getUrlVars()["s"];
	
	if(menuid==0 || menuid==null)
	{
		$('.nav ul li').removeClass('active');
		$('#menu').addClass('active');
	}
	else
	{
		$('.nav ul li').removeClass('active');
		$('#menu'+menuid).addClass('active');
	}
	
	
	menuActive=$('.topnav ul .active span').text();
	var submenuActive=$('.active .sub li:first a').addClass('selected');
	var submenuActive=$('.active .sub li:first a').text();
	

	var tabsMenu=$('#tabs li .active').text();

	$('#currentPage').html(tabsMenu+" / "+menuActive+" / "+submenuActive);
	
	
	var base_url1=window.location;
	
	if(base_url1.toString().search('index.php')>0)
	{
		$("#previewText").html("");
		var previewText="Your "+menuActive+" sources will be listed below in APA"+
		"(6th Ed.) style as you complete the form fields in the left hand panel.";
		$("#previewText").html(previewText);
	}
	
	$('.sub li a').click(function(){
		var menuActive=$('.topnav ul .active span').text();
		$('.sub li a').removeClass('selected');
		$(this).addClass('selected');
		var submenuActive=$('.sub li .selected').text();
		var tabsMenu=$('#tabs li .active').text();
		$('#currentPage').html(tabsMenu+" / "+menuActive+" / "+submenuActive);
	});
	
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight').click(function(){			   
		if($.trim($("#svPnl").text())!="")
		{
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
	
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="'+base_url+'students/images/close_pop.gif" class="btn_close" title="Close Window" alt="Close" /></a>');
	
		//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
	
		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
		return false;
	}
	    else{
		   	jAlertMod("No citation found. Save your citation(s) first.","Alert","&nbsp;OK&nbsp;",null);
		}
	
    }
	);

	$('a.poplight2').click(function(){	
	var n = $('.chkIntext:checked').length;
	if(n>0) {  
		//if($.trim($("#svPnl").text())!=""){
			
			var popID = $(this).attr('rel'); //Get Popup Name
			var popURL = $(this).attr('href'); //Get Popup href to define size
		
			//Pull Query & Variables from href URL
			var query= popURL.split('?');
			var dim= query[1].split('&');
			var popWidth = dim[0].split('=')[1]; //Gets the first query string value
		
			//Fade in the Popup and add close button
			$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="'+base_url+'students/images/close_pop.gif" class="btn_close" title="Close Window" alt="Close" /></a>');
		
			//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
			var popMargTop = ($('#' + popID).height() + 80) / 2;
			var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
			//Apply Margin to Popup
			$('#' + popID).css({
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});
	
			//Fade in Background
			$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
			$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
			return false;
		//}
	    //else{
		//   	jAlertMod("No citation found. Save your citation(s) first.","Alert","&nbsp;OK&nbsp;",null);
		//}
	}else{
		if(!$('#intext_content').html()){
			jAlertMod("Click save at foot of form before using Email.","Alert","&nbsp;OK&nbsp;",null);
		}else{
			jAlertMod("Click the checkbox alongside in-text before using Email.","Alert","&nbsp;OK&nbsp;",null);
		}
		
		return false;
	}
	
    }
	);
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  //fade them both out
		});
		return false;
	});
	
	//init();	
	DetectSection();
	DetectSection2();
	randomVideo();

	var secName4Ad = getSectionName();
	if(secName4Ad == 'apa'){
		randomAd();
	}
	
	refreshMenu();
	
	if(menuActive!="Books"){
		rigtTabContent('b4');
	}else{		
		rigtTabContent('b6');
	}
	

	$('.active .sub li:first a').click();
	

    var hashes2 = window.location.href.slice(window.location.href.indexOf('/students/') + 10).split('/');
	//alert(hashes2);
	if(menuid > 0 || menuid!=null || hashes2 =='harvard,' || hashes2 =='apa,' || hashes2 =='mla,'){
		//$('#preview').click();
		//$('#aWorldcatSearch').click();
		$('#ins').click();
	}else{
		//by default display tab
		//$('#aWorldcatSearch').click();
		$('#ins').click();
	}
	
	
	//if(menuid==0 || menuid==null){ $('#ins').click();}
	//else{$('#preview').click();}
	//menu_submenu();

	if(document.log==false && document.fblog==true){
		rigtTabContent('b9');
	}
	
	$("#aCheckSpell1").click(function(e){
		callCheckSpell(e,2);
	});
	
	//$('#tabs li:first').addClass('imgLI');
	//$('#tabs1 li:first').addClass('imgLI');
});
