var tags = new Array('div','td','tr','p','b','table','strong','emphasis','a','h1','span');
var initSize;

//Call fontSizer to check if font was enlarged by user previously
//fontSizer(0);

function fontSizer(inc){
    // Copyright 2003 Eddie Traversa
    // http://www.dhtmlnirvana.com/
    // free to use as long as this copyright notice stays intact
    var checkSize;
    
    if(inc == 0)
	{
	    checkSize = getCookie("StyleSheetSize");
	}
	else
	{
	    if(initSize == null)
	        checkSize = 1;
	    else
	        checkSize = initSize;
	}
	
    if(checkSize != null)
    {
	    if (!document.getElementById) 
		    return;

//        setStyleSheet();

        //Setup initial size variable
        initSize = parseInt(checkSize);
	    //Increment/Decrement variable
        initSize += inc;
//        alert(initSize);
        //Make sure the decrements aren't smaller 
        //than the original size
	    if (initSize <= 1 ){
		    initSize = 1;
            setCookie("StyleSheetSize",initSize,"","/");
		    return;
        }
        //Stop after 5 increments 
	    if (initSize > 5 ){
		    initSize = 5;
            setCookie("StyleSheetSize",initSize,"","/");
		    return;
	    }
    	
        setCookie("StyleSheetSize",initSize,"","/");
	    var existSize;
	    getBody = document.getElementsByTagName('body')[0];
	    //Loop through all the tags and change the font size
        for (i = 0 ; i < tags.length ; i++ ) {
	        getallTags = getBody.getElementsByTagName(tags[i]);
	        
            for (k = 0 ; k < getallTags.length ; k++) 
	        {
	            //Get exisitng font size of text
	            existSize = elementFontSize(getallTags[k])
	            //Make sure text is no smaller than 10px
                if(existSize < 10)
                    existSize = 10;
                //Increment/Decrement the existing font size
                getallTags[k].style.fontSize = existSize + inc + 'px';
	        }
	    }

    }
}

function setStyleSheet()
{
	if (document.getElementsByTagName)
		x = document.getElementsByTagName('link');
	else if (document.all)
		x = document.all.tags('link');
	else
	{
		alert('This script does not work in your browser');
		return;
	}

	for (var i=0;i<x.length;i++)
	{		
        var CurrSizeStyleSheet = x[i].getAttribute("href");			
        var StyleName = CurrSizeStyleSheet.substring(0, CurrSizeStyleSheet.length - 5);		
	    x[i].setAttribute("href", StyleName + "M" + ".css");
    }
}

function elementFontSize(element)
{
    if (document.defaultView)
    {
        var computedStyle = document.defaultView.getComputedStyle(element, null);
        if (computedStyle)
        {
            fontSize = computedStyle.getPropertyValue("font-size");
        }
    }
    else if (element.currentStyle)
    {
        fontSize = element.currentStyle.fontSize;
    }
    
    return parseFloat(fontSize);
}

function DecreaseFontSize()
{
	changeCSS("smaller");		
}

function IncreaseFontSize()
{					
	changeCSS("larger");		
}

function getCookie(NameOfCookie)
{
    // First we check to see if there is a cookie stored.
    // Otherwise the length of document.cookie would be zero.
    if (document.cookie.length > 0)
    {
        // Second we check to see if the cookie's name is stored in the
        // "document.cookie" object for the page.

        // Since more than one cookie can be set on a
        // single page it is possible that our cookie
        // is not present, even though the "document.cookie" object
        // is not just an empty text.
        // If our cookie name is not present the value -1 is stored
        // in the variable called "begin".

        begin = document.cookie.indexOf(NameOfCookie+"=");
        if (begin != -1)
        {
            // Our cookie was set.
            // The value stored in the cookie is returned from the function.
            begin += NameOfCookie.length+1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end)); 
        }
    }
    // Our cookie was not set.
    // The value "null" is returned from the function.
    return null;
}

function replace(string,text,by) {
		// Replaces text with by in string
		var strLength = string.length, txtLength = text.length;
		if ((strLength == 0) || (txtLength == 0)) return string;

		var i = string.indexOf(text);
		if ((!i) && (text != string.substring(0,txtLength))) return string;
		if (i == -1) return string;

		var newstr = string.substring(0,i) + by;

		if (i+txtLength < strLength)
			newstr += replace(string.substring(i+txtLength,strLength),text,by);

		return newstr;
	}



