/*
@author: Hasan Rashid
Date: 6/22/2008
Description: Function needed in MF pages
*/

function links(url, properties)
{
	if (!properties) {
		properties = 'scrollbars=yes';
	}
	window.open(url, '', properties);
}

/*
@author: Hasan Rashid
Date: 6/22/2008
Description: Open up page for counsellors
*/
function email_counsellor_page(id)
{
	if(!isNaN(id))
	{		
		newwin=window.open('mc_email.php?page_id='+id,'emailwin','left=100,top=100,width=400,height=200,resizable=1');
	}
	else return;
}
/*
@author: Hasan Rashid
Date: 6/22/2008
Description: Email related articles for counsellors
*/

function email_ra_page(id)
{
	if(!isNaN(id))
	{		
		newwin=window.open('mc_email.php?id='+id,'emailwin','left=100,top=100,width=400,height=200,resizable=1');
	}
	else return;
}

function email_page(id, page)
{
	if(!isNaN(id))
	{		
		newwin=window.open('emailer_cs.php?page_id='+id+'&type='+page,'emailwin','left=100,top=100,width=400,height=200,resizable=1');
	}
	else return;
}
/*
@author: Hasan Rashid
Date: 6/22/2008
Description: print window text
*/

function printContent(id){
	str=document.getElementById(id).innerHTML
	newwin=window.open('','','left=100,top=100,width=5,height=5,toolbars=0');
	newwin.document.write('<HTML>\n<HEAD>\n');
	newwin.document.write('<TITLE>Print Page</TITLE>\n');
	newwin.document.write('<script>\n');
	newwin.document.write('function chkstate(){\n');
	newwin.document.write('if(document.readyState=="complete"){\n');
	newwin.document.write('window.close()\n');
	newwin.document.write('}\n');
	newwin.document.write('else{\n');
	newwin.document.write('setTimeout("chkstate()",1000)\n');
	newwin.document.write('}\n');
	newwin.document.write('}\n');
	newwin.document.write('function print_win(){\n');
	newwin.document.write('window.print();\n');
	newwin.document.write('chkstate();\n');
	newwin.document.write('}\n');
	newwin.document.write('<\/script>\n');
	newwin.document.write('</HEAD>\n');
	newwin.document.write('<BODY onload="print_win()">\n');
	newwin.document.write(str);
	newwin.document.write('</BODY>\n');
	newwin.document.write('</HTML>\n');
	newwin.document.close();
//    newwin.focus(); 
    if (window.print)
	{
		newwin.print(); 			
		newwin.close();
	}
}
/*
@author: Hasan Rashid
Date: 6/22/2008
Description: increase decrease font
*/

