﻿/************************************************
common.debug.js
Shared javascript file for sales pages
(debug version)
************************************************/

// Release jQuery $ shortcut
var $j = jQuery.noConflict();


$j(document).ready(function() {
    //decorate button
    //quick fix js error on ie6
    if ($j.browser.msie && parseInt($j.browser.version) < 7) {
        var index = document.domain.toLowerCase().lastIndexOf("englishtown.com", 0);
        if (index >= 0 && index + 15 == document.domain.length) {
            document.domain = "englishtown.com";
        }
    }
    $j('.button').each(function() {
        var wrapDiv = $j(this).wrapInner('<span class="buttonColor"></span>').wrap('<span class="middle"></span>').parent().wrap('<div></div>').parent().append('<span class="right"></span>').prepend('<span class="left"></span>');
        wrapDiv.addClass($j(this).attr('class'));
        $j(this).removeClass();
    });

    calculateHW();

    if ($j.browser.msie && parseInt($j.browser.version) < 7) {
        $j('img[src*=".png"]').each(function() {
            $j(this).addClass('neediepngfix');
        });
        // $j('div,span').each(function() {
        // if (($j(this).css('background') && $j(this).css('background').indexOf('.png') > -1) || ($j(this).css('background-image') && $j(this).css('background-image').indexOf('.png') > -1))
        //   $j(this).addClass('neediepngfix');
        // });
    }

    // Add decorator div to language dropdown
    $j('#languagelist').prepend('<div class="top"/>');

		$j('a.videoPlayerFloat').click(function(){videoPlayerFloat($j(this).attr('href'),$j(this).attr('title'));return false;});	
		
    // start the school tour if request.
    window.setTimeout(function() { if (window.startSchoolTour) openSchoolTour(); }, 1000);
});

$j(window).resize(calculateHW);

function calculateHW() {
    var viewWidth, viewHeight, bodyWidth, bodyHeight;

    bodyHeight = $j(document).height();
    bodyWidth = $j(document).width();

    if (self.innerHeight) // all except Explorer
    {
        viewWidth = self.innerWidth;
        viewHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        viewWidth = document.documentElement.clientWidth;
        viewHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        viewWidth = document.body.clientWidth;
        viewHeight = document.body.clientHeight;
    }

    if (viewWidth < 982) {
        bodyWidth = 982;
    }

    if (bodyHeight < viewHeight) {
        bodyHeight = viewHeight;
    }

    $j('#dim_bg').css('height', bodyHeight);
    $j('#dim_bg iframe').css('height', bodyHeight);
    $j('#popupcitypicker').css('height', bodyHeight);
    $j('#dim_bg').css('width', bodyWidth);
    $j('#dim_bg iframe').css('width', bodyWidth);
    $j('#popupcitypicker').css('width', bodyWidth);
}
/*
function videoPlayerFloat(close, url, title, content) {
    $j('#dim_bg').show();
    $j('#dim_bg').css('opacity', 0).fadeTo('slow', 0.7);

    $j('#popupwindow').show();
    $j('#popupwindow').html('<div class="video"></div>');
    $j('#popupwindow .video').html('<div class="close"><a href="javascript:void(0);" class="closePopup">'+close+'</a></div><div class="videoplayer"></div><div class="title"></div><div class="upsell"></div>')
    $j('#popupwindow .video .videoplayer').html(generateVideoPlayer(url)); //for youtube; suggesting to create a video player generation function to translate the URL and insert the correct code
    $j('#popupwindow .video .title').html(title);
    $j('#popupwindow .video .upsell').html(content);

    $j('#popupwindow a.closePopup').click(function() {
        closePopup();
        return false;
    });
}
*/
function CheckNumbers(e) {
    var keynum;
    var keychar;
    var numcheck;
    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if (e.shiftKey)
        return false;
    // escapce , . / ; ' [ ] - = and space
    if (keynum == 186 || keynum == 188 || keynum == 32 || keynum == 190 || keynum == 192 ||
        keynum == 187 || keynum == 191 || keynum == 59 || keynum == 222 || keynum == 220 ||
        keynum == 189 || keynum == 219 || keynum == 221 || keynum == 109 || keynum == 107)
        return false;
    // Determine whether the keystroke is a number from the keypad.
    if (keynum >= 96 && keynum <= 105)
        return true;

    keychar = String.fromCharCode(keynum);
    numcheck = /[A-Za-z]/;
    return !numcheck.test(keychar);
}

