﻿
//The object to store parameters for function GetFrameElement
function FrameParamObj(frameName,  frameLocation, elementName, elementType, parentFrameName)
{
    this.FrameName = frameName; //The name of the frame
    this.FrameLocation = frameLocation; //The location of the frame (Child, Parent, Sibling)
    this.ElementName = elementName; //The name of the element to look for
    this.ElementType = elementType; //The type of the element to look for (Standard, Intersoft)
    this.ParentFrameName = parentFrameName; //The name of the parent frame
}

//This function is to get other element in another Frame
function GetFrameElement(FrameParamObj)
{   
    var frame; //used to store the frame element
	switch (FrameParamObj.FrameLocation)
    {
        case "Child":
            frame = window.frames[FrameParamObj.FrameName];            
            break;
        case "Parent":
            frame = window.parent;     
            break;
        case "Sibling":
            frame = window.parent.frames[FrameParamObj.FrameName];
            break;
        case "SiblingChild":
            frame = window.parent.frames[FrameParamObj.ParentFrameName];
            frame = frame[FrameParamObj.FrameName];
            break;
        case "GrandParent":
            frame = window.parent.parent;
            break;
    }
        
    if(frame == null)
    {
        return null;
    }    

    var element; //used to store the element we are looking for
    switch (FrameParamObj.ElementType)
    {
        case "Standard":
            element = frame.document.getElementById(FrameParamObj.ElementName);            
            break;
        case "Intersoft":
            try {
                element = frame.ISGetObject(FrameParamObj.ElementName);
            }
            catch(e) {
                return null;
            }
            break;              
    }     
    return element;
}

// Get QueryString, usage: queryString('page').

