// Gamerang internal scripts

/*
 | Browser object
 */
function g_Browser(){
 d=document;
 this.agt=navigator.userAgent.toLowerCase();
 this.major=parseInt(navigator.appVersion);
 this.dom=(d.getElementById);
 this.ns=(d.layers);
 this.ns4up=(this.ns && this.major>=4);
 this.ns6=(this.dom&&navigator.appName=="Netscape");
 this.op=(window.opera);
 if(d.all)this.ie=1;else this.ie=0;
 this.ie4=(d.all&&!this.dom);
 this.ie4up=(this.ie&&this.major>=4);
 this.ie5=(d.all&&this.dom);
 this.ie6=(d.nodeType);
 this.sf=(this.agt.indexOf("safari")!=-1);
 this.win=((this.agt.indexOf("win")!=-1)||(this.agt.indexOf("16bit")!=-1));
 this.winme=(this.agt.indexOf("win 9x 4.90")!=-1);
 this.xpsp2=(this.agt.indexOf("sv1")!=-1);
 this.mac=(this.agt.indexOf("mac")!=-1);
}
var oBw=new g_Browser();


//emailreg
		
var misformattedFields = "";

function validateEmail(theForm)
{	
	var returnValue = true;
	misformattedFields = emailaddrChk(document.email_form.email.value);
	returnValue = isEmpty(misformattedFields);
	if(!returnValue)
	{
		alert(misformattedFields);
	}
	if (returnValue) emailWinner();
	return returnValue;
}	

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0) || (s == ""))
}

function emailaddrChk(email) {
var ret="";
if (email == null || email == "")
	ret = "A full email address must be entered - for example joe@gamerang.com.";
else {
if (email.indexOf('"') != -1)
	ret = "Your email address cannot contain double quotes. ";
if (email.indexOf("'") != -1)
	ret += "Your email address cannot contain single quotes. ";
if (email.indexOf(",") != -1)
	ret += "Your email address cannot contain commas.";
if (ret=="")
	if (email.search(/^\S+\@\S+\.\S+$/) == -1)
		ret = "A full email address must be entered - for example Cindy@gamerang.com.";
}
return ret;
}

/*
 * SearchBox Functs
 *
*/	
function LeftSearch(form) {	
	var trimmedStr = form.term.value.replace(/\s*$/,'').replace(/^\s*/, '');
	form.term.value = trimmedStr;
	if (trimmedStr == "") {
		alert("Please enter a valid search phrase.");
		form.term.focus();
	} else {
		getSearchAction(trimmedStr);
	}		
}
function getSearchAction(searchTerm)
{
document.search.action= "/Products/SearchShowcase.aspx?term=" + searchTerm;	
document.search.submit();
}
function openWindow(ref,windowname,w,h,scrollable){
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings =
		'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollable+',resizable=yes'
		win = window.open(ref,windowname,settings)
}
function showModalChoiceDialog(myURL, name, show)
{	
	if (show) {
		NewDialog(myURL, name, 370, 300);
	} else {
		window.location.href = "/account/";
	}
}

function showModalHolidayDialog(myURL, name, show)
{	
	if (show) {
		NewDialog(myURL, name, 445, 320);
	} else {
		window.location.href = "/account/";
	}
}
function writetoplink() {
	document.write("[ <a class=link2 href='#top'>top</a> ]\r");
}
function NewDialog(mypage, myname, w, h) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,status=no';
	win = window.open(mypage, 'GamerangDialog', winprops);
	if (win.opener == null)
		win.opener = window;
	win.focus();
}
function NewScrollWin(mypage, myname, w, h) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,status=no';
	win = window.open(mypage, 'GamerangDialog', winprops);
	if (win.opener == null)
		win.opener = window;
	win.focus();
}
function showHide(panelID)
{
    var panel = document.getElementById(panelID);
    if (panel != null)
    {
        if (panel.style.visibility == "hidden")
        {
        panel.style.display = "block";
        panel.style.visibility = "visible";
        } else {
        panel.style.display = "none";
        panel.style.visibility = "hidden";               
        }
    }
}