function openPopup(url, name, width, height, top, left) {
    if (!width) width = 600;
    if (!height) height = 600;
    if (!top) top = 200;
    if (!left) left = 300;

    // If the user opens the popup window which means user has some action on the page,
    // then the Popunder should be stopped forever.
    PopupManager.stopPopunder();
    var newWindow = window.open(url, name, 'height=' + height + ',width=' + width + ',scrollbars=1,resizable=0,top=' + top + ',left=' + left + ',status=yes');
    return newWindow;
}

function openWindow(url, name, width, height, top, left) {
    if (!width) width = 1024;
    if (!height) height = 800;
    if (!top) top = 50;
    if (!left) left = 100;

    // If the user opens another window which means user has some action on the page,
    // then the Popunder should be stopped forever.
    PopupManager.stopPopunder();

    var newWindow = window.open(url, name, 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',status=1, scrollbars=1,resizable=1, toolbar=1,location=1,menubar=1');
    return newWindow;
}

function changeLanguage(value) {
    PopupManager.stopPopup();

    var location = String(document.location);

    // Remove the last "#" in the url.
    var pos = location.lastIndexOf("#");
    if (pos >= 0) {
        location = location.substring(0, pos);
    }

    location = location.replace(/(&)?lng=[^&]*/, "").replace(/\?$|(\?)&/, "$1");
    document.location = location + (/\?/.test(location) ? "&" : "?") + "lng=" + value;
}

function sp_callWebSvc(wsUrl, param, callback) {
    if (param == null || param == "") {
        param = "{}";
    }

    $j.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: wsUrl,
        data: param,
        dataType: "json",
        success: callback
    });
}

// Menu scripts
$j(document).ready(function() {

    //decorate tab
    var activeItem = $j('.etm-ctnr .etm-left li.active');
    if (activeItem.hasClass('first')) {
        $j('a', activeItem).wrap('<span class="text"></span>').parent().wrap('<div id="gt-over"></div>').parent().append('<span class="right"></span>').prepend('<span class="left"></span>');
    } else {
        $j('a', activeItem).wrap('<span class="text"></span>').parent().wrap('<div id="gt-over"></div>').parent().append('<span class="right"></span>').prepend('<span class="left"></span>').parent().before($j('<li class="extra"><a> </a></li>'));
    }

    //fix ie6
    if ($j.browser.msie && parseInt($j.browser.version) < 7) {
        //fix simbling selector of login panel
        $j('.etm-ctnr .etm-right div.customitem > a').addClass('menuitem');
    }

    //fix ie  
    if ($j.browser.msie) {
        //fix login panel dropdown
        $j('.etm-ctnr .etm-right div.customitem').hover(function() {
            $j(this).addClass('hover');
        }, function() {
            $j(this).removeClass('hover');
        });

        //fix submenu dropdown
        $j('.etm-sub-ctnr ul.etm-left li').hover(function() {
            $j(this).addClass('hover');
        }, function() {
            $j(this).removeClass('hover');
        });

        $j('.etm-sub-ctnr ul.etm-left li.dir').hover(function() {
            $j(this).addClass('dir_hover');
        }, function() {
            $j(this).removeClass('dir_hover');
        });

        //fix choose language dropdown
        $j('#gf-language_swapper ul.dropdown li').hover(function() {
            $j(this).addClass('hover');
        }, function() {
            $j(this).removeClass('hover');
        });

    }

    $j('.etm-sub-ctnr .etm-left .dir ul').append('<div class="sub_drd_deco"><div class="bgleft"></div><div class="bgext"></div><div class="bgright"></div></div>');
}
);