function PageQuery(q)
{
    if(q.length > 1)
        this.q = q.substring(1, q.length);
    else
        this.q = null;
    
    this.keyValuePairs = new Array();
    
    if(q)
    {
        var q1 = this.q.split("?")[1];
        
        if (q1)
        {
            for(var i=0; i < q1.split("&").length; i++)
            {
                this.keyValuePairs[i] = q1.split("&")[i];
            }
        }
    }
    
    this.getKeyValuePairs = function()
    {
        return this.keyValuePairs;
    }
    
    this.getValue = function(s)
    {
        for(var j=0; j < this.keyValuePairs.length; j++)
        {
            if(this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        
        return null;
    }
    
    this.getParameters = function()
    {
        var a = new Array(this.getLength());
        for (var j=0; j < this.keyValuePairs.length; j++)
        {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    
    this.getLength = function()
    {
        return this.keyValuePairs.length;
    }
}

function QueryString(key, url)
{
    if(url == undefined)
        url = document.URL;
        
    var page = new PageQuery(url);
    var qsValue = page.getValue(key);
    
    if(qsValue == null)
        return qsValue;
    
    return unescape(qsValue);
}

// end of function QueryString


// Open Window with default property :
//    * ControlBoxImage = is_webdesktop-16.gif
//    * ContentMode = IFrame
//    * AllowMaximize = Yes
//    * AllowMinimize = Yes
 
function OpenDefaultWindow (windowName, windowText, windowURL, defaultSize, controlBoxImage, width, height, asyncLoad)
{
    var dm = ISGetDesktopManager();
    var wnd = dm.GetWindow(windowName);
    if (wnd == null)
    {
        if (windowText.length > 80)
            windowText = windowText.substring(0, 80) + "...";            
    
        wnd = dm.CreateWindow();
        wnd.Text = windowText;              
        wnd.Name = windowName;
        if (!asyncLoad) wnd.ContentURL = windowURL;
        
        if (controlBoxImage == null) controlBoxImage = "is_webdesktop-16.gif";
        if (width == null) width = 800;
        if (height == null) height = 600;
        if (defaultSize == null) defaultSize = true;
        
        wnd.ControlBoxImage = controlBoxImage;
        wnd.ContentMode = "UseIFrame";
        wnd.AllowMinimize = "Yes";
        wnd.AllowMaximize = "Yes";
        if(!defaultSize) wnd.Size = new UnitSize(width, height);
        wnd.DesktopManager = dm;
        dm.Windows.Add(wnd);
        wnd.Show();
        wnd.MoveToCenterDesktop();
        if (asyncLoad) setTimeout(function() {wnd.SetContentURL(windowURL);}, 50); // load URL in separate thread
    }
    else
    {
        wnd.Activate();
    }			
}		

function IsIE7x()
{
    return /7./.test(navigator.userAgent) && /MSIE/.test(navigator.userAgent);
}

function SetCookie(name, value, days)
{
    var date = new Date();
    if (days == null || days == 0)
        days = 1;
    
    date.setTime(date.getTime() + 3600000 * 24 * days);
    document.cookie = name + "=" + value
         + ";expires=" + date.toGMTString();
}

function ReadCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		
		while (c.charAt(0) == ' ')
		    c = c.substring(1, c.length);
		    
		if (c.indexOf(nameEQ) == 0)
		    return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function EraseCookie(name)
{
	SetCookie(name, "", -1);
}

// GeneralTypeMapper similar to server side's GeneralTypeMapper
// This is used to avoid using Names.
function GeneralTypeMapper()
{
    this.FeedbackType = new FeedbackType();
    this.ActivityType = new ActivityType();
    this.ContributionStatus = new ContributionStatus();
}

function FeedbackType()
{
    // We use string because most IDs are passed as string.
    // Hence, we don't need to parse the string into integer.
    
    this.BugSubmission = "45";
    this.FeatureRequest = "46";
}

function ActivityType()
{
    this.Review = "1";
    this.Testimonial = "2";
    this.GeneralFeedback = "3";
    this.CaseStudy = "4";
    this.Complaint = "5";
    this.Article = "6";
    this.BugSubmission = "7";
    this.FeatureRequest = "8";
    this.CommunityItems = "9";
    this.ForumPost = "10";
}

function ContributionStatus()
{
    this.Draft = "21";
    this.Submitted = "22";
    this.WaitingForReview = "23";
    this.InReview = "24";
    this.ChangesRequired = "25";
    this.Approved = "26";
}

function RegisterWindow()
{
    /* 
    This function is used during onload event of a window, so that the desktopwindow will 
    respond to move or click events of this document.
    */
    
    var dm = ISGetDesktopManager();
    if (dm)
        dm.RegisterEvents(window, true);
    
    dm = null;
}

function TrimString(sInString)
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function global_window_onload()
{
    isPopup_CloseAcrossFrameClick = true;
}

function global_window_onunload()
{
    window.detachEvent("onload", global_window_onload);
    window.detachEvent("onunload", global_window_onunload);
}

if (window.attachEvent)
{
    window.attachEvent("onload", global_window_onload);
    window.attachEvent("onunload", global_window_onunload);
}
else
    window.addEventListener("load", global_window_onload, false);
    
function OpenShortcut(dm, scName)
{
    var shortcut = dm.ShortcutIcons.GetNamedItem("sc" + scName);
    
    if (shortcut != null)
        shortcut.Open();
    else
    {
        var fe = dm.GetContentWindow().ISGetObject("feNav");
        var allButtons = fe.GetAllButtons();
        var button = allButtons.GetNamedItem("btn" + scName);
        
        if (button != null)
            button.Open();
    }
}

function OpenNewBrowser(myPage,myName,browserWidth,browserHeight,scrollBar,windowPosition)
{
    var LeftPosition = (screen.width);
    var TopPosition = (screen.height);
    
    if (windowPosition == "random")
    {
        if (LeftPosition)
            LeftPosition = Math.floor(Math.random()*(screen.width-browserWidth));
        else
            LeftPosition = 100;
        
        if (TopPosition)
            TopPosition = Math.floor(Math.random()*((screen.height-browserHeight)-75));
        else
            TopPosition = 100;
    }
    
    if (windowPosition == "center" || windowPosition == null)
    {
        if (LeftPosition)
            LeftPosition = (screen.width-browserWidth)/2;
        else
            LeftPosition = 100;
           
        if (TopPosition)
            TopPosition = (screen.height-browserHeight)/2;
        else
            TopPosition = 100;
    }
    
    var settings = 'width=' + browserWidth +', height=' + browserHeight + ', top=' + TopPosition + ', left=' + LeftPosition + ', scrollbars=' + scrollBar + ', location=yes, directories=yes, status=yes, menubar=yes, toolbar=yes, resizable=yes';
    window.open(myPage,myName,settings);
}

function GoToHelpAndSupport()
{    
     OpenNewBrowser('http://support.intersoftpt.com/','','800','600','yes','center');
}
