﻿function showCal(b, page)
{
	var calendar , calWidth , calHeight;
	calWidth = 220;
	calHeight = 200;
	calendar = window.open(page + '?fn=' + document.getElementById(b).value + '&fr=' + b, 'cal', 'width=' + calWidth + ',height=' + calHeight);
	var X = window.screen.availWidth;
	var Y = window.screen.availHeight;
	var X = (X - calWidth) / 2;
	var Y = (Y - calHeight) / 2;
	calendar.moveTo(X,Y);
}

function click(id)
{
	var obj = $get(id);
	if(document.all)
		obj.click();
	else
	{
		var evt = obj.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, obj.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		obj.dispatchEvent(evt);
	}
}

function clickIfEnter(ev, id)
{
    var keyCode = ev ? ev.keyCode : event.keyCode;
    if(keyCode == 13)
        click(id);
}

function clearText(id)
{    
    if (document.getElementById(id).value == "First Name" || document.getElementById(id).value == "Last Name" || document.getElementById(id).value == "School Name")
        {
            document.getElementById(id).value = "";
            document.getElementById(id).style.color = "black";
        }
    
}
           
function resetText(id, text)
{
    if (document.getElementById(id).value == "")
        {
            document.getElementById(id).style.color = "silver";
            document.getElementById(id).value = text;            
        }
}   

function showLogin()
{
	if(myLightWindow)
		myLightWindow.activateWindow({href: '/Login.aspx', width: 400, height: 350, title: ''});
	else
		setTimeout('showLogin()', 500);
}

function showLightWindow(url, w, h)
{
	if(myLightWindow)
		myLightWindow.activateWindow({href: url, width: w, height: h, title: ''});
	else
		setTimeout("showLightWindow('" + url + "', " + w + ", " + h + ")", 500);
}

function qs(ji, par)
{
	var hu = '';
	if(parent)
		hu = parent.parent.location.search.substring(1);
	else
		hu = window.location.search.substring(1);
	
	var gy = hu.split("&");
	for (i = 0; i < gy.length; i++) 
	{
		var ft = gy[i].split("=");
		if (ft[0].toLowerCase() == ji.toLowerCase())
		{
			return ft[1];
		}
	}
	
	return null;
}

function redirectLogin(username, url)
{
    var redirectUrl = qs("RedirectUrl", true);

    var wnd = parent.parent.parent ? parent.parent.parent : parent.parent;

    if (redirectUrl)
        wnd.location.href = redirectUrl;
    else
        if (url)
        wnd.location.href = url;
    else
        wnd.location.href = '/' + username + '/dashboard';
}

var _availableNickNameID;
var _notAvailableNickNameID;
function checkNickNameAvailability(username, id1, id2)
{
	if(username != '')
	{
		_notAvailableNickNameID = id1;
		_availableNickNameID = id2;
		
		PageMethods.NickNameExists(username, onCheckNickNameAvailabilityComplete);
	}
	else
	{
		$get(id1).style.display = 'none';
		$get(id2).style.display = 'none';
	}
}

function onCheckNickNameAvailabilityComplete(response)
{
	if(response.toString().toLowerCase() == "true")
	{
		$get(_availableNickNameID).style.display = 'none';
		$get(_notAvailableNickNameID).style.display = 'inline';
	}
	else
	{
		$get(_notAvailableNickNameID).style.display = 'none';
		$get(_availableNickNameID).style.display = 'inline';
	}
}

function resizeIframe(id)
{
	var ifr = $get(id);
	if(ifr)
	{
		ifr.style.width = (ifr.offsetWidth + 100) + 'px';
		ifr.style.height = (ifr.offsetHeight + 100) + 'px';
	}
	else
		setTimeout("resizeIframe('" + id + "')", 200);
}

function setSchoolName(name)
{
	var school = $get(_addSchoolClientID);
	if(school)
		school.value = name;
}

function setSchoolLevel(name)
{
	var level = $get(_schLevelClientID);
	if(level)
		level.value = name;
}

function setCompanyName(name)
{
	var comp = $get(_addCompanyClientID);
	if(comp)
		comp.value = name;
}

function closeLightWindow()
{
	myLightWindow.deactivate();
}

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

var _globalValue = '';