// Popup Manager Scripts
PopupManager = new function() {

    var CookieName = "nsplegacy";
    var CookieDelimiter = "~";

    var EESmallPopup = "EESmallPopup";
    var EEPopunder = "EEPopunder";
    var EEMediumPopup = "EEMediumPopup";
    var MainDomain = "englishtown.com";

    var HomePage = "home.aspx";
    var CommercePage = "/commerce/";
    var PopupPageList = ["forgot-password.aspx", "login.aspx", "school-tour.aspx", "comparison-table.aspx", "features-table.aspx", "cambridge.aspx", "class-topics.aspx", "ee-depart.aspx", "pt-thankyou.aspx", "ee-thankyou.aspx", "ee-subscribe.aspx", "ee-subscribe-thankyou.aspx", "contact-us.aspx", "conditions.aspx", "privacy.aspx", "security.aspx", "terms.aspx"];

    var _stopPopup = false;
    var _stopPopunder = false;
    var _stopMediumPopup = false;

    this.stopPopup = function() {
        _stopPopup = true;
    };

    this.suspendPopup = function() {
        // Store current status
        var currentStatus = _stopPopup;

        // Stop popup
        _stopPopup = true;

        return currentStatus;
    };

    this.resumePopup = function(originalStatus) {
        _stopPopup = originalStatus;
    };

    this.stopPopunder = function() {
        _stopPopunder = true;
        this.saveResultToCookie(EEPopunder, "True");
    };

    this.stopMediumPopup = function() {
        _stopMediumPopup = true;
        this.saveResultToCookie(EEMediumPopup, "True");
    };

    // The init function is called in jQuery(document).ready(fn);
    this.init = function(popupSetting) {
        //debugger;

        // Prevent the popup displays when user leave the page before the page is fully initialized.
        // E.g. User open the school page, before the page is fully loaded, updateDocumentLink() method is not finsihed, click
        //      Home page. At this time, the ee-subscribe page should not display.
        // The popup function will start to work when the updateDocumentLink() method is finished.
        var currentStatus = this.suspendPopup();

        _popupSetting = popupSetting;

        var popupResult = this.getCurrentResult();
        if (popupResult == null) {
            // Seems the client user does not allow cookie or the required cookie is missing.
            // Do not popup any screens, otherwise, user will feel angry.
            return;
        }

        // Can not rely on the popup type from server side, since the page will not hit the server.
        if (popupResult.PopupType.indexOf(EESmallPopup) >= 0) {
            this.initEESmallPopup();
        }

        if (popupResult.PopupType.indexOf(EEPopunder) >= 0) {
            this.initEEPopunder();
        }

        if (popupResult.PopupType.indexOf(EEMediumPopup) >= 0) {
            this.initEEMediumPopup();
        }

        // Update current page's links to stop the popup based on conditions.
        thisObj = this;
        window.setTimeout(function() { updateDocumentLink(); thisObj.resumePopup(currentStatus); }, 1000);
    };

    this.getCurrentResult = function() {
        //debugger

        var popupResult = this.getResultFromCookie();
        if (popupResult == null) {
            return null;
        }

        // Decide what kind of popup windows should be displayed this time.
        var popupTypes = "";
        if (_popupSetting.EnableSmallPopup
            && !popupResult.EESmallPopupDisplayed
            && this.checkPage(HomePage)
            && popupResult.FirstVisitPage == HomePage) {
            popupTypes += EESmallPopup;
        }

        if (_popupSetting.EnablePopunder
            && !popupResult.PopunderDisplayed
            && this.checkPage(HomePage)) {
            popupTypes += EEPopunder;
        }

        if (_popupSetting.EnableMediumPopup
            && !popupResult.MediumPopupDisplayed
            && _popupSetting.EnableSmallPopup) {
            //debugger;
            // If the current page is one of the following pages:
            // 1. ee-thankyou.aspx
            // 2. ee-subscribe-thankyou.aspx
            // 3. pt-thankyou.aspx
            // Stop the MediumPopup forever.
            if (this.checkPage("ee-thankyou.aspx")
            || this.checkPage("ee-subscribe-thankyou.aspx")
            || this.checkPage("pt-thankyou.aspx")) {
                this.stopMediumPopup();
            }
            else {
                if (!this.checkPage(HomePage)
                    && !this.checkPage(CommercePage)
                    && !this.checkPopupPage()) {
                    popupTypes += EEMediumPopup;
                }
            }
        }

        popupResult.PopupType = popupTypes;

        return popupResult;
    };

    this.getResultFromCookie = function() {

        var cookie = getCookie(CookieName);
        if (cookie == null) {
            // Create a new cookie
            cookie = this.generateDefaultCookie();
            if (cookie == null) {
                return;
            }
        }

        var popupResult = {};
        var values = cookie.split(CookieDelimiter);

        // Recover the settings from last cookie value.
        if (values[0] == "True") {
            popupResult.EESmallPopupDisplayed = true;
        }
        else {
            popupResult.EESmallPopupDisplayed = false;
        }

        if (values[1] == "True") {
            popupResult.PopunderDisplayed = true;
        }
        else {
            popupResult.PopunderDisplayed = false;
        }

        if (values[2] == "True") {
            popupResult.MediumPopupDisplayed = true;
        }
        else {
            popupResult.MediumPopupDisplayed = false;
        }

        // Get the first vist page
        popupResult.FirstVisitPage = values[3];

        return popupResult;
    };

    this.generateDefaultCookie = function() {
        //debugger
        var path = window.location.pathname;
        var pageName = path.substring(path.lastIndexOf('/') + 1);

        var values = [];
        values[0] = "False";
        values[1] = "False";
        values[2] = "False";
        values[3] = pageName;

        var cookieValue = values.join(CookieDelimiter);
        setCookie(CookieName, cookieValue, 365, "/", this.getDomain());
        return getCookie(CookieName);
    };

    this.saveResultToCookie = function(type, value) {
        //debugger
        var cookie = getCookie(CookieName);
        if (cookie == null) return;

        var values = cookie.split(CookieDelimiter);

        if (type == EESmallPopup) {
            values[0] = value;
        } else if (type == EEPopunder) {
            values[1] = value;
        } else if (type == EEMediumPopup) {
            values[2] = value;
        }

        var cookieValue = values.join(CookieDelimiter);
        setCookie(CookieName, cookieValue, 365, "/", this.getDomain());
    };

    this.checkPage = function(pageName) {
        return window.location.pathname.lastIndexOf(pageName) >= 0;
    };

    this.getDomain = function() {
        if (document.domain.indexOf(MainDomain) >= 0) {
            return MainDomain;
        }
        else {
            return document.domain;
        }
    };

    this.checkPopupPage = function(pageName) {
        var isPopupPage = false;
        for (var i = 0; i < PopupPageList.length; i++) {
            if (this.checkPage(PopupPageList[i])) {
                isPopupPage = true;
                break;
            }
        }
        return isPopupPage;
    };

    this.initEESmallPopup = function() {
        var thisObj = this;
        window.setTimeout(function() {
            //debugger
            thisObj.saveResultToCookie(EESmallPopup, "True");
            $j('#' + _popupSetting.EESmallPopupTarget).show('slide', { direction: 'down', easing: 'easeInCubic' }, 500);
        },
            _popupSetting.EESmallPopupTime * 1000);
    };

    this.initEEPopunder = function() {
        var thisObj = this;
        registerEvent(window, "beforeunload", function() {
            //debugger
            if (_stopPopup || _stopPopunder) return;
            thisObj.saveResultToCookie(EEPopunder, "True");
            var newWindow = window.open("/online/ee-depart.aspx", "winEEPopunder", 'height=800,width=1000,scrollbars=yes,resizable=0,top=50,left=100,status=yes');
            // Let the original window goes to the top.
            if (newWindow != null) {
                newWindow.blur();
            }
        });
    };

    this.initEEMediumPopup = function() {
        var thisObj = this;
        registerEvent(window, "beforeunload", function() {
            //debugger
            if (_stopPopup || _stopMediumPopup) return;
            thisObj.saveResultToCookie(EEMediumPopup, "True");
            var newWindow = window.open("/online/ee-subscribe.aspx", "winEEMediumPopup", 'height=690,width=610,scrollbars=yes,resizable=0,top=50,left=300,status=yes');
        });
    };
};

