
    String.prototype.trim = function() { //removes spaces from front and back 
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }

    function querySt(ji) {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i = 0; i < gy.length; i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return unescape(ft[1]); //removes space before string.for eg. "%20%20logos" then returns "logos"
            }
        }
    }

    function changeClass(elementID, newClass) {
        var element = document.getElementById(elementID);
        
        if (element == null) {
            return;
        }

        element.setAttribute("class", newClass); //For Most Browsers
        element.setAttribute("className", newClass); //For IE; harmless to other browsers.

        if (elementID != 'custom_sw_development') {
            element = document.getElementById('custom_sw_development');
            if (element != null) {
                element.setAttribute("class", ''); //For Most Browsers
                element.setAttribute("className", ''); //For IE; harmless to other browsers.
            }
        }
//        if (elementID != 'projects') {
//            element = document.getElementById('projects');
//            if (element != null) {
//                element.setAttribute("class", ''); //For Most Browsers
//                element.setAttribute("className", ''); //For IE; harmless to other browsers.
//            }
//        }

    }

    function openPage(elementID, pageName) {
        changeClass(elementID, 'expand');
        document.getElementById('ifrm').src = pageName;
    }


    //ref: http://www.dynamicdrive.com/forums/showthread.php?t=6074
    var active = null;
    var gIsMenuHeader = false;
    var changeState = (function() { 
        return function(link, isMenuHeader, category, action) {
            _gaq.push(['_trackEvent', category, action]); //track click event
            
            if (active == link) {
                //when we click same link again, then active(previous) and current link is same, so do nothing.
            } else if (active) {
                if (gIsMenuHeader) {
                    //if previously selected link is menu header, change color to blue. If it's inner menu item, then change color to white
                    active.style.color = '#0099FF'; //blue
                }
                else {
                    active.style.color = '#CCCCCC'; //white
                }
                //new selected link should be of brown color
                (active = link).style.color = '#993300'; //brown 
            } else { //when no link is selected or active
                var state = 'active';

                if (link.style.color == '#CCCCCC' || link.style.color == '#0099FF') { //white or blue menu item link color
                    state = 'inactive';
                    active = link;
                }
                
                if (state == 'active') {
                    link.style.color = '#993300';
                }
                else {
                    if (gIsMenuHeader) {
                        link.style.color = '#0099FF';
                    }
                    else {
                        link.style.color = '#CCCCCC';
                    }
                }
            }
            gIsMenuHeader = isMenuHeader;
        };
    })();


    function page_load() {
        var section = querySt("section"); //"section" string has to be in small letters in url
        if (section == undefined || section == "") {
            var link = null;
            if (document.getElementById('mobile') != null) {
                link = document.getElementById('mobile');
                changeState(link, false, 'Services - Custom Software Development', 'Mobile Applications');
            } else if (document.getElementById('a_projects') != null) {
	            link = document.getElementById('a_projects');
	            changeState(link, true, 'Portfolio - Sample Projects', 'Projects Page');
            } else if (document.getElementById('a_who') != null) {
                link = document.getElementById('a_who');
                changeState(link, true, 'About Us - Who We Are', 'Who We Are');
            } else if (document.getElementById('a_contact') != null) {
                link = document.getElementById('a_contact');
                changeState(link, true, 'Contact Us - Contact Information', 'Contact Information');
            } else if(document.getElementById('a_clients')) {
                link = document.getElementById('a_clients');
                changeState(link, true, 'Portfolio - Clients', 'Clients');
            }
            active = link;
            return;
        }
        var strSection = new String(section.toUpperCase());
        strSection = strSection.trim(); //removes spaces from front

        /* SERVICES TAB */
        if (strSection == "DESKTOP") {
            openPage('custom_sw_development', 'Services_CustomSoftware_DesktopApps.html');
            var link = document.getElementById('desktop');
            changeState(link, false, 'Services - Custom Software Development', 'Desktop Applications');
            active = link;
        }
        else if (strSection == "WEB") {
            openPage('custom_sw_development', 'Services_CustomSoftware_WebApps.html');
            var link = document.getElementById('web');
            changeState(link, false, 'Services - Custom Software Development', 'Web Applications');
            active = link;
        }
        else if (strSection == "MOBILE") {
            openPage('custom_sw_development', 'Services_CustomSoftware_MobileApps.html');
            var link = document.getElementById('mobile');
            changeState(link, false, 'Services - Custom Software Development', 'Mobile Applications');
            active = link;
        }
        else if (strSection == "SERVICES") {
            openPage('custom_sw_development', 'Services_CustomSoftware_WebServices.html');
            var link = document.getElementById('services');
            changeState(link, false, 'Services - Custom Software Development', 'Web Services');
            active = link;
        }
        else if (strSection == "SERVER") {
            openPage('custom_sw_development', 'Services_CustomSoftware_ServerApps.html');
            var link = document.getElementById('server');
            changeState(link, false, 'Services - Custom Software Development', 'Server Applications');
            active = link;
        }
        else if (strSection == "SYNC") {
            openPage('custom_sw_development', 'Services_CustomSoftware_SyncMiddleware.html');
            var link = document.getElementById('sync');
            changeState(link, false, 'Services - Custom Software Development', 'Sync Middleware');
            active = link;
        }

        else if (strSection == "SKETCH") {
            openPage('prototype_design', 'Services_Phototype_SketchFlow.html');
            var link = document.getElementById('sketch');
            changeState(link, false, 'Services - Prototype Design', 'Expression SketchFlow');
            active = link;
        }
        else if (strSection == "BLEND") {
            openPage('prototype_design', 'Services_Phototype_Blend.html');
            var link = document.getElementById('blend');
            changeState(link, false, 'Services - Prototype Design', 'Expression Blend');
            active = link;
        }
        else if (strSection == "GRAPHIC") {
            openPage('prototype_design', 'Services_Phototype_Graphic.html');
            var link = document.getElementById('graphic');
            changeState(link, false, 'Services - Prototype Design', 'Graphic Design');
            active = link;
        }
        else if (strSection == "XAML") {
            openPage('prototype_design', 'Services_Phototype_XAML.html');
            var link = document.getElementById('xaml');
            changeState(link, false, 'Services - Prototype Design', 'XAML');
            active = link;
        }

        else if (strSection == "CONCEPTS") {
            openPage('ui_design', ' Services_Graphic_Concepts.html');
            var link = document.getElementById('concepts');
            changeState(link, false, 'Services - User Interface Design', 'Concepts');
            active = link;
        }   
       
        else if (strSection == "WIREFRAMES") {
            openPage('ui_design', 'Services_UI_Wireframes.html');
            var link = document.getElementById('wireframes');
            changeState(link, false, 'Services - User Interface Design', 'Wireframes');
            active = link;
        }
        else if (strSection == "TEMPLATES") {
            openPage('ui_design', 'Services_UI_ControlTemplate.html');
            var link = document.getElementById('templates');
            changeState(link, false, 'Services - User Interface Design', 'Control Templates');
            active = link;
        }
        else if (strSection == "CONTROLS") {
            openPage('ui_design', 'Services_UI_UserControls.html');
            var link = document.getElementById('controls');
            changeState(link, false, 'Services - User Interface Design', 'User Controls');
            active = link;
        }
        else if (strSection == "SHADES") {
            openPage('ui_design', 'Services_UI_Background.html');
            var link = document.getElementById('shades');
            changeState(link, false, 'Services - User Interface Design', 'Background Shades');
            active = link;
        }
        else if (strSection == "THEMES") {
            openPage('ui_design', 'Services_UI_Themes.html');
            var link = document.getElementById('themes');
            changeState(link, false, 'Services - User Interface Design', 'Themes');
            active = link;
        }
        else if (strSection == "ICONS") {
            openPage('graphics_design', 'Services_Graphic_Icons.html');
            var link = document.getElementById('icons');
            changeState(link, false, 'Services - Graphics Design', 'Icons');
            active = link;
        }
        else if (strSection == "LOGOS") {
            openPage('graphics_design', 'Services_Graphic_Logos.html');
            var link = document.getElementById('logos');
            changeState(link, false, 'Services - Graphics Design', 'Logos');
            active = link;
        }
        else if (strSection == "ADS") {
            openPage('graphics_design', 'Services_Graphic_BackgroundAds.html');
            var link = document.getElementById('ads');
            changeState(link, false, 'Services - Graphics Design', 'Background/Ads');
            active = link;
        }
        else if (strSection == "BANNERS") {
            openPage('graphics_design', 'Services_Graphic_ShadesBanners.html');
            var link = document.getElementById('banners');
            changeState(link, false, 'Services - Graphics Design', 'Shades/Banners');
            active = link;
        }
        else if (strSection == "VECTOR") {
            openPage('graphics_design', 'Services_Graphic_VectorGraphicXAML.html');
            var link = document.getElementById('vector');
            changeState(link, false, 'Services - Graphics Design', 'Vector Graphics using XAML');
            active = link;
        }
        else if (strSection == "DBA") {
            openPage('dba', 'Services_DatabaseAdmin.html');
            var link = document.getElementById('a_dba'); //menuHeader is true
            changeState(link, true, 'Services - Database Administration', 'Database Administration');
            active = link;
        }
        else if (strSection == "REPORTING") {
            openPage('reporting', 'Services_Reporting.html');
            var link = document.getElementById('a_reporting');
            changeState(link, true, 'Services - Reporting', 'Reporting');
            active = link;
        }
        else if (strSection == "DOC") {
            openPage('doc', 'Services_Documentation.html');
            var link = document.getElementById('a_doc');
            changeState(link, true, 'Services - Documentation', 'Documentation');
            active = link;
        }
        else if (strSection == "QA") {
            openPage('qa', 'Services_QA.html');
            var link = document.getElementById('a_qa');
            changeState(link, true, 'Services - Quality Assurance', 'Quality Assurance');
            active = link;
        }
        else if (strSection == "PM") {
            openPage('pm', 'Services_ProjectManagement.html');
            var link = document.getElementById('a_pm');
            changeState(link, true, 'Services - Project Management', 'Project Management');
            active = link;
        }
        else if (strSection == "SUPPORT") {
            openPage('support', 'Services_Support.html');
            var link = document.getElementById('a_support');
            changeState(link, true, 'Services - Support', 'Support');
            active = link;
        }
        

    /* PORTFOLIO TAB */ 
	
		 else if (strSection == "PROJECTS") {
		    openPage('projects', 'Projects_Mainpage.html');
            var link = document.getElementById('a_projects');
            changeState(link, true, 'Portfolio - Sample Projects', 'Projects Page');
            active = link;
        }
		else if (strSection == "TOG") {
            openPage('projects', 'Projects_TeeTimesOnTheGo-TOG.html');
            var link = document.getElementById('a_projects');
            changeState(link, true, 'Portfolio - Sample Projects', 'Tee Times On The Go');
            active = link;
        }		
		else if (strSection == "IPADSHOWCASE") {
            openPage('projects', 'Projects_iPadShowcase_si.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'iPad Showcase');
            active = link;
        }
		else if (strSection == "TOURNAMENT") {
            openPage('projects', 'Projects_TournamentManagement.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Tournament Management');
            active = link;
        }
		else if (strSection == "AT") {
            openPage('projects', 'Projects_Healthcare_At.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Acquisition Software');
            active = link;
        }
		else if (strSection == "MTICKETING") {
            openPage('projects', 'Projects_SymfoneeMobileTicketing.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Mobile Ticketing');
            active = link;
        }
	
        else if (strSection == "TICKETING") {
            openPage('projects', 'Projects_TicketingVenue.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Ticketing');
            active = link;
        }
        else if (strSection == "MMO") {
            openPage('projects', 'Projects_MMO-Hospitality.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'MMO');
            active = link;
        }
		else if (strSection == "PRO") {
            openPage('projects', 'Projects_Healthcare_Pro.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Analysis Software');
            active = link;
        }
		
        else if (strSection == "AFIS") {
            openPage('projects', 'Projects_AFIS-LawEnforcement.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'AFIS');
            active = link;
        }
        else if (strSection == "PRM") {
            openPage('projects', 'Projects_PRM-Hospitality.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'PRM');
            active = link;
        }
        else if (strSection == "HOA") {
            openPage('projects', 'Projects_HostAlert-Hospitality.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Host Alert');
            active = link;
        }
        else if (strSection == "SURVEY") {
            openPage('projects', 'Projects_Survey-Hospitality.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Survey');
            active = link;
        }
        else if (strSection == "VERI5") {
            openPage('projects', 'Projects_Veri5-HealthCare.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Veri5');
            active = link;
        }
        else if (strSection == "MARLIN") {
            openPage('projects', 'Projects_Marlin-DataAcquisition.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Marlin');
            active = link;
        }
        else if (strSection == "DMD") {
            openPage('projects', 'Projects_DMD-Military.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'DMD');
            active = link;
        }
        else if (strSection == "MOA") {
            openPage('projects', 'Projects_MOA-LawEnforcement.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'MOA');
            active = link;
        }
		else if (strSection == "ZNOSE") {
            openPage('projects', 'Projects_zNose.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'zNose');
            active = link;
        }	
		else if (strSection == "OSW") {
            openPage('projects', 'Projects_On-Schedule.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'On-Schedule');
            active = link;
        }	
        else if (strSection == "WEBDESIGNS") {
            openPage('webdesigns', 'Projects_WebDesigns.html');
            var link = document.getElementById('a_webdesigns');
            changeState(link, true, 'Portfolio - Sample Projects', 'Web Designs');
            active = link;
        }
        else if (strSection == "FLASH") {
            openPage('projects', 'Projects_Flash.html');
            var link = document.getElementById('a_projects');
            changeState(link, false, 'Portfolio - Sample Projects', 'Flash');
            active = link;
        }
        else if (strSection == "CLIENTS") {
            openPage('clients', 'Portfolio_Clients.html');
            var link = document.getElementById('a_clients');
            changeState(link, true, 'Portfolio - Clients', 'Clients');
            active = link;
        }
		 else if (strSection == "TESTIMONIALS") {
            openPage('testimonials', 'Portfolio_Testimonials.html');
            var link = document.getElementById('a_testimonials');
            changeState(link, true, 'Portfolio - Testimonials', 'Testimonials');
            active = link;
        }
        else if (strSection == "TECHNOLOGIES") {
            openPage('technologies', 'Portfolio_Technologies.html');
            var link = document.getElementById('a_technologies');
            changeState(link, true, 'Portfolio - Technologies', 'Technologies');
            active = link;
        }

    /* ABOUT US TAB */
        else if (strSection == "WHO") {
            openPage('who', 'AboutUs_WhoWeAre.html');
            var link = document.getElementById('a_who');
            changeState(link, true, 'About Us - Who We Are', 'Who We Are');
            active = link;
        }
        else if (strSection == "WHAT") {
            openPage('what', 'AboutUs_WhatWeDo.html');
            var link = document.getElementById('a_what');
            changeState(link, true, 'About Us - What We Do', 'What We Do');
            active = link;
        }
        else if (strSection == "WHY") {
            openPage('why', 'AboutUs_WhyUs.html');
            var link = document.getElementById('a_why');
            changeState(link, true, 'About Us - Why Us', 'Why Us');
            active = link;

        }
		else if (strSection == "GOVERNMENT") {
            openPage('government', 'AboutUs_Government.html');
            var link = document.getElementById('a_government');
            changeState(link, true, 'About Us - Government', 'Government');
            active = link;

        }
        
    /* CONTACT US TAB */
        else if (strSection == "CONTACT") {
            openPage('contact', 'ContactUs_Information.html');
            var link = document.getElementById('a_contact');
            changeState(link, true, 'Contact Us - Contact Information', 'Contact Information');
            active = link;
        }
        else if (strSection == "JOB") {
            openPage('job', 'ContactUs_Jobs.html');
            var link = document.getElementById('a_job');
            changeState(link, true, 'Contact Us - Career Opportunity', 'Career Opportunity');
            active = link;
        }
        else if (strSection == "TERMS") {
            openPage('terms', 'ContactUs_TermsOfUse.html');
            var link = document.getElementById('a_terms');
            changeState(link, true, 'Contact Us - Terms of Use', 'Terms of Use');
            active = link;
        }

        //default page to open when quesry string is wrong
        else { 
            //openPage('custom_sw_development', 'Services_CustomSoftware_DesktopApps.html');


//NEW WAY
            var link = null;
            if (document.getElementById('mobile') != null) {
                link = document.getElementById('mobile');
                changeState(link, false, 'Services - Custom Software Development', 'Mobile Applications');
                openPage('custom_sw_development', 'Services_CustomSoftware_MobileApps.html');
            } 
            /* else if (document.getElementById('mticketing') != null) {
	            link = document.getElementById('mticketing');
	            changeState(link, false, 'Portfolio - Sample Projects', 'Mobile Ticketing');
	            openPage('projects', 'Projects_SymfoneeMobileTicketing.html');
	          */
            else if (document.getElementById('a_projects') != null) {
                link = document.getElementById('a_projects');
                changeState(link, true, 'Portfolio - Sample Projects', 'Projects Page');
	            openPage('projects', 'Projects_Mainpage.html');
            } else if (document.getElementById('a_who') != null) {
                link = document.getElementById('a_who');
                changeState(link, true, 'About Us - Who We Are', 'Who We Are');
                openPage('who', 'AboutUs_WhoWeAre.html');
            } else if (document.getElementById('a_contact') != null) {
                link = document.getElementById('a_contact');
                changeState(link, true, 'Contact Us - Contact Information', 'Contact Information');
                openPage('contact', 'ContactUs_Information.html');
            } else if(document.getElementById('a_clients')) {
                link = document.getElementById('a_clients');
                changeState(link, true, 'Portfolio - Clients', 'Clients');
            }
            active = link;
        }
    }
    
    
    page_load();