function setCookie(name, value, expires, path, domain, secure)
{
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function changeCSS(Size)
{
	if (document.getElementsByTagName)
		x = document.getElementsByTagName('link');
	else if (document.all)
		x = document.all.tags('link');
	else
	{
		alert('This script does not work in your browser');
		return;
	}
	
	for (var i=0;i<x.length;i++)
	{		
		var CurrSizeStyleSheet = x[i].getAttribute("href");			
		var CurrSize = CurrSizeStyleSheet.substring(CurrSizeStyleSheet.length - 5);
		var StyleName = CurrSizeStyleSheet.substring(0, CurrSizeStyleSheet.length - 5);		
		
		switch (CurrSize.substring(0,1))
		{
			case "S" :
				if (Size == "larger")
				{
					x[i].setAttribute("href", StyleName + "M" + ".css");
					setCookie("StyleSheetSize","M","","/");
				}
				else if (Size == "smaller")
				{
					x[i].setAttribute("href", StyleName + "S" + ".css");
				}
				break;
			case "M" :
				if (Size == "larger")
				{
					x[i].setAttribute("href", StyleName + "L" + ".css");
					setCookie("StyleSheetSize","L","","/");
				}
				else if (Size == "smaller")
				{
					x[i].setAttribute("href", StyleName + "S" + ".css");
					setCookie("StyleSheetSize","S","","/");
				}
				break;
			case "L" :
				if (Size == "larger")
				{
					x[i].setAttribute("href", StyleName + "X" + ".css");
					setCookie("StyleSheetSize","X","","/");
				}
				else if (Size == "smaller")
				{
					x[i].setAttribute("href", StyleName + "M" + ".css");
					setCookie("StyleSheetSize","M","","/");
				}
				break;
			case "X" :
				if (Size == "larger")
				{
					x[i].setAttribute("href", StyleName + "X" + ".css");
					setCookie("StyleSheetSize","X","","/");
				}
				else if (Size == "smaller")
				{
					x[i].setAttribute("href", StyleName + "L" + ".css");
					setCookie("StyleSheetSize","L","","/");
				}
				break;
		}
	}			
}

function clickButton(strID) 
{
	var pButton = document.getElementById(strID);
	if (event && event.which) {
		if (event.which == 13) {
			pButton.click();
			return false;
		}
	} else if (window.event && window.event.keyCode) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancel = true;
			pButton.click();
			return false;
		}
	}
}

function OpenPrintWindow()
{
	var strUrl = window.document.location.href;		
	
	if (strUrl.indexOf("?") > 0)
	{
		window.open(strUrl + "&action=print","","","");
	}	
	else
	{
		window.open(strUrl + "?action=print","","","");
	}
}

function OpenNewWindow(Url, Width, Height, Top, Left, Location, MenuBar, Resizable, Scrollbars, Toolbar)
{
	strFeatures = ((Width) ? "; width=" + Width : "") +
			((Width) ? "; width=" + Width : "") +
			((Height) ? "; height=" + Height : "") +
			((Top) ? "; top=" + Top : "") +
			((Left) ? "; left=" + Left : "") +
			((MenuBar) ? "; menubar=" + MenuBar : "") +
			//((Resizable) ? "; resizable=yes") +
			((Scrollbars) ? "; scrollbars=" + Scrollbars : "") +
			((Toolbar) ? "; toolbar=" + Toolbar : "");
			var winname = "win" + (Math.round((Math.random()*9000)+1))
			//alert(winname)
			strFeatures = strFeatures + ";resizable=yes";
	//var x = window.open(Url, winname);
	var x = window.open(Url, winname, strFeatures);
	//location.href=Url;
}

function OpenFlash(Url)
{
	strFeatures = "width=5; height=5; top=false; left=false; menubar=false ;resizable=true ;scrollbars=false ;toolbar=false ;status=true"
	window.open(Url, "DDWin", strFeatures);
}





function OpenNewWindowcountry(Url)
{
			//strFeatures = ((Width) ? "; width=" + Width : "") +
			//((Width) ? "; width=" + Width : "") +
			//((Height) ? "; height=" + Height : "") +
			//((Top) ? "; top=" + Top : "") +
			//((Left) ? "; left=" + Left : "") +
			//((MenuBar) ? "; menubar=" + MenuBar : "") +
			//((Resizable) ? "; resizable=" + Resizable : "") +
			//((Scrollbars) ? "; scrollbars=" + Scrollbars : "") +
			//((Toolbar) ? "; toolbar=" + Toolbar : "");		
			//window.open(Url, "DDWin", strFeatures);
			window.location.href=Url
			
}

function NavigateTo(strUrl)
{	
	window.location = strUrl;
}

function CheckDropDownSelected(oSrc, args)
{				
	args.IsValid = (args.Value != -1 && args.Value != 'Please Select One');
}

function OpenPopupWindow(Path)
{			
	window.open(Path,"","","");
}

function ConfirmDelete()
{
	var blnVal = confirm("Are you sure want to delete the selected item?");
	
	return blnVal;
}

function validEmailYN(email) {
   invalidChars = " /:,;"
    if (email == "") {return false}
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar,0) != -1) {return false}
    }
    atPos = email.indexOf("@",1)
    if (atPos == -1) {return false}
    if (email.indexOf("@",atPos+1) != -1) {return false}
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {return false}
    if (periodPos+3 > email.length)	{return false}
    return true
   }