function getCookie(cookieName) {
    var cookieNameStart, valueStart, valueEnd, cookieValue, returnValue;
    cookieNameStart = document.cookie.indexOf(cookieName + '=');
    if (cookieNameStart < 0) {
        returnValue = null;
    }
    else {
        valueStart = document.cookie.indexOf(cookieName + '=') + cookieName.length + 1;
        valueEnd = document.cookie.indexOf(";", valueStart);
        if (valueEnd == -1) {
            valueEnd = document.cookie.length;
        }
        cookieValue = document.cookie.substring(valueStart, valueEnd);
        returnValue = (cookieValue == '') ? null : unescape(cookieValue);
    }
    return returnValue;
}

function setCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
        ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ((secure) ? ";secure" : "");
}

function updateDocumentLink() {
    var linkList = document.getElementsByTagName("a");
    //debugger
    for (var i = 0; i < linkList.length; i++) {
        var link = linkList[i];

        // When use clicks the link, no matter the link will
        // -- Go to other page
        // -- "Take a tour" link
        // -- Open a popup window
        // Stop the Popunder forever, since user has did some action on the page.
        registerEvent(link, "click", function() {
            //debugger;
            PopupManager.stopPopunder();
        });

        // When user clicks the commerce link, stop the Popunder and MediumPopup forever.
        // Since Popunder has been stopped in first step, here only need to stop MediumPopup forever.
        if (link.href.indexOf("/commerce/") >= 0) {
            registerEvent(link, "click", function() {
                //debugger;
                PopupManager.stopMediumPopup();
            });
        }

        // If the link open a window or navigate to another page in the same site(same domain), then 
        // the popup window should not display.
        if (link.href.indexOf(document.domain) >= 0
            && link.href.indexOf("#") < 0) {
            registerEvent(link, "click", function() {
                //debugger;
                PopupManager.stopPopup();
            });
        }

        // E.g.
        // -- Take a tour in the sub menu
        // -- <a href="javascript:void(0);" onlick="...">text</a>
        if (link.href.indexOf("javascript") >= 0) {
            registerEvent(link, "click", function() {
                //debugger;
                PopupManager.stopPopup();
            });
        }
    }
}

