/*=======================================================================================================================
This region of functions are used for AJAX functionalities.
=======================================================================================================================*/

/* function to instantiate an XMLHttp object */
function NewXMLHttpInstance(p_Handler) { 
	var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
	var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
	var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
	//netscape, safari, mozilla behave the same??? 
	var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 					

	var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

	//Depending on the browser, try to create the xmlHttp object 
	if (is_ie){ 
		//The object to create depends on version of IE 
		//If it isn't ie5, then default to the Msxml2.XMLHTTP object 
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
		    
		//Attempt to create the object 
		try{ 
			objXmlHttp = new ActiveXObject(strObjName); 
			
			if (p_Handler != null) {
			    objXmlHttp.onreadystatechange = p_Handler; 
			}
		} 
		catch(e){ 
		//Object creation errored 
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
			return; 
		} 
	} 
	else if (is_opera){ 
		//Opera has some issues with xmlHttp object functionality 
		alert('Opera detected. The page may not behave as expected.'); 
		return; 
	} 
	else{ 
		// Mozilla | Netscape | Safari 
		objXmlHttp = new XMLHttpRequest(); 
		objXmlHttp.onload = p_Handler; 
		objXmlHttp.onerror = p_Handler; 
	} 
		
	//Return the instantiated object 
	return objXmlHttp; 
} 

/* function to send XMLHttp request */
function SendXMLHttpRequest(p_objXMLHttp, p_URL, p_FormValues) { 
	p_objXMLHttp.open('POST', p_URL, true);
	p_objXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");      
	p_objXMLHttp.send(p_FormValues); 
} 

function checkReadyState(p_objXMLHttp) {
	try {
		if (p_objXMLHttp.readyState == 4 || p_objXMLHttp.readyState == 'complete') {
			return true;
		} else {
			return false;
		}
	} catch(err) {
		return false;
	}
}
/*=====================================================================================================================*/

function getElementXMLContent(p_strElementID) {
    var m_oElement = document.getElementById(p_strElementID);
    var m_oXML;
    
    //load xml file
    if (window.ActiveXObject){
        m_oXML = new ActiveXObject("Microsoft.XMLDOM");
        m_oXML.async=false; //Enforce download of XML file first. IE only.
    } else if (document.implementation && document.implementation.createDocument) {
        m_oXML = document.implementation.createDocument("","doc",null);
    }
        
    if (typeof m_oXML!="undefined") {
        if (window.ActiveXObject)
          {
          m_oXML.loadXML(m_oElement.innerHTML);
          }
        // code for Mozilla, Firefox, Opera, etc.
        else
          {
          var parser = new DOMParser();
          m_oXML = parser.parseFromString(m_oElement.innerHTML,"text/xml");
          }
    }
    return m_oXML
}
                
function openEmailClient(p_UserID,p_Domain,p_Subject) {
   var m_arrParameters = openEmailClient.arguments;
   
   if (m_arrParameters.length==3) {
      document.location = 'mailto:' + m_arrParameters[0] + '@' + m_arrParameters[1] + '?subject=' + m_arrParameters[2];
   } else {
      document.location = 'mailto:' + m_arrParameters[0] + '@' + m_arrParameters[1];
   }
}

function showHideContent(p_Div,p_Img) {
   var m_oDivContainer = document.getElementById(p_Div);
   var m_oExpandIcon = document.getElementById(p_Img);
   
   if (m_oDivContainer.style.display == 'none') {
      m_oDivContainer.style.display = 'block';
      m_oExpandIcon.src = '/images/collapse.gif';
      m_oExpandIcon.title = 'Hide Details';
   } else {
      m_oDivContainer.style.display = 'none';
      m_oExpandIcon.src = '/images/expand.gif';
      m_oExpandIcon.title = 'Show Details';
   }
   
   return true
}

function printWindow(){
	browserVersion = parseInt(navigator.appVersion)
	if (browserVersion >= 4) window.print();
}

