﻿
function CheckString(inString)
{
  inString = trim(inString);
  if ((inString=="") || (inString==" ") || (inString==null))
    return false;
  else
    return true;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// Restrict data entry to numbers for a text box not contained 
// Note the handleReturnAsTab argument is optional --
// if unspecified or false, a return is treated as a return; otherwise, a
// return will be treated as a tab.
function numbersOnly(e, handleReturnAsTab)
{
   var key;
   var keychar;

   if (window.event)
      key = window.event.keyCode;
   else if (e)
      key = e.which;
   else
      return true;

   keychar = String.fromCharCode(key);
   var numbers = "0123456789";

   // Treat a return as a tab, if necessary.
   if ( (arguments.length == 2) && (handleReturnAsTab) && ( key == 13) )
      window.event.keyCode = 9;
      
   if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
      return true;
   else if ((numbers.indexOf(keychar) > -1))
   {
      if ((e) && (e.shiftKey))
         return false;
      else if (e)
         return true;
      else if (window.event.shiftKey)
         return false;
      
      return true;
   }
   else
   {
   	  // Cancel any further key press handlers
	  if (e)
	     e.cancelBubble = true;
	  else 
	     window.event.cancelBubble = true;

      return false;
   }   
}

function numbersWithDecimal(e, handleReturnAsTab)
{
   var key;
   var keychar;

   if (window.event)
      key = window.event.keyCode;
   else if (e)
      key = e.which;
   else
      return true;

   //key = keyCode;
   keychar = String.fromCharCode(key);
   var numbers = "0123456789.";

   // Treat a return as a tab, if necessary.
   if ( (arguments.length == 2) && (handleReturnAsTab) && ( key == 13) )
      window.event.keyCode = 9;
      
   if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
      return true;
   else if ((numbers.indexOf(keychar) > -1))
   {
      if ((e) && (e.shiftKey))
         return false;
      else if (e)
         return true;
      else if (window.event.shiftKey)
         return false;
      
      return true;
   }
   else
   {
   	  // Cancel any further key press handlers
	  if (e)
	     e.cancelBubble = true;
	  else 
	     window.event.cancelBubble = true;

      return false;
   }   
}


function NumbersOnlyWithDecimal(keyCode){
    if (!((keyCode >= 48 && keyCode <= 57) ||
			(keyCode >= 96 && keyCode <= 105) || 
			(keyCode >= 35 && keyCode <= 40) || 
			keyCode == 8 || keyCode == 110 ||
			keyCode == 9  || keyCode == 27 ||
			keyCode == 13 || keyCode == 190 ||
			keyCode==144 || keyCode == 46))
	 {
	     return false;
	  }
	else {
	    return true;
	 }
}

function AlphaOnly(e, handleReturnAsTab)
{
   var key;
   var keychar;

   if (window.event)
      key = window.event.keyCode;
   else if (e)
      key = e.which;
   else
      return true;

   keychar = String.fromCharCode(key);
   keychar = keychar.toUpperCase();
   var Alphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";

   // Treat a return as a tab, if necessary.
   if ( (arguments.length == 2) && (handleReturnAsTab) && ( key == 13) )
      window.event.keyCode = 9;
      
   if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
      return true;
   else if ((Alphas.indexOf(keychar) > -1))
      return true;
   else{      
      window.event.cancelBubble = true;
      return false;
     }
  }
  
  //Counts how many times the specified pattern is in the text
// - Returns a number on how many times it is present
function patternCount(stringCheck, pattern)
{
    var result = stringCheck.split(pattern);

    if (result)
        return result.length - 1;
    else
        return 0;
}
  
  function ValidateEmail(emailAddress) { 
    var pattern1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
    if(!pattern1.test(emailAddress)) { 
        //alert("The email address you have is invalid!"); 
        //form.email.focus(); 
        return false; 
       } 
     else
      return true;
}

//Verifies a web address
// - Returns boolean
function isWebAddress(strURL)
{
    var pattern = '';
    
    if (patternCount(strURL, 'http://') == 0)
        if (patternCount(strURL, 'https://') == 0)
        {
                strURL = 'http://' + strURL;
                pattern = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
        }
        else
            pattern = /https:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/; 
    else
        pattern = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/; 
   
     if (pattern.test(strURL))
         return true;
     else
        return false; 
}

//Pass value as string
// - Returns boolean
function isPhone(value)
{
    var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
    
    if (!phoneRe.test(value))
        return false;
    else
        return true;
}

//for ajax
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;
}

//date vaildation ---Lily	
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

//This function return a date object after accepting 
//a date string and dateseparator as arguments
function ConvertDateToNumber(dateString)
{
	
	var dtObject;
	var cDate,cMonth,cYear, FullDate
	
	dtObject = new Date(dateString)
	//extract day portion	
	cDate=dtObject.getDate();
	
	if (cDate < 10){
	    cDate = '0'+cDate;
	}
	
	//extract moth portion
	cMonth=dtObject.getMonth();
	cMonth = cMonth +1;
	if (cMonth < 10){
	    cMonth = '0'+cMonth;
	}
    
	//extract year portion				
	cYear=dtObject.getFullYear();
	
	//make fulldate as string
	FullDate = '' + cYear + cMonth + cDate;
	return FullDate;
}