function registerEvent(element, eventName, fn) {
    //debugger
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        element.attachEvent("on" + eventName, fn, false);
    } else if (navigator.userAgent.indexOf("Firefox") > 0) {
        element.addEventListener(eventName, fn, false);
    }
}

function changeParentUrl(url, closeCurrent) {

    //debugger
    if (window.opener != null) {
        // Stop the popup in parent.
        if (window.opener.PopupManager != null) {
            window.opener.PopupManager.stopPopup();
        }

        window.opener.location = url;
    }

    if (closeCurrent) {
        window.close();
    }
}

function openSchoolTourInParent() {
    //debugger
    if (window.opener != null) {
        window.opener.openSchoolTour();
    }

    window.close();
}

function showLoginForm() {
    $j(".customitem").addClass('hover');
    setTimeout(closeLoginForm, 10000);
}

function closeLoginForm() {
    $j(".customitem").removeClass('hover');
    //    $j(".loginpanel").hide();
}
//checks the browser type and instantiates the XMLHttp object.
function GetXmlHttpObject(handler)
{    
   var objXmlHttp=null; //Create the local xmlHTTP object instance 
   
   //Create the xmlHttp object depending on the browser 
    if (navigator.userAgent.indexOf("MSIE")>=0)    
    {        
      //if not IE default to Msxml2 
       var strName="Msxml2.XMLHTTP";
       if (navigator.appVersion.indexOf("MSIE 5.5")>=0)        
       {            
         strName="Microsoft.XMLHTTP"        
       }     
       //Create the object 
       try        
         { 
            objXmlHttp=new ActiveXObject(strName)            
            objXmlHttp.onreadystatechange=handler    
            return objXmlHttp        
         }catch(e)        
         {            
            alert("Error. Scripting for ActiveX might be disabled")            
            return        
         }    
      }    
       // other browsers eg mozilla , netscape and safari 
      if (navigator.userAgent.indexOf("Mozilla")>=0)    
      {        
        objXmlHttp=new XMLHttpRequest();        
        objXmlHttp.onload=handler;        
        objXmlHttp.onerror=handler;  
        
         //Return the instantiated object 
        return objXmlHttp;    
       }
}
function GetPassword(objEmail)
{
   if (objEmail != null &&  objEmail.value == "" || !isValidEmail(objEmail.value)){
		$j("#EmailError").css("display", "block");
		$j("#EmailError").text($j("#EmailReminderError").val());
		objEmail.focus();
	}
	else
	{
	    SendReminderEmail(objEmail.value);
	}
}
var parameter = function()
{
    var parameterList = new Array();
    this.add = function(name,value)
    {
        parameterList[name] = value;
        return this;
    }
    //(<param1>value1</param1> <param2>value2</param2> )
    this.toXml = function()
    {
        var xml = "";
        for(var p in parameterList)
        {
            if(typeof(parameterList[p]) != "function")
                xml += "<" + p + ">" + parameterList[p].toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</" + p + ">";
        }
        return xml;   
    }
    // (Param1=Value1&Param2=Value2&)
    this.toPost = function()
    {
        var postStr = "";
        for (var p in parameterList)
        {
            if (typeof(parameterList[p]) != "function")
                postStr += p + "=" + parameterList[p] + "&";
        }
        postStr = postStr.substr(0,postStr.length - 1);
        return postStr;
    }
}


