﻿
/* --------------------------------------------------------------------------------
 * Client Name: National Quality Forum
 * Project Name: New Website Implemenation 
 * Module: JS
 * Name: Common.js
 * Purpose: Common javascript funciton
 *                   
 * Author: MHA
 * Language: C# SDK version 2.0
 * --------------------------------------------------------------------------------
 * Change History:
 *  version: 1.0    MHA  05/11/09
 *  Description: Initial Development
 * -------------------------------------------------------------------------------- */


///Region Global Variable
var fontStatus="="; /// '<' means less '>' means large
var cookieName="NQFCookie"
var originalFontSize="12";
var originalFontSizeNum=12;
///Endregion


/// Jquery section code begins
$(document).ready(function(){
  // Reset Font Size
  var cookieValue = readCookie(cookieName);
  //console.log("cookieValue="+cookieValue);
  if(cookieValue)
  {
     $('#mainContentBlock').css('font-size', parseInt(cookieValue, 10));
  }
  
  //console.log("current font size="+$('#mainContentBlock').css('font-size'));
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('#mainContentBlock').css('font-size');
    var currentFontSizeNum = parseInt(currentFontSize, 10);
    ///11-10 =1  10-10=0 9-10=-1
    
    var diff = currentFontSizeNum-originalFontSizeNum;
    
    if(diff==0 || diff==-1)
    {  
     var newFontSize = ++currentFontSizeNum;
     $('#mainContentBlock').css('font-size', newFontSize);
     eraseCookie(cookieName);
     createCookie(cookieName,newFontSize,1);
     //console.log("++newFontSize="+newFontSize);
    }
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('#mainContentBlock').css('font-size');
    var currentFontSizeNum = parseInt(currentFontSize, 10);
    /// 11-10=1 10-10=0 9-10=-1
    var diff = currentFontSizeNum-originalFontSizeNum;
   if(diff==0 || diff==1)
    {  
     var newFontSize = --currentFontSizeNum;
     $('#mainContentBlock').css('font-size', newFontSize);
     eraseCookie(cookieName);
     createCookie(cookieName,newFontSize,1);
      //console.log("--newFontSize="+newFontSize);
    }
    return false;
  });
});
///Jquery code ends

/// Cookie code begins
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=/";
}

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);
}

/// Cookie code ends


//Pop up function begins
function popup(url,width,height) 
{
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 ///params+=',location,resizable,scrollbars'
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}
//Pop up function ends
function ExpandDiv(dvID, currentObj)
{
    //alert(dvID);
    var dvObj=document.getElementById(dvID);
    //alert(dvObj.style.display);
    //alert(currentObj);
    if(dvObj.style.display=='none')
    {
        dvObj.style.display='block';
        currentObj.innerHTML='[-]';
    }
    else
    {
        dvObj.style.display='none';
        currentObj.innerHTML='[+]';
    }
}

function ExpandImageDiv(dvID, currentObj)
{
    
    
    var dvObj=document.getElementById(dvID);
   
    if(dvObj.style.display=='none')
    {
        dvObj.style.display='block';
        currentObj.innerHTML='<img src="/images/commonImages/minusYellow.gif" style="cursor:pointer"  alt="Minus Icon" border="0" align="middle" title="Minus Icon" />';
    }
    else
    {
        dvObj.style.display='none';
        currentObj.innerHTML='<img src="/images/commonImages/plusYellow.gif" style="cursor:pointer"  alt="Plus Icon" border="0" align="middle" title="Plus Icon" />';
    }
}