//------------------------------------------------------------------------------------
//Dialog Screen Functions 
//fnSetDialogValues sets the values for the look and feel of the Dialog box.
function fnSetDialogValues(height, width){
	var iHeight=height;
	var iWidth=width;
	var dialogTop="";
	var dialogLeft="";
	var dialogEdge="Raised";
	var dialogCenter="Yes";
	var dialogHelp="No";
	var dialogResize="No";
	var dialogStatus="No";
	var dialogScrollbar="No";
	
	/*if (isBrowserIE6()){
	    iHeight = iHeight + 55;
	}*/

	var sFeatures="dialogHeight: " + iHeight + "px;";
	sFeatures=sFeatures + "dialogWidth: " + iWidth + "px;";
	sFeatures=sFeatures + "dialogTop: " + dialogTop + "px;";
	sFeatures=sFeatures + "dialogLeft: " + dialogLeft + "px;";
	sFeatures=sFeatures + "edge: " + dialogEdge + ";";
	sFeatures=sFeatures + "center: " + dialogCenter + ";";
	sFeatures=sFeatures + "help: " + dialogHelp + ";";
	sFeatures=sFeatures + "resizable: " + dialogResize + ";";
	sFeatures=sFeatures + "status: " + dialogStatus + ";";
	sFeatures=sFeatures + "scroll: " + dialogScrollbar + ";";
	return sFeatures;
}


//VerifyCancel function is the event handler for the Cancel buttons' and TAB hyperlinks' onclick event.
//If any controls have been modified on the screen, the function causes a modal diolog
//to pop-up asking the user to verify whether they really want to cancel without saving their changes.
//The parameter vsModified is a boolean value indicating whether or not modifications were made to screen.
//The parameter vsQuestion determines whether a question related to the Cancel button or one related
//to the Tab links should be displayed in the dialogue box.  Send the string "CANCEL_BTN" to indicate that 
//the dialog is response to clicking the cancel button, or send the string "TAB_CHANGE" if the dialog is
//in response to a tab link click.
function VerifyCancel(vbModified, vsQuestion)
{	
	var continueCancel = true;		
	if(vbModified)	{		
		
		var sFeatures = fnSetDialogValues(135,350);		
		var CANCEL_BTN_DIALOG = "Do you wish to cancel and lose your changes?";		
		var TAB_CHANGE_DIALOG = "Do you wish to switch tabs and lose your changes?";				
		var sDialogText;				
		
		if(vsQuestion == "CANCEL_BTN")			
			sDialogText = CANCEL_BTN_DIALOG;		
		else if(vsQuestion == "TAB_CHANGE")			
			sDialogText = TAB_CHANGE_DIALOG;		
		else			
			sDialogText = "Error - wrong value passed to the CommonCode/VerifyCancel javascript Function!";				
		
	    //This is done as a workaround just for now...
		continueCancel = window.showModalDialog("YesNo.htm", sDialogText, sFeatures);												
	}				//to cancel returns false. To continue with postback, returns true.	

	if ( continueCancel == true )
	{	
        document.getElementById('hidModified').value = "false";
        history.back();
        //return true;
    }
    else
	    return continueCancel;	
}



function pageModified()
{
	var page_changed = document.getElementById('hidModified').value;
	if (page_changed == "true")
		return true;
	else
		return false;
}

function setPageModified()
{
	document.getElementById('hidModified').value = "true";
}

 function getPrint(print_area){ 
        //Creating new page
        var pp = window.open();
        //Adding HTML opening tag with <HEAD> … </HEAD> portion 
        pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
        pp.document.writeln('<LINK href=StyleSheet.css type="text/css" rel="stylesheet">')
        pp.document.writeln('<LINK href=StyleSheet.css type="text/css" rel="stylesheet" media="print">')
        pp.document.writeln('<base target="_self"></HEAD>')//Adding Body Tag
        pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
        pp.document.writeln(' leftMargin="10" topMargin="0" rightMargin="0">');//Adding form Tag
        pp.document.writeln('<form method="post">');//Creating two buttons Print and Close within a HTML table
        pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
        pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
        pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
        pp.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');
        pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');//Writing print area of the calling page
        pp.document.writeln(document.getElementById(print_area).innerHTML);//Ending Tag of </form>, </body> and </HTML>
        pp.document.writeln('</form></body></HTML>'); 
        
    }


