﻿var curMenu;
function showmenu(id)
{
	$get(id).style.visibility="visible";
	$get(id).style.display="";	
}

function hidemenu(id)
{
	$get(id).style.visibility="hidden";
	$get(id).style.display="none";
}

function trimString(str) 
{
    str = this != window ? this : str;
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

// To check valid Email // 
function isEmail(s)
{
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the.
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function IsValidNumericValue(strVal)
{
	nNoOfArguments = IsValidNumericValue.arguments.length;
	if(nNoOfArguments < 1)
		return false;
		
	var sValidChars = "0123456789";		
	strVal = new String(strVal);	//convert the value to a string object
	
	if(strVal.length <= 0 )
		return false;
	
	var bReturn = true;
	var i = new Number(0);
	
	if(0 == parseInt(strVal,10))
	    return true;
	
	if(0 == strVal.charAt(0))
	    return false;
	
	while ((bReturn) && (i < strVal.length))
	{
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0);
		i++;
	}
	return (bReturn)
}

/*****new function created to allow space in last name *************************/	
function IsValidAlpha2(val)
{
    //if (isBlank(val)){return false;}
    for(var i=0;i<val.length;i++){
	    if(!isAlpha2(val.charAt(i))){return false;}
	}
    return true;
}
function isAlpha2(num) {
    if (num.length>1){return false;}
    var string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
    if (string.indexOf(num)!=-1){return true;}
    return false;
}
/*************functions end here**************************/

function IsValidAlphaNumeric(val)
{
    //if (isBlank(val)){return false;}
    for(var i=0;i<val.length;i++){
	    if(!isAlphaDigit(val.charAt(i))){return false;}
	}
    return true;
}
function isAlphaDigit(num) {
    if (num.length>1){return false;}
    var string="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    if (string.indexOf(num)!=-1){return true;}
    return false;
}

// To use short for document.getElementByID
function $get(ctlID)
{
    if( window.mmIsOpera ) return(document.getElementById(ctlID));
	if (document.all) return(document.all[ctlID]);
	if (document.getElementById) return(document.getElementById(ctlID));
	return(false);
}

// to allow only numbers // 
function noAlpha(ctl)
{
    var obj = $get(ctl);
    reg = /[^0-9]/g;
    obj.value =  obj.value.replace(reg,"");
}

// to allow only numbers // 
function onlyNumbers(event) 
{     
    event = (window.event) ? window.event : event;
        
     if (navigator.appName == 'Microsoft Internet Explorer')
        var KeyPressed = event.keyCode;
     else
        var KeyPressed = event.which;
        
    if (KeyPressed > 31 && (KeyPressed < 48 || KeyPressed > 57))
        return false;     
    return true; 
}

function moveXbySlicePos(x, img)
{ 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par)
		{
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;	
	return x;
}

function moveYbySlicePos(y, img) 
{
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

function ShowHidePanels(imgID, pgID)
{
    if($get(imgID).src.indexOf('icon_minus')!=-1)
    {
        $get(imgID).src = "../authorpoint/images/icon_plus.gif";
        $get(pgID).style.display='none';
    }
    else
    {
        $get(imgID).src = "../authorpoint/images/icon_minus.gif";
        $get(pgID).style.display='block';
    }
}

/*//#A 052005 AP: To get the top position of the object*/
function TopPos(obj, pos)
{
    var topCoord = 0;
	while(obj)
	{
	   topCoord += obj.offsetTop;
	   obj = obj.offsetParent;
	}
	return topCoord + pos + 'px';
}

/*// #A 052005 AP: To get the left position of the object*/
function LeftPos(obj, pos)
{
    var leftCoord = 0;    
    while(obj)
	{
	   leftCoord += obj.offsetLeft;
	   obj = obj.offsetParent;	   
	}	
	return leftCoord + pos + 'px';
}

// Function to validate Apply for special education price
function ValidateApplySpecialPrice()
{
    var Validation = true;
    var returnValue = true;
   // $get("HexillionApplyEmailValidator1").innerHTML="";
    document.getElementById('divMsgs').style.display='none';
    
    Control = $get("txtApplyName");
    Control.value = trimString(Control.value);
    if (Control.value == "")
    {
        Validation = false;
        returnValue = false;
        Control.className = "txtbox_all_red";
        $get("lblApplyNameError").style.display="none";
        $get("lblApplyError").style.display="none";
    }
    else if (IsValidAlpha2(Control.value) == false)
    {
        $get("lblApplyNameError").innerHTML = "*Invalid Name.<br>";
        $get("lblApplyNameError").style.display="block";
        $get("lblApplyError").style.display="none";
        returnValue = false;
        Control.className = "txtbox_all_red";
    }
    else
    {
        Control.className = "txtbox_all";
        $get("lblApplyNameError").style.display="none";
        $get("lblApplyError").style.display="none";
    }
    
    Control = $get("txtApplyEmailID");
    Control.value = trimString(Control.value);
    if (Control.value == "")
    {
        Validation = false;
        returnValue = false;
        Control.className = "txtbox_all_red";
        $get("lblApplyEmailError").style.display="none";
        $get("lblApplyError").style.display="none";
    }
    else if (isEmail(Control.value) == false)
    {
        $get("lblApplyEmailError").innerHTML = "*Invalid email address.<br>";
        $get("lblApplyEmailError").style.display="block";
        $get("lblApplyError").style.display="none";
        returnValue = false;
        Control.className = "txtbox_all_red";
    }
    else if(isValidEmail(Control.value) == false)
    {
    $get("lblApplyEmailError").style.display="none";
        $get("lblApplyError").style.display="block";
        returnValue = false;
        Control.className = "txtbox_all_red";
    }
    else
    {
        Control.className = "txtbox_all";
        $get("lblApplyEmailError").style.display="none";
        $get("lblApplyError").style.display="none";
    }
    if (Validation == false)
    {
    
        document.getElementById("lblApplyValidation").style.visibility = "visible";
        document.getElementById("lblApplyValidation").style.display = "inline";
        document.getElementById('divMsgs').style.display='block';
    }
    else
    {
        document.getElementById("lblApplyValidation").style.visibility = "hidden";
        document.getElementById("lblApplyValidation").style.display = "none";        
    }   
    if(returnValue == false)
    {
        document.getElementById('divMsgs').style.display='block';
    }
    if(returnValue)
        document.getElementById('divApplyForPromoCode').style.display='none';
    return returnValue;
}

function isValidEmail(email)
{
    var domain = email.substring(email.lastIndexOf('.')+1).toLowerCase();
    if(domain.length !=2 && domain != 'edu')
     {
        return false;
     }
    return true;
}
function ShowHide(id)
{
    document.getElementById('divMsgs').style.display='none';
    document.getElementById('txtApplyName').value ="";
     document.getElementById('txtApplyName').className ='txtbox_all';  
     document.getElementById('txtApplyEmailID').className ='txtbox_all';
    document.getElementById('txtApplyEmailID').value ="";
    var e = document.getElementById(id); 
     if(e.style.display == 'none')
        e.style.display = 'block';
     else
        e.style.display = 'none';
    return false;
   
}

// if(navigator.appName.toLowerCase().indexOf('netscape')!=-1)
//        $get('dropdownmenu').style.left = LeftPos(document.getElementById('liSupport'),-0);
//    else
//        $get('dropdownmenu').style.left = LeftPos(document.getElementById('liSupport'),0);
//    $get('dropdownmenu').style.top = TopPos(document.getElementById('liSupport'),0);
//    
//    if(navigator.appName.toLowerCase().indexOf('netscape')!=-1)
//        $get('downloaddropdown').style.left = LeftPos(document.getElementById('lidownload'),-9);
//    else
//        $get('downloaddropdown').style.left = LeftPos(document.getElementById('lidownload'),0);
//    $get('downloaddropdown').style.top = TopPos(document.getElementById('lidownload'),36);
//    
//    

//  


/* ---------------------------------------------------------- */

var timerID = null;
var timerOn = false;
var timecount = 1000;
var what = null;
var newbrowser = true;
var check = false;


function hideAll()
{   
    hideLayer('layer1');    
    hideLayer('layer2');    
}


function startTime() 
{  
    if (timerOn == false) 
    {
        timerID=setTimeout( "hideAll()" , timecount);
        timerOn = true;
    }
}


function stopTime() 
{
    if (timerOn) 
    {
        clearTimeout(timerID);
        timerID = null;
        timerOn = false;
    }
}
onLoad();
function onLoad()
{
    init();
}

function init()
{
    if (document.layers) 
    {
        layerRef="document.layers";
        styleSwitch="";
        visibleVar="show";
		//screenSize = window.innerWidth;
		what ="ns4";
    }
    else if(document.all)
    {
        //  alert ("Running IE");
        layerRef="document.all";
        styleSwitch=".style";
        visibleVar="visible";
        //screenSize = document.body.clientWidth + 18;
        what ="ie";        
    }
    else if(document.getElementById)
    {
        //  alert ("Running Netscape 6");
        layerRef="document.getElementById";
        styleSwitch=".style";
        visibleVar="visible";
        what="moz";	  
    }
    else
    {
        //alert("Older than 4.0 browser.");
        what="none";
        newbrowser = false;
    }

	window.status='status bar text to go here';
	check = true;
}

// Toggles the layer visibility off 
function hideLayer(layerName) 
{
    if(check) 
    {   
        if (what =="none") 
        { 
            return; 
        } 
        else if (what == "dom1") 
        { 
            document.getElementById(layerName).style.visibility="hidden"; 
        } 
        else 
        { 
            eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility="hidden"');             
        }
    }
    else
    {
        return;
    }
} 

function MouseOverMenu(type)
{
    hideAll();
    showLayer('layer'+ type);
    stopTime();
    return true;
}

function MouseOutMenu(type)
{
    startTime();
    return true;
}

// Turns the layers on and off
function showLayer(layerName)
{
    if(check)
	{
	    if (what =="none")
		{
			return;
	    }
    	else if (what == "moz")
    	{
    	    document.getElementById(layerName).style.visibility="visible";
			document.getElementById(layerName).style.visibility="visible";
		}
		else
		{
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
        }
    }
	else {// alert ("Please wait for the page to finish loading.");
		return;
	}
}
