﻿// JScript File
 
function openPopup(strOpen)
    {
        open(strOpen, "printUSA", "status=1, width=500, height=300, top=100, left=300, scrollbars=yes, menubar=no,resizable=no,directories=no,location=no");

    }
    
    
    function InvokePop(countryCode, zipCode, searchText, productType)
    {
        debugger;        
        valCountry = ValidHTMLEncode(countryCode);
        valZip=ValidHTMLEncode(zipCode);
        valSearch = ValidHTMLEncode(searchText);
        valProductType = ValidHTMLEncode(productType);
        
        // to handle in IE 7.0          
        var Pageurl = "printUSA.aspx";
        
        if (window.showModalDialog)
        {      
            var parameters = Pageurl + '?countryCode='+ valCountry +'&zipCode=' + valZip + '&searchtext=' + valSearch + '&category=' + valProductType;
            //parameters = OutputEncoder_EncodeUrl(parameters);
                        
//            retVal = window.showModalDialog(parameters, "status=1, width=500, height=300, top=100, left=300, scrollbars=yes, menubar=no,resizable=no,directories=no,location=no");
//            retVal = window.open(parameters, "_blank", "status=1, width=600, height=500, top=100, left=300, scrollbars=yes, menubar=no, resizable=no, directories=no, location=no");
            retVal = openPopupWindow(parameters, "_blank", width=600, height=500)
        }
        // to handle in Firefox
        else
        {     
            var parameters = Pageurl + '?countryCode='+ valCountry +'&zipCode=' + valZip + '&searchtext=' + valSearch + '&category=' + valProductType;
            //parameters = OutputEncoder_EncodeUrl(parameters);
            retVal = window.open(parameters, "status=1, width=600, height=500, top=100, left=300, scrollbars=yes, menubar=no,resizable=no,directories=no,location=no");
            retVal.focus();           
        }         
    }
    
function RefreshPage()
{
    window.document.getElementById("RebindFlagSpan").firstChild.Value = "1";
    window.document.forms(0).submit();
}

function TableHide()
 {
    debugger;
    document.getElementById("tdBody1").style.display = "hidden";
 }


function EncodeHtml(strInput)
{
	var c;
	var EncodeHtml = '';
	if(typeof strInput !='string') return strInput
	for(var cnt = 0; cnt < strInput.length; cnt++)
	{
		c = strInput.charCodeAt(cnt);
		
		if (( ( c > 96 ) && ( c < 123 ) ) ||
			( ( c > 64 ) && ( c < 91 ) ) ||
			( c == 32 ) ||
			( ( c > 47 ) && ( c < 58 ) ) ||
			( c == 46 ) ||
			( c == 44 ) ||
			( c == 45 ) ||
			( c == 95 ))
		{
			EncodeHtml = EncodeHtml + String.fromCharCode(c);
		}
		else
		{
			EncodeHtml = EncodeHtml + '&#' + c + ';';
		}
	}
	return EncodeHtml;
}



//Function to HTML Encode
function ValidHTMLEncode(str)
{
	if ((null != str.match(/<[^<|>]+?>/gi,'')))
	{
		return str.replace( /<[^<|>]+?>/gi,'' );
	}
	else
	{
		return str;
	}
}


function OutputEncoder_SingleByteHex( charC )
{
                var SingleByteHex = charC.toString(16);

                for ( var cnt = SingleByteHex.length; cnt < 2; cnt++ )
                {
                                SingleByteHex = "0" + SingleByteHex;
                }
                
                return SingleByteHex;
}

function OutputEncoder_TwoByteHex( charC )
{
                var TwoByteHex = charC.toString(16);

                for( var cnt = TwoByteHex.length; cnt < 4; cnt++ )
                {
                                TwoByteHex = "0" + TwoByteHex;
                }
                
                return TwoByteHex;
}



function OutputEncoder_EncodeUrl( strInput )
{
                var c;
                var EncodeUrl = '';
                
                for(var cnt = 0; cnt < strInput.length; cnt++)
                {
                                c = strInput.charCodeAt(cnt);

                                if (( ( c > 96 ) && ( c < 123 ) ) ||
                                                ( ( c > 64 ) && ( c < 91 ) )  ||
                                                ( ( c > 47 ) && ( c < 58 ) ) ||
                                                ( c == 46 ) ||
                                                ( c == 45 ) ||
                                                ( c == 95 ))
                                {
                                                EncodeUrl = EncodeUrl + String.fromCharCode(c);
                                }
                                else if ( c > 127 )
                                {
                                                EncodeUrl = EncodeUrl + '%u' + OutputEncoder_TwoByteHex(c);
                                }
                                else
                                {
                                                EncodeUrl = EncodeUrl + '%' + OutputEncoder_SingleByteHex(c);
                                }
                }
                
                return EncodeUrl;
}



// This Functions to encode url 
function encodeUrl(url)   
{   
    if (url.indexOf("?")>0)   
    {   
        encodedParams = "?";   
        parts = url.split("?");   
        params = parts[1].split("&");   
        for(i = 0; i < params.length; i++)   
        {   
            if (i > 0)   
            {   
                encodedParams += "&";   
            }   
            if (params[i].indexOf("=")>0) //Avoid null values   
            {   
                p = params[i].split("=");   
                encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));   
            }   
            else  
            {   
                encodedParams += params[i];   
            }   
        }   
        url = parts[0] + encodedParams;   
    }   
    return url;   
}  

//This Fuction to open new window with encoded url
var myPopupWindow = '';   
function openPopupWindow(url, name, width, height)   
{   
    debugger;    
    //Remove special characters from name   
    name = name.replace(/\/|\-|\./gi, "");   
  
    //Remove whitespaces from name   
    var whitespace = new RegExp("\\s","g");   
    name = name.replace(whitespace,"");   
  
    //If it is already open   
    if (!myPopupWindow.closed && myPopupWindow.location)   
    {   
        myPopupWindow.location.href = encodeUrl(url);   
    }   
    else  
    {   
        url = encodeUrl(url);
        myPopupWindow= window.open(url, name, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height );   
        if (!myPopupWindow.opener) myPopupWindow.opener = self;   
    }   
  
     //If my main window has focus - set it to the popup   
    if (window.focus) {myPopupWindow.focus()}   
} 