function increaseFontSize() {
var min=8;
var max=18;

var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
var ul = document.getElementsByTagName('li');
   for(i=0;i<ul.length;i++) {
      if(ul[i].style.fontSize) {
         var s = parseInt(ul[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      ul[i].style.fontSize = s+"px"
   }   
}
function decreaseFontSize() {
var min=8;
var max=18;

var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
var ul = document.getElementsByTagName('li');
   for(i=0;i<ul.length;i++) {
      if(ul[i].style.fontSize) {
         var s = parseInt(ul[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      ul[i].style.fontSize = s+"px"
   }      
}
// ***************************************************************************************
function process_message(message)
{
	if (message)
	{
		alert(message);
	}
}

function popup(url, properties)
{
	if (!properties) {
		properties = 'scrollbars=yes';
	}
	window.open(url, '', properties);
}

function exitdemo() {
	parent.window.close();
	window.close();
}

function navigateInOpener(url)
{
	self.opener.document.location = url;
}

function switchFrench() {
	var actLoc = window.location.toString();
	var position = actLoc.lastIndexOf("/");
	var newURL = actLoc.substr(0,position) + '/french' + actLoc.substr(position);
	window.location = newURL;
}

function showRLE()
{
	document.all('rle').style.display = '';
}

function hideRLE()
{
	document.all('rle').style.display = 'none';
	document.all('rle_link').style.display = '';
}

function watchForEnter()
{
	if (window.event.keyCode == 13)
	{
		go_button.click();
	}
}

function watchForEnter2()
{
	if (window.event.keyCode == 13)
	{
		go_button2.click();
	}
}

function email_this_page()
{
	var email = prompt('Please enter your email address below. A link for this page will be sent to the email address.', '@');
	var url = document.location;

	if (!email)
	{
		return;
	}

	document.location = 'emailer.php?email=' + escape(email) + '&url=' + escape(url) + '&fullscreen=false' + '&width=' + (document.body.clientWidth + 24);
}

function email_this_page_fullscreen()
{
	var email = prompt('E-mail address:', '@');
	var url = document.location;

	if (!email)
	{
		return;
	}

	document.location = 'emailer.php?email=' + escape(email) + '&url=' + escape(url) + '&fullscreen=true';
}
function edit_profile()
{
	popup('edit-profile.php', 'width=430,height=520,left=150,top=150,resizable=yes');
}

function help_online()
{
	popup('help.php', 'width=500,height=500,left=150,top=100,resizable=yes,scrollbars=1');
}

function faq()
{
	popup('faq.php', 'width=450,height=300,left=150,top=50,resizable=yes,scrollbars=1');
}

function super_search(url)
{
	popup(url, 'width=450,height=400,left=250,top=150,scrollbars=yes,resizable=yes');
}

function article(url)
{
	popup(url, 'width=450,height=400,left=250,top=150,resizable=yes,scrollbars=yes');
}

function calculator(url, name)
{
	popup('calculator.php?url=' + escape(url) + '&name=' + name, 'width=500,height=400,left=250,top=150,resizable=yes,scrollbars=yes');
}

function calculator2(url, name)
{
	popup('../calculator.php?url=' + escape(url) + '&name=' + name, 'width=500,height=400,left=250,top=150,resizable=yes,scrollbars=yes');
}

function terms_of_use()
{
	popup('terms_of_use.php', 'width=485,height=500,resizable=yes,scrollbars=yes');
}

function terms_of_use2()
{
	popup('_en/terms_of_use.php', 'width=485,height=500,resizable=yes,scrollbars=yes');
}


function ic_tutorial(url, module_name, tutid)
{
		popup(url + '&tutid=' + tutid + '&module_name=' + module_name, 'width=860,height=400,left=50,top=50,resizable=yes');
}

function ic_tutorialen(url, module_name)
{
	var url_change;
	url_change	=	url.replace(".html",".php");
//	alert(url_change);
	popup(url_change + '&module_name=' + module_name, 'width=700,height=400,left=50,top=50,resizable=no');
}

function ic_tutorialf(url, module_name)
{
	var url_change;
	url_change	=	url.replace(".html",".php");
//	alert(url_change);
	popup(url_change + '&module_name=' + module_name, 'width=893,height=400,left=50,top=50,resizable=yes,scrollbars=yes');
}

function ff_game(url, name)
{
	popup('ff_game.php?url=' + escape(url) + '&name=' + name, 'width=700,height=400,left=50,top=50,resizable=yes');
}

function mpp_tutorial(url)
{
	popup(url, 'width=600,height=400,left=50,top=50,resizable=yes');
}

function mpp_article(url)
{
	popup(url, 'width=450,height=450,left=50,top=50,resizable=yes,scrollbars=yes');
}

function mpp_download(url)
{
	popup(url, 'width=450,height=450,left=150,top=150,resizable=yes');
}

function relevant_download(url, name)
{
	popup(url, 'width=450,height=400,left=250,top=150,resizable=yes,scrollbars=yes');
}

function relevant_term(url)
{
	popup(url, 'width=450,height=400,left=250,top=150,resizable=yes,scrollbars=yes');
}

function mini_library(url)
{
	popup(url, 'width=500,height=400,left=150,top=100,resizable=yes,scrollbars=yes');
}

function glossary()
{
	alert('This feature is unavailable in the demo version of iAcquaint');
}

function forgot_password(email)
{
	if (!email)
	{
		return;
	}

	document.location = 'login.php?action=send-password&email=' + escape(email);
}

function show_forgot_password_form()
{
	document.all('ForgotPasswordForm').style.display = '';
}

function nocontent() {
	alert('This feature is unavailable in the demo version of iAcquaint');
}

function print_in_popup(id)
{
	alert('This feature is unavailable in the demo version of iAcquaint');
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v3.0
  //Copyright 1998 Macromedia, Inc. All rights reserved.
  var i,j,aLayer,retVal,curDrag=null,NS=(navigator.appName=='Netscape'), curLeft, curTop;
  if (!document.all && !document.layers) return false;
  retVal = true; if(!NS && event) event.returnValue = true;
  if (MM_dragLayer.arguments.length > 1) {
    curDrag = MM_findObj(objName); if (!curDrag) return false;
    if (!document.allLayers) { document.allLayers = new Array();
      with (document) if (NS) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
        for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
          with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
      } else for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];}
    curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
    curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
    curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
    curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
    curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
    curDrag.MM_oldZ = (NS)?curDrag.zIndex:curDrag.style.zIndex;
    curLeft= (NS)?curDrag.left:curDrag.style.pixelLeft; curDrag.MM_startL = curLeft;
    curTop = (NS)?curDrag.top:curDrag.style.pixelTop; curDrag.MM_startT = curTop;
    curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop -cU;
    curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop +cD;
    curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
    document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
    if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  } else {
    var theEvent = ((NS)?objName.type:event.type);
    if (theEvent == 'mousedown') {
      var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
      var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
      var maxDragZ=null; document.MM_maxZ = 0;
      for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
        var aLayerZ = (NS)?aLayer.zIndex:aLayer.style.zIndex;
        if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
        var isVisible = (((NS)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
        if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
          var parentL=0; var parentT=0;
          if (!NS) { parentLayer = aLayer.parentElement;
            while (parentLayer != null && parentLayer.style.position) {
              parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
              parentLayer = parentLayer.parentElement; } }
          var tmpX=mouseX-(((NS)?pageX:style.pixelLeft+parentL)+MM_hLeft);
          var tmpY=mouseY-(((NS)?pageY:style.pixelTop +parentT)+MM_hTop);
          var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS)?clip.width :offsetWidth);
          var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS)?clip.height:offsetHeight);
          if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
              || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
      if (curDrag) {
        document.onmousemove = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEMOVE);
        curLeft = (NS)?curDrag.left:curDrag.style.pixelLeft;
        curTop = (NS)?curDrag.top:curDrag.style.pixelTop;
        MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
        document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
        if(curDrag.MM_toFront) {
          eval('curDrag.'+((NS)?'':'style.')+'zIndex=document.MM_maxZ+1');
          if (!curDrag.MM_dropBack) document.MM_maxZ++; }
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mousemove') {
      if (document.MM_curDrag) with (document.MM_curDrag) {
        var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
        var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
        newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
        if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
        if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
        if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
        if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
        MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
        if (NS) {left = newLeft; top = newTop;}
        else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
        if (MM_dragJS) eval(MM_dragJS);
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mouseup') {
      document.onmousemove = null;
      if (NS) document.releaseEvents(Event.MOUSEMOVE);
      if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
      if (document.MM_curDrag) with (document.MM_curDrag) {
        if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
            (Math.pow(MM_targL-((NS)?left:style.pixelLeft),2)+
             Math.pow(MM_targT-((NS)?top:style.pixelTop),2))<=MM_tol) {
          if (NS) {left = MM_targL; top = MM_targT;}
          else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
          MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
        if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
        if(MM_dropBack) {if (NS) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
        retVal = false; if(!NS) event.returnValue = false; }
      document.MM_curDrag = null;
    }
    if (NS) document.routeEvent(objName);
  } return retVal;
}


