var defaultEmptyOK = false
var whitespace = " \t\n\r";			// whitespace characters
function RenderPhoneValidationByClick(e) {

    var key;
    if (window.event) // IE
    {
        key = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        key = e.which;
    }

    //alert(key);
    // Key 8 - Backspace
    // Key 17 - Ctrl
    // Key 107 - + Sign
    // Key 9 - Tab
    // Key 46 - Delete
    // Key 111 - / Sign
    // Key 32 - Space
    // Key 188 - Comma
    // Key 16 - Shift
    // Key 189 - Dash 
    // Key 35 - Home
    // Key 36 - End
    // Keys 48-57 and 97-105 - Numeric Digits
    if ((key < 48 || key > 57) && (key < 95 || key > 105) && (key != 8) && (key != 46) && (key != 111) && (key != 32) && (key != 37) && (key != 35) && (key != 36) && (key != 39) && (key != 188) && (key != 189) && (key != 16) && (key != 9) && (key != 107)) {
        if (window.event) //IE
            window.event.returnValue = false;
        else //Firefox
            e.preventDefault();

    }
}

function ChangeCountryCode(formName, countryCodeFieldNamesStr, stateCodeFieldNamesStr) {
    var CountryID, objCode, CountryCode, objField;
    var arrcCountryCodeFieldNames = new Array();
    var arrcStateCodeFieldNames = new Array();
    var i = 0;
    arrcCountryCodeFieldNames = countryCodeFieldNamesStr.split(',');
    arrcStateCodeFieldNames = stateCodeFieldNamesStr.split(',');

    CountryID = document.getElementById("CountryID").value;
    // deal with selection of ~~~~~~~~~~~~ line in list
    if (CountryID == "-2") {
        //document.Registration.CountryID.selectedIndex = 0;
        //CountryID = document.Registration.CountryID.value;
    }
    objCode = document.getElementById("CountryCode" + CountryID);

    // deal with duplicated countries in list
    if (objCode.length > 0) {
        objCode = objCode[0];
    }
    if (objCode != null) {
        // deal with objCode eval call failiure
        if (objCode.value != undefined) {
            CountryCode = objCode.value;
        }
        else {
            CountryCode = "";
        }


        if (CountryCode.length > 0) {
            CountryCode = "+" + CountryCode;
        }
        else {
            CountryCode = "";
        }

        if (CountryCode == "+1" || CountryCode == "+61" || CountryCode == "+7") {
            // USA - Enabled StateCode Box
            for (i = 0; i < arrcStateCodeFieldNames.length; i++) {
                objField = document.getElementById(arrcStateCodeFieldNames[i]);
                if (objField != null) {
                    objField.style.display = "block";
                }
            }
        }
        else {
            // Not USA - Disable StateCode Box
            for (i = 0; i < arrcStateCodeFieldNames.length; i++) {
                objField = document.getElementById(arrcStateCodeFieldNames[i]);
                if (objField != null) {
                    objField.style.display = "none";
                }
            }
        }

        for (i = 0; i < arrcCountryCodeFieldNames.length; i++) {
            objField = document.getElementById(arrcCountryCodeFieldNames[i]);
            if (objField != null) {
                objField.value = CountryCode;
            }
        }
    }

}
  
function changeImage(ImagesRoot,ImgName,Newsrc,OnOrOff)
{
	var obj;
	Newsrc = ImagesRoot + '/' + Newsrc + '_' + OnOrOff + '.gif';
	obj = eval("document.all." + ImgName);
	obj.src = Newsrc;
}

function isEmpty(s)
{	return ((s == null) || (s.length == 0) || (isEmptySpaces(s)) || isWhitespace(s));
}
function isEmptySpaces(s)
{	var i ;
	var cond=true ;
	
	for (i=0 ; i<s.length ; i++)
		if (!(s.charAt(i)==" "))

			cond=false ;
	return cond ;	
}

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       return false
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }    
    return true;
}

