﻿/********************************************************************************
*Description           :This file includes common javascripts.                  *
*Version               :1.0.0                                                	*
*Date Created          :23/01/2009                                        	    *
*Created By            :Satish Patel    			                            *   
*Last modified Date    :12/06/2009	                                	        *
*Copyright © 2009 Rigel Networks                                       	        *

* This software is the property of Rigel Networks and its licensors,	        *
* and contains their confidential trade secrets. Use, 			                *
* examination, copying, transfer and disclosure to others, in		            *
* whole or in part, are prohibited except with the express prior	            *
* written consent of Rigel Networks.					                        *
* This is unpublished proprietary source code. The 			                    *
* copyright notice above does not evidence any actual 		                    *
* publication or any intent to publish this source code.		                *
*Change History							                                        *
*date	Description		Name of the Person		                                *	
*										                                        *
*										                                        *
********************************************************************************/
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

function confirm_delete()
{
  if (confirm("Are you sure you want to delete?")==true)
    return true;
  else
    return false;
}

function showhelp(iDiv,iDivContent, iTable, iDivImagePath, iLeft, iTop)
{
    iDiv.style.left = getAbsLeft(iTable) + iLeft + 'px';
    iDiv.style.top = getAbsTop(iTable) + iTop + 'px';
    iDiv.innerHTML = prepareMessageForPopup(iDivContent.innerHTML, 'App_Themes/Default/images/');//
    iDiv.style.display = 'block';        
}
function hidehelp(iDiv)
{   
    iDiv.style.display = 'none';
}

function getAbsLeft(o) 
{
	oLeft = o.offsetLeft
	while(o.offsetParent!=null) {
		oParent = o.offsetParent
		oLeft += oParent.offsetLeft
		o = oParent
    }
    return oLeft
}
function getAbsTop(o) 
{
    oTop = o.offsetTop
	while(o.offsetParent!=null) {
		oParent = o.offsetParent
		oTop += oParent.offsetTop
		o = oParent
	}
    return oTop
}



function prepareMessageForPopup(msg, imagePath)
    {
        var msgString = '';       
        msgString += '<table width="80%" border="0" cellspacing="0" cellpadding="0">';
        msgString += '<tr>';
        msgString += '<td class="Tool_Tip_Img"><img src="' + imagePath + 'tool_bg1.png"  /></td>';
        msgString += '<td class="Tool_Tip_Top"><img src="' + imagePath + 'spacer.gif" width="1" height="20" /></td>';
        msgString += '<td class="Tool_Tip_Img"><img src="' + imagePath + 'tool_bg2.png" /></td>';
        msgString += '</tr>';
        msgString += '<tr>';
        msgString += '<td class="Tool_Tip_Left">';
        msgString += '<img src="' + imagePath + 'spacer.gif" width="20" height="1" />';
        msgString += '</td>';
        msgString += '<td class="Tool_Tip_MidCtn">';
        msgString += '<p>';                         
        msgString += msg;                             
        msgString += '</p>';
        msgString += '<p>&nbsp;</p>';
        msgString += '</td>';
        msgString += '<td class="Tool_Tip_Right">';
        msgString += '<img src="' + imagePath + 'spacer.gif" width="20" height="1" />';
        msgString += '</td>';
        msgString += '</tr>';
        msgString += '<tr>';
        msgString += '<td class="Tool_Tip_Img_1">';
        msgString += '<img src="' + imagePath + 'tool_bg3.png"  width="20" height="20" />';
        msgString += '</td>';
        msgString += '<td class="Tool_Tip_Bottom">';
        msgString += '<p class="Tool_Tip_Btm_Img">';
        msgString += '<img src="' + imagePath + 'tool_line_bottom_image.png" width="60" height="64" />';
        msgString += '</p>';
        msgString += '</td>';
        msgString += '<td class="Tool_Tip_Img_1">';
        msgString += '<img src="' + imagePath + 'tool_bg4.png"  width="20" height="20" />';       
        msgString += '</td>';
        msgString += '</tr>';
        msgString += '</table>';

    return msgString;
    }
    
  
  function setPageHeight()
  {
        var height =  document.documentElement.clientHeight - 182;     
        var browser=navigator.appName;                  
           /*if (browser == "Firefox")
           {
               height = height + 89;                           
           }
           if (browser == "Netscape")
           {
           
               height = height + 89;                           
           }*/
           /*else
           {               
               document.getElementById('divMasterContainer').style.height = height.toString();
           } */     
        document.getElementById('tdDivMasterContainer').style.height =  height.toString() + 'px'; 
  }
  
  
