﻿function PopUp(url) {
	var strName, intWidth, intHeight, intXpos, intYpos, strScroll, strResize, winBars;

	strName = 'popup';
	intWidth = 500;
	intHeight = 500;
	intXpos = 20;
	intYpos = 40;
	strScroll = 'yes';
	strResize = 'yes';
	strWinbars = 'no';

	if (PopUp.arguments[0] == '') {
		PopUp.arguments[0] = '#';
	}

	//handled agruments if they are left blank
	if (PopUp.arguments.length > 1) {
		strName = PopUp.arguments[1];
	}

	if (PopUp.arguments.length > 2) {
		intWidth = PopUp.arguments[2];
	}

	if (PopUp.arguments.length > 3) {
		intHeight = PopUp.arguments[3];
	}

	if (PopUp.arguments.length > 4) {
		intXpos = PopUp.arguments[4];
	}

	if (PopUp.arguments.length > 5) {
		intYpos = PopUp.arguments[5];
	}

	if (PopUp.arguments.length > 6) {
		strScroll = PopUp.arguments[6];
	}

	if (PopUp.arguments.length > 7) {
		strResize = PopUp.arguments[7];
	}

	if (PopUp.arguments.length > 8) {
		strWinbars = PopUp.arguments[8];
	}

	if (strWinbars == 'no') {
		winBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no';
	} else {
		winBars = 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
	}

	var winOptions = 'scrollbars=' + strScroll + ',resizable=' + strResize;
	var winSize = 'height=' + intHeight + ',width=' + intWidth;
	var winPosition = 'left=' + intXpos + ',top=' + intYpos;
	var winFeatures = winBars + ',' + winOptions + ',' + winSize + ',' + winPosition;

	if (window.open(url, strName, winFeatures) == null) {
		alert('You seem to have popup blocking software enabled.\nIn order to use certain features of GTG Hydroponics, please configure your popup blocker to allow popups from gtghydroponics.com.');
	}
}

function RandomPicture() {
	var lower = 1
	var upper = 14

	var range = upper - lower + 1;
	var l = ("" + range).length;
	var number = (Math.floor(Math.random() * Math.pow(10, l)) % range) + parseInt(lower)

	var randomPic = "<img src =\"/images/random/" + number + ".jpg\">";

	return randomPic;
}

function SetUniqueRadioButton(nameregex, current) {
    var re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        var elm = document.forms[0].elements[i]

        if (elm.type == 'radio') {
            if (re.test(elm.id)) {
                elm.checked = false;
            }
        }
    }
    
    current.checked = true;
}

function ResizeImage(field, max) {
    var elem = document.getElementById(field.id);
    if (elem == undefined || elem == null) return false;
    if (max == undefined) max = 100;

    if (elem.width > elem.height) {
        if (elem.width > max) elem.width = max;
    } else {
        if (elem.height > max) elem.height = max;
    }
}

function GetPageHeight(adjustment) {
    var intHeight = 0;

    if (navigator.appName == 'Microsoft Internet Explorer') {
        intHeight = document.documentElement.clientHeight - (adjustment > 0 ? adjustment : 145);
    } else if ((navigator.appName == 'Opera') || (navigator.appName == 'Netscape')) {
        intHeight = Number(window.innerHeight) - (adjustment > 0 ? adjustment : 155);
    }

    return intHeight;
}

function MaximizeBodyTable(tableName, bottomAdjustment) {
    var theTable;
    var adjust = (bottomAdjustment ? bottomAdjustment : 0);

    if (navigator.appName == 'Netscape') {
        theTable = document.getElementById(tableName);
        theTable.style.height = GetPageHeight(adjust) + 'px';
    } else {
        theTable = document.getElementById(tableName);
        theTable.style.height = GetPageHeight(adjust);
    }
}

function AddOnLoadEvent(e) {
    var currentOnLoad = window.onload;

    window.onload = function() {
        if (currentOnLoad) {
            currentOnLoad();
        }

        if (e) {
            e();
        }
    }
}
