﻿// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
	var obj = null;
	if(document.getElementById){
	/* Prefer the widely supported W3C DOM method, if
	available:-
	*/
		obj = document.getElementById(id);
	}else if(document.all){
	/* Branch to use document.all on document.all only
	browsers. Requires that IDs are unique to the page
	and do not coincide with NAME attributes on other
	elements:-
	*/
	obj = document.all[id];
	}
	/* If no appropriate element retrieval mechanism exists on
	this browser this function always returns null:-
	*/
	return obj;
}
function getElementsByName_s(sname){
	var obj = null;
	if(document.getElementsByName){
	/* Prefer the widely supported W3C DOM method, if
	available:-
	*/
		obj = document.getElementsByName(sname);
	}else if(document.all){
	/* Branch to use document.all on document.all only
	browsers. Requires that IDs are unique to the page
	and do not coincide with NAME attributes on other
	elements:-
	*/
	obj = document.all[sname];
	}
	/* If no appropriate element retrieval mechanism exists on
	this browser this function always returns null:-
	*/
	return obj;
}
//Returns the node text value 
function getInnerText (node)
{
	if(node!=null)
	{
		if(node.childNodes.length>0)
			return (node.textContent || node.innerText || node.text || node.childNodes[0].nodeValue) ;
		else
			return (node.textContent || node.innerText || node.text) ;
	}
	else
		return '';
}
function setInnerText (node, val) {

	if (typeof node.value != 'undefined') 
	{
	    node.value=val;
	}
	else if (typeof node.textContent != 'undefined') 
	{
		node.textContent=val;
		
	}
	else if (typeof node.innerText != 'undefined') 
	{
		node.innerText=val;
	}
	else if (typeof node.text != 'undefined') 
	{
		node.text=val;
	}
	else if (typeof node.childNodes[0].nodeValue != 'undefined')
	{
		node.childNodes[0].nodeValue=val;
	}
}
function PasswordReminderEmail(clientID, controlID, sLanguage, sFromPartnerEmail)
{
    try
    {
        if(clientID!='')
            clientID+='_';
        if(controlID=='')
            controlID='txtEmail';
            
        var sEmailId = getElementById_s(clientID+controlID).value;
       
        if (sEmailId == "")
        {
            var sErrMsg = new String(getElementById_s(clientID+"hdnTP_EmailIdErrMsg").value);
            alert(sErrMsg);
        }
        else
        {
 	        var sURL = location.protocol+"//"+location.hostname+":"+location.port+"/services/misc.asmx/SendPwdReminder?sToAddress="+sEmailId+"&sLang="+sLanguage+"&sFromPartnerEmail="+sFromPartnerEmail;           
            AJAXcallback("PasswordReminder", sURL, function(){DisplayPwdReminderMsg(clientID);})                      
        }        
    }
    catch(e)
    {
    }
    
    function DisplayPwdReminderMsg(clientID)
    {
        var bReturnVal = getInnerText(aXmlHttp['PasswordReminder'].responseXML.documentElement);

        if (bReturnVal == "false")
            sErrMsg = new String(getElementById_s(clientID+"hdnTP_InvalidEmailIdErrMsg").value);
        else
            sErrMsg = new String(getElementById_s(clientID+"hdnTP_PwdReminderEmailSentMsg").value);

        alert(sErrMsg);
    }
}
function listSelectedValue(name)
{
	var list=getElementById_s(name);
	return list.options[list.selectedIndex].value;
}

function Round(dNumber,dExchangeRate,iExponent)
{
    dNumber = replaceCommaDecimalSeparator(dNumber);
    dExchangeRate = replaceCommaDecimalSeparator(dExchangeRate);
    dNumber = (Math.round(parseFloat(dNumber).toFixed(2) * dExchangeRate * Math.pow(10, iExponent)) / Math.pow(10, iExponent)).toFixed(iExponent);
    return dNumber;
}

function replaceDecimalSeparator(dNumber,sDecimalSeparator,iExponent)
{
	if(sDecimalSeparator != '' && sDecimalSeparator != '.')
		dNumber=parseFloat(dNumber).toFixed(iExponent).toString().replace('.', sDecimalSeparator);
    else if(sDecimalSeparator != '' && sDecimalSeparator == '.')
		dNumber=parseFloat(dNumber).toFixed(iExponent);
    
	return dNumber;
}

function replaceCommaDecimalSeparator(dNumber)
{
	dNumber=dNumber.toString().replace(',', '.');
	return dNumber;
}