function formatPhoneNumber(e,obj, iSelectedCountryIndex)
{
if(iSelectedCountryIndex <=2) //if selected country is us or canada
    {
        var firstChr = obj.value.substring(0,1);
        if(firstChr != '(')
            {
                if((obj.value.length == 3 || obj.value.length == 7) && (e.keyCode != 46 && e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 39))
                    {
                        if(e.keyCode != 109)
                            obj.value = obj.value + "-";
                    }
            }
        else
            {
                if((obj.value.length == 4) && (e.keyCode != 46 && e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 39))
                    {
                        if(e.keyCode != 109)
                            obj.value = obj.value + ")";
                    }
                else if((obj.value.length == 8) && (e.keyCode != 46 && e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 39))
                    {
                        if(e.keyCode != 109)
                        obj.value = obj.value + "-";
                    }
            }    
 
        /*if(iSelectedCountryIndex > 2) //other than us and canada
        {if(obj.value.length < 21){return true;}else{if(e.keyCode == 46 || e.keyCode == 8 || e.keyCode == 37 || e.keyCode == 39)
        {return true;}else{return false;}}}
        else */
     if(e.keyCode == 46 || e.keyCode == 8 || e.keyCode == 37 || e.keyCode == 39)
        {    
        return true;
        }
     else if(firstChr != '(' && obj.value.length == 12)
        {
            if(e.keyCode == 9)//tab
                return true;
            else 
                return false;
        }
     else if(firstChr == '(' && obj.value.length == 13)
        {
        if(e.keyCode == 9)//tab
                return true;
            else 
                return false;
        }
    else
        {    
        return true;
        }
    
    }
} 


function showQualityCheckToolTip(){        
        return overlib('<span background-color:#ffffff> The Quality Checkmark is your assurance that this consultant has submitted at least three references for your review.</span>',FGCOLOR,'#F4EFDC',TEXTSIZE,"12px");
        }
function hidToolTip(){
        return nd();
        }
function showToolTip(msg){        
        return overlib('<span background-color:#ffffff>' + msg + '</span>',FGCOLOR,'#F4EFDC',TEXTSIZE,"12px");
        }
        

//START - Changes by satish on 08/03/2009 for CF-56
function openPageFromConsultant(iPageName)
{
    if(location.href.toLowerCase().indexOf('/consultant/') > -1)
    {
        if(confirm("For accessing this page you need to logout.\nClick 'OK' to proceed."))
            {
            location.href = "../" + iPageName;
            return true;
            }
        else
            return false;
    }
    else
    {
        location.href = iPageName;        
        return true;
    }    
}
//END - Changes by satish on 08/03/2009 for CF-56

//START - Changes by satish on 08/03/2009 for CF-93
function openPageFromRegisteredConsultant(iPageName)
{
    if(location.href.toLowerCase().indexOf('/registeredconsultant/') > -1)
    {
        if(confirm("For accessing this page you need to logout.\nClick 'OK' to proceed."))
            {
            location.href = "../" + iPageName;
            return true;
            }
        else
            return false;
    }
    else
    {
        location.href = iPageName;        
        return true;
    }    
}
//END - Changes by satish on 08/03/2009 for CF-93

//START - Changes by satish on 08/03/2009 for CF-49
function notifyForLogoutOnEmailChange( newvalue, oldvalue)
{
if(newvalue != oldvalue)
    if(confirm("You will be logged out as you have changed your Username/Email. Please login using new Email."))
        return true;
    else
        return false;    
else 
    return true;
}
//END - Changes by satish on 08/03/2009 for CF-49

//START - Changes by satish on 08/03/2009 for CF-
function hideVolatileDiv()
{
var obj = document.getElementById('divVolatileMessage');
if(obj != null)
{
//obj.style.display = 'none';
//setObject();
shiftOpacity('divVolatileMessage',2000);
}
}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
    var obj = document.getElementById('divVolatileMessage');
    if(obj != null)     
    obj.style.display = 'none';
    //opacity(id, 0, 100, millisec);        
    } else {
        opacity(id, 100, 0, millisec);
    }
} 
//END - Changes by satish on 08/03/2009 for CF-