function isFloat (s)
{   var i;
	var dot=false ;
	
    if (isEmpty(s)) 
       return false;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
		if (c=='.') 
		{	if (dot)
				return false ;
			else
				dot=true ;				
		};
        if (!isDigit(c) && c!='.') return false;
    }    
    return true;
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isSmallLetter (c)
{   return ((c >= "a") && (c <= "z"))
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isWhitespace (s)
{   var i;
    for (i = 0; i < s.length; i++)
    {           
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function addToErrMsg(errMsg,addToMsg){	
	errMsg=errMsg+addToMsg + "\n";
	return errMsg;
}

function isValidPassword(s)
{
	var isValid=true;
	if (s.length<4){
		return false;		
	}
	/*else
	{   for (i = 0; i < s.length; i++)
		{   			
			var c = s.charAt(i);
			if (! isLetterOrDigit (c) )
				return false;
		}
	} 
	*/
    return true;
}

function isValidPhone(s)
{
	var isValid=true;
	if (s.length<6){
		return false;
	}
	else
	{	for (i=0; i<s.length; i++)
		{
			var c = s.charAt(i);
			if ( !isDigit(c) )
				return false;
		}
	}
	return true;
}



function isEmail(s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    
    while ((i < sLength) && (s.charAt(i) != "@"))
		i++ ;

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    
    while ((i < sLength) && (s.charAt(i) != "."))
		i++ ;
    
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function UpdateHiddenOfDatePicker(tDate,frmName,dayInputName,monthInputName,yearInputName){
	var dd,mm,yyyy,index1, index2;
	index1 = tDate.indexOf('/',0);
	dd = tDate.substr(0,index1);
	index2 = tDate.indexOf('/',index1+1);
	mm = tDate.substr(index1+1,index2-index1-1);
	yyyy = tDate.substr(index2+1,4);
			
	if (index1>2 || index1==0 || index2<3 || index2>5 || isNaN(dd)  || isNaN(mm) || isNaN(yyyy)){
		alert("Invalid date format\nDate format: dd/mm/yyyy");
	}
	else if(dd>31 || dd<1 || mm<1 || mm>12 || yyyy<2000 || yyyy>2020){
		alert("Wrong date");
	}
	else
	{
		eval('document.'+frmName+'.'+dayInputName+'.value=dd');
		eval('document.'+frmName+'.'+monthInputName+'.value=mm');
		eval('document.'+frmName+'.'+yearInputName+'.value=yyyy');
	}			
}
function openDialog(src,myWidth,myHeight)
{	var winSTR,myWin;
	winSTR = "toolbar=no,address=no,status=no,scrollbars=1,resizable=1,alwayRaised=yes,width=" + myWidth + ",height=" + myHeight; 
	myWin = window.open(src,"dialogWin",winSTR);
}

function OpenHelpWindow(src,width,height,moreProperties,moveX,moveY)
{
		var sourceURL,winSTR,myWin;
		sourceURL=src;
		winSTR = 'toolbar=no,address=no,status=no,resizeable=yes,alwayRaised=yes,width='+width+',height='+height+moreProperties;
		myWin = window.open(sourceURL,'HelpWindow',winSTR);
		
		myWin.moveTo(moveX,moveY);	
		myWin.focus();
}
function openPopup(sourceURL,width,height)
{					
	winSTR = 'toolbar=no,address=no,status=no,resizable=yes,alwayRaised=yes,width='+width+',height='+height;
	myWin = window.open(sourceURL,'',winSTR);		
}
function openCenteredPopup(sourceURL,width,height)
{					
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	winSTR = 'toolbar=no,address=no,status=no,resizable=yes,alwayRaised=yes,width='+width+',height='+height+',left=' + winl + ',top=' + wint;
	myWin = window.open(sourceURL,'',winSTR);		
}
function openCenteredPopupWithScroll(sourceURL,width,height)
{					
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	winSTR = 'scrollbars=yes,toolbar=no,address=no,status=no,resizable=yes,alwayRaised=yes,width='+width+',height='+height+',left=' + winl + ',top=' + wint;
	myWin = window.open(sourceURL,'',winSTR);		
}
function openPopupWithScroll(sourceURL,width,height)
{					
	winSTR = 'scrollbars=yes,toolbar=no,address=no,status=no,resizable=yes,alwayRaised=yes,width='+width+',height='+height;
	myWin = window.open(sourceURL,'',winSTR);		
}
function CheckForillegalCharacters(FormName,FieldName,MsgErrorName)
{
	var obj;
	var oneChar;
	obj = eval("document." + FormName + "." + FieldName + ".value");
	if (obj.length>0){
			for (i=0; i<obj.length; i++)
			{
				oneChar = obj.charAt(i);
				if (oneChar == '<' || 
					oneChar == '>' || 
					oneChar == '|' || 
					oneChar == ';' || 
					oneChar == '/' || 
					oneChar == '\\' ||
					oneChar == '\'' ||  
					oneChar == '&' ||  
					oneChar == '"' ||
					oneChar == '*' ||
					oneChar == ','
					)
				{	
					AddError(MsgErrorName); 
					break;
				}
			}
		}
}
function CheckForillegalCharactersNoSpaces(FormName,FieldName,MsgErrorName)
{
	var obj;
	var oneChar;
	obj = eval("document." + FormName + "." + FieldName + ".value");
	if (obj.length>0){
			for (i=0; i<obj.length; i++)
			{
				oneChar = obj.charAt(i);
				if (oneChar == '<' || 
					oneChar == '>' || 
					oneChar == '|' || 
					oneChar == ';' || 
					oneChar == '/' || 
					oneChar == '\\' ||
					oneChar == '\'' ||  
					oneChar == '&' ||  
					oneChar == '"' ||
					oneChar == '*' ||
					oneChar == ',' ||
					oneChar == ' '
					)
				{	
					AddError(MsgErrorName); 
					break;
				}
			}
		}
}

function pickRandomNumber(range) 
{
	if (Math.random)
	{
		return Math.round(Math.random() * (range-1));
	}	
	else 
	{
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

function AddToFav()
{
	var bookmarkurl = window.location.href;
    var bookmarktitle = document.title;
    if (document.all) 
    {
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
    }
}


//////////////////////////////////////////////////////////// Tooltip JS /////////////////////////////////////////////////
/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005
	
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
Updated:	
March, 11th, 2006 - Fixed positioning of tooltip when displayed near the right edge of the browser.
April, 6th 2006, Using iframe in IE in order to make the tooltip cover select boxes.
		
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
	
Thank you!
	
www.dhtmlgoodies.com
Alf Magne Kalleland
	
************************************************************************************************************/
var dhtmlgoodies_tooltip = false;
var dhtmlgoodies_tooltipShadow = false;
var dhtmlgoodies_shadowSize = 4;
var dhtmlgoodies_tooltipMaxWidth = 200;
var dhtmlgoodies_tooltipMinWidth = 100;
var dhtmlgoodies_iframe = false;
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('opera') == -1 && document.all) ? true : false;
function showTooltip(e, tooltipTxt) {
    
    var bodyWidth = Math.max(document.body.clientWidth, document.documentElement.clientWidth) - 20;

    if (!dhtmlgoodies_tooltip) {
        dhtmlgoodies_tooltip = document.createElement('DIV');
        dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
        dhtmlgoodies_tooltipShadow = document.createElement('DIV');
        dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';

        document.body.appendChild(dhtmlgoodies_tooltip);
        document.body.appendChild(dhtmlgoodies_tooltipShadow);

        if (tooltip_is_msie) {
            dhtmlgoodies_iframe = document.createElement('IFRAME');
            dhtmlgoodies_iframe.frameborder = '5';
            dhtmlgoodies_iframe.style.backgroundColor = '#FFFFFF';
            dhtmlgoodies_iframe.src = '#';
            dhtmlgoodies_iframe.style.zIndex = 100;
            dhtmlgoodies_iframe.style.position = 'absolute';
            document.body.appendChild(dhtmlgoodies_iframe);
        }

    }
    
    dhtmlgoodies_tooltip.style.display = 'block';
    dhtmlgoodies_tooltipShadow.style.display = 'block';
    if (tooltip_is_msie) dhtmlgoodies_iframe.style.display = 'block';

    var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
    if (navigator.userAgent.toLowerCase().indexOf('safari') >= 0) st = 0;
    var leftPos = e.clientX + 10;

    dhtmlgoodies_tooltip.style.width = null; // Reset style width if it's set 
    dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
    dhtmlgoodies_tooltip.style.left = leftPos + 'px';
    dhtmlgoodies_tooltip.style.top = e.clientY + 10 + st + 'px';


    dhtmlgoodies_tooltipShadow.style.left = leftPos + dhtmlgoodies_shadowSize + 'px';
    dhtmlgoodies_tooltipShadow.style.top = e.clientY + 10 + st + dhtmlgoodies_shadowSize + 'px';
    
    if (dhtmlgoodies_tooltip.offsetWidth > dhtmlgoodies_tooltipMaxWidth) {	/* Exceeding max width of tooltip ? */
        dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
    }

    var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;
    if (tooltipWidth < dhtmlgoodies_tooltipMinWidth) tooltipWidth = dhtmlgoodies_tooltipMinWidth;


    dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
    dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
    dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

    if ((leftPos + tooltipWidth) > bodyWidth) {
        dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px', '') - ((leftPos + tooltipWidth) - bodyWidth)) + 'px';
        dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px', '') - ((leftPos + tooltipWidth) - bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
    }
    
    if (tooltip_is_msie) {
        dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
        dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
        dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
        dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

    }
    
}

function hideTooltip() {
    if (dhtmlgoodies_tooltip.style) {
        dhtmlgoodies_tooltip.style.display = 'none';
        dhtmlgoodies_tooltipShadow.style.display = 'none';
        if (tooltip_is_msie) dhtmlgoodies_iframe.style.display = 'none';
    }
}

function showTooltipByFieldValue(e, tooltipTxt, fldName, fldValue, bIsEqual) {
    if (bIsEqual) {
        if (document.getElementById(fldName).value == fldValue) {
            //alert('kk');
            showTooltip(e, tooltipTxt);

        }
    }
    else {
        if (document.getElementById(fldName).value != fldValue) {
            //alert('kk');
            showTooltip(e, tooltipTxt);

        }
    }
}

/*
* USAGE in HTML: 
* onmouseover="showTooltip(event,'This is a tooltip content.');return false"
*/
//////////////////////////////////////////////////////////// Tooltip JS //////////////////////////////////////////////////