/* 
Function name:	setMonthNumberOfDays(oYear, oMonth, oDay)
Description:	This function adjust the number of days selection for a selected month.  
			It supports leap years and is Y2K compliant.
				
Original creator:	Ben McFarlin (mcfarlin@netscape.net) 
Web site:		http://sites.netscape.net/mcfarlin
Source:		This script and many more are available free online at 
			The JavaScript Source!! http://javascript.internet.com

Modified by:	Roaniver P. Madrid (roan.madrid@asia-hotels.com; roan_madrid@yahoo.com)
Date modified:	04-Feb-2005
Modifications:	- function name and parameters.
			- descriptive variable names.
			- added value to the "value" parameter when creating OPTION objects.
			- auto selecting the previously selected day when changing month or year.
*/
function setMonthNumberOfDays(oYear, oMonth, oDay) {
	var oSelectedDate1stDayOfTheMonth;
	var oSelectedDateLastDayOfTheMonth;
	
	var iPreviouslySelectedDay;
	var iTimeDifference, iSelectedMonthNumberOfDays;
	
	var i;
	
	try {
		iPreviouslySelectedDay = oDay.options[oDay.selectedIndex].value;
		
		oSelectedDate1stDayOfTheMonth = new Date(oYear.options[oYear.selectedIndex].value, oMonth.options[oMonth.selectedIndex].value,1);
		iTimeDifference = oSelectedDate1stDayOfTheMonth - 86400000;
		
		oSelectedDateLastDayOfTheMonth = new Date(iTimeDifference);
		iSelectedMonthNumberOfDays = oSelectedDateLastDayOfTheMonth.getDate();
		
		for (var i = 0; i < oDay.length; i++) {
			oDay.options[0] = null;
		}
		
		for (var i = 0; i < iSelectedMonthNumberOfDays; i++) {
			oDay.options[i] = new Option(i+1,i+1);
		}

		if (iSelectedMonthNumberOfDays >= iPreviouslySelectedDay) {
			oDay.options[iPreviouslySelectedDay-1].selected = true;
		} else {
			oDay.options[0].selected = true;
		}
	} catch(e) {
		return
	}
}

/* description: get the index of the selected option in radio button array. */
function selectedRadioButtonIndex(oRadioButton) {
	var iCtr,iSelectedRadioButtonIndex;
	var blnSelected = false;
	
	for(iCtr=0;iCtr<oRadioButton.length;iCtr++) {
		if (oRadioButton[iCtr].checked) {
			iSelectedRadioButtonIndex = iCtr;
			blnSelected = true;
			break;
		}
	}
		
	if (blnSelected) {
		return iSelectedRadioButtonIndex
	} else {
		return -1
	}
}

function transferSelectedList(oListFrom,oListTo) {
	var iCtr = 0;
	
	if (oListFrom.selectedIndex != -1) {
		for(iCtr=0;iCtr<oListFrom.options.length;++iCtr) {
			if (oListFrom.options[iCtr].selected) {
				oListTo.options[oListTo.options.length] = new Option(oListFrom.options[iCtr].innerText, oListFrom.options[iCtr].value);
				oListTo.options[oListTo.options.length-1].selected = true;
				oListFrom.options[iCtr] = null;
				iCtr = iCtr-1;
			}
		}
	} else {
		alert('No choices were selected for transfer');
	}
}

function emptyListBox(oListBox) {
	var iCtr;
	
	for(iCtr=0;iCtr<oListBox.options.length;iCtr++) {
		oListBox.options[iCtr] = null;
	}
}

function selectAllList(oListBox) {
	var iCtr
		
	for(iCtr=0;iCtr<oListBox.options.length;iCtr++) {
		oListBox.options[iCtr].selected = true;
	}
}

function selectAllCheckBox(p_CheckBoxID) {
    var m_oCheckBox = document.getElementsByName(p_CheckBoxID);
	var iCtr;
	
	for(iCtr=0;iCtr<m_oCheckBox.length;iCtr++) {
	    m_oCheckBox[iCtr].checked = true;
	}
	
	return true
}

function unselectAllCheckBox(p_CheckBoxID) {
    var m_oCheckBox = document.getElementsByName(p_CheckBoxID);
	var iCtr;
	
	for(iCtr=0;iCtr<m_oCheckBox.length;iCtr++) {
	    m_oCheckBox[iCtr].checked = false;
	}
	
	return true
}

