﻿// JScript File

/////////////////////////////////////////
// popWindow()                         //
// 2007-02-26 Andy Male                //
//                                     //
// implement as class                  //
// pops new window to print for example//
/////////////////////////////////////////

function popWindow()
{
    // Defaults have setters
    this.url_= '';
    this.windowName_ = '';
    this.height_ = 200;
    this.width_ = 200;
    this.top_ = 0;
    this.left_ = 0;
    this.resizable_ = 'no';
    this.scrollbars_ = 'no';
    this.toolbar_ = 'no';
    this.status_ = 'no';
    this.menubar_ = 'no';
    this.location = 'no';
    this.popWindow = null;
       
    this.newWindow = function ()
    {
        //alert('height='+this.height_+',width='+this.width_+',left='+this.left_+',top='+this.top_+',resizable='+this.resizable_+',scrollbars='+this.scrollbars_+',toolbar='+this.toolbar_+',status='+ this.status_)
        this.popWindow = window.open(this.url_, this.windowName_,'height='+this.height_+',width='+this.width_+',left='+this.left_+',top='+this.top_+',resizable='+this.resizable_+',scrollbars='+this.scrollbars_+',menubar='+this.menubar_+',location='+this.location_+', toolbar='+this.toolbar_+',status='+ this.status_);
//        this.popWindow.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
//        this.popWindow.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" >");
//        this.popWindow.document.write("<head><title>TagsEasy Corporate Tagging and Social Search</title><link href=\"App_Themes/tagsEasy/print.css\" type=\"text/css\" media=\"print\" rel=\"stylesheet\" /></head>");
//        this.popWindow.document.write("<body><div id=\"mainPrintContent\" class=\"test\">");
//        this.popWindow.document.write("HELLO</div></body></html>");
//        this.popWindow.document.close();
    }
    
    this.write = function(str)
    {
        this.newWindow.document.write(str);
    }
    
    this.close = function()
    {
        this.newWindow.document.close();
    }
    
    this.windowFocus = function ()
    {
        if (window.focus) 
        {
            this.objNewWindow_.focus();
        }
    }
    
    // Getters setters
    this.setURL = function (value)
    {
        // Could put a regex in here to check its a valid looking URL
        if ((value != null) && (value != ''))
        {
	    value = value.replace(" ", "%20");
            this.url_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }

    this.setWindowName = function (value)
    {
        // This can't have spaces
        if ((value != null) && (value != '') && (hasWhiteSpace(value) == false))
        {
            this.windowName_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setHeight = function (value)
    {
        if (isInt(value))
        {
            this.height_ = parseInt(value);
            return true;
        }
        else
        {
            return false;
        }
    }

    this.setWidth = function (value)
    {        
        if (isInt(value))
        {
            this.width_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setTop = function (value)
    {
        if (isInt(value))
        {
            this.top_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setLeft = function (value)
    {
        if (isInt(value))
        {
            this.left_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }

    this.setResizable = function (value)
    {
        if (strYesNo(value))
        {
            this.resizable_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setScrollbars = function (value)
    {
        if (strYesNo(value))
        {
            this.scrollbars_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }

    this.setMenubar = function (value)
    {
        if (strYesNo(value))
        {
            this.menubar_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }

    this.setLocation = function (value)
    {
        if (strYesNo(value))
        {
            this.location_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setToolbar = function (value)
    {    
        if (strYesNo(value))
        {
            this.toolbar_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    this.setStatus = function (value)
    {
        if (strYesNo(value))
        {
            this.status_ = value;
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function strYesNo(strVal)
    {
        returnVal_ = false;
        if ((strVal.toLowerCase() == 'yes') || (strVal.toLowerCase() == 'no'))
        {
            returnVal_ = true;
        }
        return returnVal_;
    }
    
    function hasWhiteSpace(strVal)
    {
        returnVal_ = true;
        RegExp = /\s/;
        if (strVal.match(RegExp) == null) returnVal_ = false;
        return returnVal_;
    }
    
    function isInt(strVal)
    {
        if (isNaN(parseInt(strVal)))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

// USED TO TEST 
//    alert(    
//        'printView_.url_=' + printView_.url_ + '\r\n' +
//        'printView_.windowName_=' + printView_.windowName_ + '\r\n' +
//        'printView_.height_=' + printView_.height_ + '\r\n' +
//        'printView_.width_=' + printView_.width_ + '\r\n' +
//        'printView_.top_=' + printView_.top_ + '\r\n' +
//        'printView_.left_=' + printView_.left_ + '\r\n' +
//        'printView_.resizable_='+ printView_.resizable_ + '\r\n' +
//        'printView_.scrollbars_=' + printView_.scrollbars_ + '\r\n' +
//        'printView_.toolbar_=' + printView_.toolbar_ + '\r\n' +
//        'printView_.status_=' + printView_.status_);


