//Usage: openWindow( url , w , h , tb , stb , L , mb , sb , rs , x , y )
//
//url - The URL of the page to open. Example: "http://iispeek.com".
//w - The width of the window in pixels.
//h - The height of the window in pixels (doesn't include menubars).
//tb - Toolbar visible? 1 = yes, 0 = no.
//stb - Status bar visible? 1 = yes, 0 = no.
//L - Linkbar visible? 1 = yes, 0 = no.
//mb - Menubar visible? 1 = yes, 0 = no.
//sb - Scrollbars visible? 1 = yes, 0 = no.
//rs - Resizable window? 1 = yes, 0 = no.
//x - The horizontal position of the window from the left of the screen.
//y - The vertical position of the window from the top of the screen.
function openWindow(url,w,h,tb,stb,l,mb,sb,rs,x,y)
{
    //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
    var t = (document.layers ? ",screenX="+x+",screenY="+y : ",left="+x+",top="+y);

    tb = (tb ? "yes" : "no");
    stb= (stb ? "yes" : "no");
    l= (l ? "yes" : "no");
    mb= (mb ? "yes" : "no");
    sb= (sb ? "yes" : "no");
    rs= (rs ? "yes" : "no");

    var win = window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t);
    win.focus();
}

function displayImage(image, w, h)
{
    openWindow('imageViewer.php?image=' + image, w, h);
}

function checkRegistrationForm()
{
    var messages = "";

    var firstName = document.getElementById('fname').value;
    var lastName = document.getElementById('lname').value;
    var emailAddress = document.getElementById('email').value;
    var password = document.getElementById('password').value;
    var cpassword = document.getElementById('cpassword').value;
    var address = document.getElementById('address1').value;
    var city = document.getElementById('city').value;
    var state = document.getElementById('state').value;
    var security_code = document.getElementById('security_code').value;

    if (firstName == "")
    {
        messages += "First Name\r\n";
    }

    if (lastName == "")
    {
        messages += "Last Name\r\n";
    }

    if (emailAddress == "")
    {
        messages += "Email Address\r\n";
    }

    if (password == "")
    {
        messages += "Password\r\n";
    }

    if (address == "")
    {
        messages += "Address\r\n";
    }

    if (city == "")
    {
        messages += "City\r\n";
    }

    if (state == "")
    {
        messages += "State\r\n";
    }

    if (security_code == "")
    {
        messages += "Security Code\r\n";
    }

    if (messages != "")
    {
        alert("The following required fields were not entered:\r\n\r\n" + messages);

        return false;
    }
    else if (password != cpassword)
    {
        document.getElementById('password').value = "";
        document.getElementById('cpassword').value = "";
        alert("Password mismatch.  Please retype your password.");

        return false;
    }

    return true;
}

function checkInformationForm()
{
    var messages = "";

    var firstName = document.getElementById('fname').value;
    var lastName = document.getElementById('lname').value;
    var address = document.getElementById('address1').value;
    var city = document.getElementById('city').value;
    var state = document.getElementById('state').value;

    if (firstName == "")
    {
        messages += "First Name\r\n";
    }

    if (lastName == "")
    {
        messages += "Last Name\r\n";
    }

    if (address == "")
    {
        messages += "Address\r\n";
    }

    if (city == "")
    {
        messages += "City\r\n";
    }

    if (state == "")
    {
        messages += "State\r\n";
    }

    if (messages != "")
    {
        alert("The following required fields were not entered:\r\n\r\n" + messages);

        return false;
    }

    return true;
}

function checkPassword()
{
    var password = document.getElementById('password').value;
    var cpassword = document.getElementById('passwordcheck').value;

    if (password.length == 0)
    {
        alert("Invalid password entered.")

        return false;
    }

    if (password != cpassword)
    {
        alert("Password mismatch.  Please retype your password.")

        document.getElementById('password').value = "";
        document.getElementById('passwordcheck').value = "";
        document.getElementById('password').focus();

        return false;
    }

    return true;
}

function addToCart(type)
{
    document.getElementById('license').value = type;
    document.addtocart.submit();
}

function removeFromCart(id)
{
    document.getElementById('itemid').value = id;
    document.thecart.submit();
}

function checkSupportForm()
{
    var messages = "";

    var emailAddress = document.getElementById('emailAddress').value;
    var fullName = document.getElementById('fullName').value;
    var messageBody = document.getElementById('messageBody').value;
    var hasSecurityCode = document.getElementById('security_code') != null;
    var subject = document.getElementById('subject');
    var securityCode ;

    if (hasSecurityCode)
    {
        securityCode = document.getElementById('security_code').value;
    }

    if (subject.value == "0")
    {
        messages += "Subject\r\n";
    }

    if (emailAddress == "")
    {
        messages += "Email Address\r\n";
    }

    if (fullName == "")
    {
        messages += "Full Name\r\n";
    }

    if (messageBody == "")
    {
        messages += "Message Body\r\n";
    }

    if (hasSecurityCode && securityCode == "")
    {
        messages += "Security Code\r\n";
    }

    if (messages != "")
    {
        alert("The following required fields were not entered:\r\n\r\n" + messages);

        return false;
    }

    return true;
}