function isAllowedStringValue(argString) {
	var ValidStringExp = /\w+/;	
	
	if (argString.match(ValidStringExp)==null){
		return false
   } else {
		return true
   }
}

function trimSpaces(argString) {
	var iCtr = 0;
	var StringA = argString;
	var StringB = argString;
	
	/*comment: remove leading spaces*/
	for(iCtr=0;iCtr<StringA.length;iCtr=0) {
		if (StringA.charAt(0)!=' ') {
			break;
		} else {
			/*comment: check if the string is not all spaces*/
			if (StringA.length>1) {
				StringB = StringA.substring(1,StringA.length);
				StringA = StringB;
			} else {
				StringA = '';
			}
		}
	}
	
	/*comment: remove trailing spaces*/
	for(iCtr=StringA.length-1;iCtr>0;iCtr--) {
		if (StringA.charAt(iCtr)!=' ') {
			break;
		} else {
			StringB = StringA.substring(0,iCtr);
			StringA = StringB;
		}
	}
	
	return StringA;
}

function openNewWindow(URL,argWidth,argHeight,argWindowName,argIsResizable,argShowFullFeature) {
    var m_arrParameters = openNewWindow.arguments;
    var m_strWindowName, m_strWindowFeatures;
    var m_oNewWindow;
    
    m_strWindowFeatures = "width=" + m_arrParameters[1] + ",height=" + m_arrParameters[2] + ",left=5,top=5,scrollbars=no";
    
    switch (m_arrParameters.length)
    {
        case 6:
            if ((argIsResizable)&&(argShowFullFeature)) {
                m_strWindowFeatures = "resizable=yes,location=yes,toolbar=yes," + m_strWindowFeatures;
            } else if ((!argIsResizable)&&(argShowFullFeature)) {
                m_strWindowFeatures = "resizable=no,location=yes,toolbar=yes," + m_strWindowFeatures;
            } else {
                m_strWindowFeatures = "resizable=no," + m_strWindowFeatures;
            }
            m_strWindowName = m_arrParameters[3];
            break
        case 5:
            if (argIsResizable) {
                m_strWindowFeatures = "resizable=yes," + m_strWindowFeatures;
            }
            m_strWindowName = m_arrParameters[3];
            break
        case 4:
            m_strWindowFeatures = "resizable=no," + m_strWindowFeatures;
            m_strWindowName = m_arrParameters[3];
            break
        default:
            m_strWindowFeatures = "resizable=no," + m_strWindowFeatures;
            m_strWindowName = 'oNewWindow';
    }
    
    m_oNewWindow = window.open(m_arrParameters[0],m_strWindowName,m_strWindowFeatures);
	m_oNewWindow.focus();
}

function getDateDiff(argDate1, argDate2) {
	iDiff = Date.parse(argDate2.toString()) - Date.parse(argDate1.toString());
	
	iInSec = iDiff / 1000;
	iMin = iInSec / 60;
	iHr = iMin / 60;
	iDay = iHr / 24;
	
	getDateDiff = iDay;
}

/*This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)
Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com)
Changes:
1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */

function isValidEmail(emailStr) {
	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/i;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : ' \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\'\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Incorrect e-mail address. (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("The username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("The domain name contains invalid characters.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("The email username is invalid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
					 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name is invalid.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function clickHere() {
    void(0);
}

//====ToolTip for Footer====//
function setLinkToolTip(p_mEvent,p_objCallerID,p_strMsg){
   var m_objCaller = document.getElementById(p_objCallerID);
   var m_CallerPosLeft =  m_objCaller.offsetLeft;
   var m_CallerPosTop = m_objCaller.offsetTop;
   var m_CallerPosWidth = m_objCaller.offsetWidth;
   var m_CallerPosHeight = m_objCaller.offsetHeight;
   var objToolTip;
   if(p_mEvent=='1'){
      objToolTip = document.getElementById("tooltip");
      objToolTip.style.padding = '2px 2px 2px 2px';
      objToolTip.style.margin='3px 3px 3px 3px';
      objToolTip.style.position='absolute';
      objToolTip.innerHTML = unescape(p_strMsg);
      objToolTip.style.border='1px solid #000000';
      objToolTip.style.display='block';
      objToolTip.style.left =(m_CallerPosLeft)+'px';
      objToolTip.style.top =(m_CallerPosTop-(objToolTip.offsetHeight+5))+'px';
      objToolTip.style.background='#FFFFE1';
      objToolTip.style.textAlign='left';
    }else{
      objToolTip = document.getElementById("tooltip");
      objToolTip.style.display='none';
   }     
}


/*=======================================================================================================================
The following cookie functions are copied from http://www.codelib.net/javascript/cookies.html.
=======================================================================================================================*/
function reldate(days) {
	var d;
	d = new Date();

	/* We need to add a relative amount of time to
	the current date. The basic unit of JavaScript
	time is milliseconds, so we need to convert the
	days value to ms. Thus we have
	ms/day
	= 1000 ms/sec *  60 sec/min * 60 min/hr * 24 hrs/day
	= 86,400,000. */

	d.setTime(d.getTime() + days*86400000);
	return d.toGMTString();
}

function readCookie(name) {
	var s = document.cookie, i;
	if (s)
	for (i=0, s=s.split('; '); i<s.length; i++) {
		s[i] = s[i].split('=', 2);
		if (unescape(s[i][0]) == name)
		return unescape(s[i][1]);
	}
	return null;
}

function makeCookie(name, value, p) {
	var s, k;
	s = escape(name) + '=' + escape(value);
	if (p) for (k in p) {

	/* convert a numeric expires value to a relative date */

	if (k == 'expires')
	p[k] = isNaN(p[k]) ? p[k] : reldate(p[k]);

	/* The secure property is the only special case
	here, and it causes two problems. Rather than
	being '; protocol=secure' like all other
	properties, the secure property is set by
	appending '; secure', so we have to use a
	ternary statement to format the string.

	The second problem is that secure doesn't have
	any value associated with it, so whatever value
	people use doesn't matter. However, we don't
	want to surprise people who set { secure: false }.
	For this reason, we actually do have to check
	the value of the secure property so that someone
	won't end up with a secure cookie when
	they didn't want one. */

	if (p[k])
	s += '; ' + (k != 'secure' ? k + '=' + p[k] : k);
	}
	document.cookie = s;
	return readCookie(name) == value;
}

function rmCookie(name) {
	return !makeCookie(name, '', { expires: -1 });
}
/*=======================================================================================================================
End of Cookie functions
=======================================================================================================================*/

/* 
<remarks>
    <description>This function converts time having a format HH:MM:SS or MM:SS into seconds.</description>
    <createdby>roan.madrid@naxos.com</createdby>
    <datecreated>2008-11-17</datecreated>
</remarks>
*/
function convertHHMMSSTimeToSeconds(p_HHMMSSTime) {
    var m_arrTimeParts;
    var m_intHour = 0; var m_intMin = 0; var m_intSec = 0;
    var m_intTimeInSeconds = 0;
    var m_TimeRegEx = /^(?:(?:(?:(?:\d+:)?\d+:)?\d+)*)$/;
    
    /*<remarks>since the "test()" regex method is proprietery, it is safe to use the match() method when testing for string patterns for cross-browser compatibility.</remarks>*/
    if (p_HHMMSSTime.match(m_TimeRegEx)!=null) {
        m_arrTimeParts = p_HHMMSSTime.split(/\:/g);
        
        if (m_arrTimeParts.length==3) {
            m_intHour = parseInt(m_arrTimeParts[0],10); m_intMin = parseInt(m_arrTimeParts[1],10); m_intSec = parseInt(m_arrTimeParts[2],10);
        } else if (m_arrTimeParts.length==2) {
            m_intMin = parseInt(m_arrTimeParts[0],10); m_intSec = parseInt(m_arrTimeParts[1],10);
        } else {
            m_intSec = parseInt(p_HHMMSSTime,10);
        }
        
        m_intTimeInSeconds = (m_intHour * 60 * 60);
        m_intTimeInSeconds = m_intTimeInSeconds + (m_intMin * 60);
        m_intTimeInSeconds = m_intTimeInSeconds + m_intSec;
    }
    
    return parseInt(m_intTimeInSeconds,10);
}