function SendReminderEmail(email)
{
    var sMethod = "SendReminderEmail"; 
    var para = new parameter();        
    para.add("emailOrUsername", email);          
    var sReuqestParam = getRequest_Soap12(sMethod, para);

    var result = soapRequest("/_services/forgotpwdsvc.asmx", sReuqestParam, sMethod);
    $j("#EmailError").css("display", "block");
    if(result=="<IsSuccess>true</IsSuccess>")
    {
        $j("#EmailError").text( $j("#EmailReminderhdn").val());
    }
    else
    {
        $j("#EmailError").text($j("#EmailReminderError").val());
    }
}

function getRequest_Soap12(sMethod, para)
{  
    var sRequest = "<?xml version='1.0' encoding='utf-8'?> ";
        sRequest += "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
        sRequest += " xmlns:xsd='http://www.w3.org/2001/XMLSchema'";
        sRequest += " xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>";
        sRequest += "<soap12:Body>  ";
        sRequest += "<" + sMethod + " xmlns='http://tempuri.org/'> ";
        sRequest += para.toXml() + " ";
        sRequest += "</" + sMethod + "> ";
        sRequest += "</soap12:Body> ";
        sRequest += "</soap12:Envelope>";
    return sRequest;  
}

function soapRequest(sWebServiceName, sRequestParam, sMethod)
{
    xmlHttp = GetXmlHttpObject(DoNothing);
    if (!xmlHttp)
    {
        return false;
    }
   
    //SOAP1.2
    xmlHttp.open("POST", sWebServiceName, false);
    xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");
    
    xmlHttp.send(sRequestParam);
    
    var sResponse = xmlHttp.responseText;
    var sResult = getWebServiceResponseValue(sResponse, sMethod)
    return sResult;
}
function DoNothing()
{
    return;
}
function getWebServiceResponseValue(sResponse, sMethod)
{
    var pos1 = sResponse.indexOf("<" + sMethod + "Result>");
    var pos2 = sResponse.indexOf("</" + sMethod + "Result>");
    var index = pos1 + sMethod.length + 2 + 6;
    var result = sResponse.substr(index,pos2 - index);
    return result;
}
function isValidEmail(email)
{
	if(email.toLowerCase()=="name@email.com" || email.toLowerCase()=="user@domain.com")
	  return(false);   //Critter Task 9715 [Raja]
	var regu	= "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]+)$"
    var reg		= new RegExp(regu);
    return (email.search(reg) > -1);
}
function checkEmailExist(email)
{    
    var url= "/sp/Callback/EmailExistence.aspx?email=" + email;   
    emailId = email;
    xmlHttp=GetXmlHttpObject(DoNothing); 
    xmlHttp.open("GET", url , false); //GET method to send requests to the remote script
    xmlHttp.send(null) //To send the request and return immedietly
    return xmlHttp.responseText;

}

function generateVideoPlayer(url) {
    //detect video site
    if (url.search(/youtube/) >= 0)
        return '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/' + getURLValue(url, 'v') + '&hl=en&fs=1&rel=0&color1=0xcccccc&color2=0xcccccc"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + getURLValue(url, 'v') + '&hl=en&fs=1&rel=0&color1=0xcccccc&color2=0xcccccc" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
    else if (url.search(/youku/) >= 0)
        return '<embed src="http://player.youku.com/player.php/sid/' + getURLValue(url, 'v') + '/v.swf" quality="high" width="425" height="344" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>';
    else if (url.search(/tudou/) >= 0)
        return '<object width="420" height="363"><param name="movie" value="http://www.tudou.com/v/' + getURLValue(url, 'v') + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="opaque"></param><embed src="http://www.tudou.com/v/' + getURLValue(url, 'v') + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="420" height="363"></embed></object>';
    else
        return 'Video not found.';
}

function closePopup(){
	$j('#popup').html('');
	$j('#popup').hide();
	$j('#dim_bg').hide();
}
/*
function closePopup() {
    $j('#popupwindow').html('');
    $j('#popupwindow').hide();
    $j('#dim_bg').hide();
}
*/
function getURLValue(url, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null)
        return "";
    else
        return results[1];
}

function ApplyHighlightedMenuStyle(menuItemId) {
		var item = document.getElementById(menuItemId);
		if (item != null) {
				item.className += " on";
				item.className += " active";
		}
}