//for treeview
// Main check function
  function checkChildNodes(TreeView,nodeID) {
    // Get root node
    var rootNode = TreeView.FindNodeById(nodeID);
    var checked; 
      
    // Check root node
    if (rootNode.Checked == true){
       checked = true; 
       rootNode.SaveState();
    }
    else {
        checked = false; 
       rootNode.SaveState();
    }
        
    // Get children
    var myNodeArray = rootNode.Nodes();
    // Start recurse search
    checkChildren(myNodeArray, nodeID, checked);
    TreeView.Render();
  }
   
  // Recursive function
  function checkChildren(childNodeArray, nodeID, checked) {
    // Loop through children
    for(var i=0; i < childNodeArray.length; i++)
    {
      // Check child nodes
      childNodeArray[i].Checked = checked;
      childNodeArray[i].SaveState();
        
      // Get child nodes
      var arChildren = childNodeArray[i].Nodes();
      // If child nodes
      if(arChildren.length > 0)
      {
      // Recurse
      checkChildren(arChildren, nodeID,checked);
      }
    }
  }
  
  function OpenCloseAll(TreeView, OpenAll){
      if (OpenAll =='false'){
        TreeView.CollapseAll();
       }    
      else{
        TreeView.ExpandAll();
      }
      TreeView.Render();
  }
  function OpenBranch(TreeView, nodeID){
    var rootNode = TreeView.FindNodeById(nodeID);
    rootNode.ExpandAncestors();
    rootNode.Select();
    TreeView.Render();
   }
   
  function OpenBranchOverivew(TreeView, nodeID){
    var rootNode = TreeView.FindNodeById(nodeID);
    rootNode.ExpandAncestors();
    rootNode.set_selectedCssClass = rootNode.get_selectedCssClass();
    //rootNode.set_cssClass = "SelectedNode";
    //rootNode.Select();
    TreeView.Render();
   }
   
   function IsLastChild(TreeView, Nodeid){
        var rootNode = TreeView.FindNodeById(Nodeid);
      // Get children
        var ChildNodeArray = rootNode.Nodes();
        if (ChildNodeArray.length > 0 ){
            return false;
        }
        else
        {
            return true;
        }
      
     } 
    
      
 function OpenHelpWindow(keyID, height){
    window.open('Quickhelp.aspx?keyid='+keyID,'QuickHelp','width=460,height='+height);
}


// for cookie
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);
}

function detectBrowser(){
    var existedCookie = readCookie('InDEED');
    if (existedCookie ==null){
        var browser=navigator.appName;
        var b_version=navigator.appVersion;
        var index = b_version.indexOf("MSIE 6.0");
        if (index > 0){
               alert("Your currently browser is IE 6.0. \n Please upgrade your browser to IE 7.0 or Firefox 3.0 \n to maximize your INDEED experience!");
               createCookie('InDEED','IE6.0',0);
            }
     }
}

//for master page, calcalte the length of line
function inherit(Left, Middle, Right) {
   
    if (document.layers) {
    alert('sorry, no pretty layouts for netscape 4');
    }
    else if (document.getElementById) {
      
    //var Extender = document.getElementById(Extender);
    var Right = document.getElementById(Right);
    var Left = document.getElementById(Left);
    var RightHeight = Right.offsetHeight;
    var LeftHeight = Left.offsetHeight;
    var MiddleHeight = 0;
    
    if (Middle!==''){
        var Middle = document.getElementById(Middle);
        if (Middle) {
        MiddleHeight = Middle.offsetHeight;
          //alert("middle height:" + MiddleHeight);
         }
     }
     
      //alert("left Height:" + Left.offsetHeight); 
      //alert("Right Height:" + Right.offsetHeight); 
      
      
      if ((LeftHeight > RightHeight) && (LeftHeight > MiddleHeight)){
          Left.style.height = 'auto';
          Middle.style.height = Left.offsetHeight + 'px';
      }
      
       if ((RightHeight > LeftHeight) && (RightHeight > MiddleHeight)){
          Right.style.height = 'auto';
          Middle.style.height = Right.offsetHeight + 'px';
      }
      
             
    return true
    }
      }
      
      function converMoneytoNumber(instring){
          var newstring='';
           for (i = 0; i < instring.length; i++){
            if ((instring.charAt(i)!='$') && (instring.charAt(i)!=',')){
                newstring = newstring +instring.charAt(i);        
            }
          } 
          return newstring;
      }
      
    function backToTop() {
        var x1 = x2 = x3 = 0;
        var y1 = y2 = y3 = 0;

        if (document.documentElement) {
            x1 = document.documentElement.scrollLeft || 0;
            y1 = document.documentElement.scrollTop || 0;
        }

        if (document.body) {
            x2 = document.body.scrollLeft || 0;
            y2 = document.body.scrollTop || 0;
        }

        x3 = window.scrollX || 0;
        y3 = window.scrollY || 0;

        var x = Math.max(x1, Math.max(x2, x3));
        var y = Math.max(y1, Math.max(y2, y3));

        window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

        if (x > 0 || y > 0) {
            window.setTimeout("backToTop()", 25);
        }
        return false;
    }

 
    function toggleDiv_BCS(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"
            }
        }
    

