﻿var AjaxUrl = "Ajax.aspx";

function printIt(pid)
{
    window.open("ProductPrint.aspx?pid="+pid,"print","toolbars=no,width=650,height=500");
}

function checkMail(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email))
	    return true;
	else
	    return false;
}

function gotoLang(langId)
{
    location.href = "default.aspx?l=" + langId;
}

//-------------------------------------------- ORDER TABLES: -----------------------------------------//

function buildTbl(tblId, tblName)
{
    var strTbl = "";
    var divItem = eval("divTables" + tblId);
    
    if (eval("document.aspnetForm.chkItem" + tblId).checked == true)
    {
        strTbl += "<b>For Motor Type:</b> " + tblName + "<br />";
        strTbl += "<input type='hidden' name='tbl" + tblId + "name' value='" + tblName + "' />";
        strTbl += "<table cellpadding='0' cellspacing='0' width='464'>";
        strTbl += "    <tr>";
        strTbl += "        <td style='width: 5px;'>";
        strTbl += "            <img src='images/tbl_motor_left.gif' alt='' /></td>";
        strTbl += "        <td style='width: 454px; background-image: url(images/tbl_motor_bg.gif);'>";
        strTbl += "            <table cellpadding='0' cellspacing='0' width='454' style='table-layout: fixed;'>";
        strTbl += "                <tr style='font-weight: bold;'>";
        strTbl += "                    <td style='width: 74px; height: 40px;' align='center'>";
        strTbl += "                        Voltage<br />";
        strTbl += "                        Range";
        strTbl += "                    </td>";
        strTbl += "                    <td rowspan='2' style='width: 1px; background-color: White;'>";
        strTbl += "                    </td>";
        strTbl += "                    <td style='width: 74px;' align='center'>";
        strTbl += "                        Current<br />";
        strTbl += "                        Range";
        strTbl += "                    </td>";
        strTbl += "                    <td rowspan='2' style='width: 1px; background-color: White;'>";
        strTbl += "                    </td>";
        strTbl += "                    <td style='width: 74px;' align='center'>";
        strTbl += "                        Torque<br />";
        strTbl += "                        Range";
        strTbl += "                    </td>";
        strTbl += "                    <td rowspan='2' style='width: 1px; background-color: White;'>";
        strTbl += "                    </td>";
        strTbl += "                    <td style='width: 74px;' align='center'>";
        strTbl += "                        Speed<br />";
        strTbl += "                        Range";
        strTbl += "                    </td>";
        strTbl += "                    <td rowspan='2' style='width: 1px; background-color: White;'>";
        strTbl += "                    </td>";
        strTbl += "                    <td style='width: 74px;' align='center'>";
        strTbl += "                        Frequency<br />";
        strTbl += "                        Range";
        strTbl += "                    </td>";
        strTbl += "                    <td rowspan='2' style='width: 1px; background-color: White;'>";
        strTbl += "                    </td>";
        strTbl += "                    <td style='width: 75px;' align='center'>";
        strTbl += "                        Shaft<br />";
        strTbl += "                        Diameter";
        strTbl += "                    </td>";
        strTbl += "                </tr>";
        strTbl += "                <tr>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Voltage Range min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Voltage Range max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Current Range min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Current Range max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Torque Range min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Torque Range max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Speed Range min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Speed Range max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Frequency Range min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Frequency Range max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                    <td style='height: 80px;' align='center'>";
        strTbl += "                        Min:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Shaft Diameter min' /><br />";
        strTbl += "                        Max:<br />";
        strTbl += "                        <input type='text' style='height:14px;width:50px;' name='tbl Shaft Diameter max' /><br />";
        strTbl += "                    </td>";
        strTbl += "                </tr>";
        strTbl += "            </table>";
        strTbl += "        </td>";
        strTbl += "        <td style='width: 5px;'>";
        strTbl += "            <img src='images/tbl_motor_right.gif' alt='' /></td>";
        strTbl += "    </tr>";
        strTbl += "</table>";
        strTbl += "<br />";
        
        divItem.innerHTML = divItem.innerHTML + strTbl;
    }
    else
    {
        divItem.innerHTML = "";
    }
}

function sendOrder()
{
    var str = "";
    var isChecked = false;
    var isMotor = false;
    var elem = document.getElementById("aspnetForm").elements;
    
    for(var i = 0; i < elem.length; i++)
    {
        if (elem[i].checked && isChecked == false)
        {
            str += "<b><u>Checked items:</u></b><br /><br />";
            isChecked = true;
        }
        
        if (elem[i].name.indexOf('chkItems') != -1)
        {
            if (elem[i].checked == true)
            {
                str += elem[i].value + "<br />";
            }
        }
    }
    str += "<br /><br />";
    
    for(var i = 0; i < elem.length; i++)
    {
        if (elem[i].name.indexOf('tbl') != -1 && isMotor == false)
        {
            str += "<b><u>Motor Types Tables:</u></b><br />";
            isMotor = true;
        }
        
        if (elem[i].name.indexOf('tbl') != -1 && elem[i].name.indexOf('name') != -1)
        {
            str += "<br /><b>Motor Type:</b> " + elem[i].value + "<br />";
        }
        else if (elem[i].name.indexOf('tbl') != -1)
        {
            str += "<b>" + elem[i].name.replace("tbl ","") + ":</b> " + elem[i].value + "<br />";
        }
    }
    
    document.getElementById("aspnetForm").hiddenResult.value = str;
    document.getElementById("aspnetForm").submit();
}

function clearOrder()
{
    location.href = location.href;
}

//-------------------------------------------- SUBMENU: -----------------------------------------//

function showSub(groupid)
{
    //alert(groupid);
    
    document.getElementById("group" + groupid).style.display = "block";
    //new Effect.SlideDown("group" + groupid);
}

function showItems(subid)
{
    //alert(subid);
    
    document.getElementById("sub" + subid).style.display = "block";
    //new Effect.SlideDown("sub" + subid);
}

//-------------------------------------------- USERS ADMIN: -----------------------------------------//

function openTbody(uid)
{
    document.getElementById("tBody" + uid).style.display = "block";
    //new Effect.SlideDown(item);
}

function closeTbody(uid)
{
    document.getElementById("tBody" + uid).style.display = "none";
    //new Effect.SlideDown(item);
}

//-------------------------------------------- SEND TO FRIEND: -----------------------------------------//

var AjaxShowFS = false;

function showFsend()
{
    if (AjaxShowFS == false)
    {
        new Effect.SlideDown("divFsend");
        
        AjaxShowFS = true;
    }
}

function hideFsend()
{
    new Effect.SlideUp("divFsend");
    
    AjaxShowFS = false;
}

function hideFsendOK()
{
    new Effect.SlideUp("divFsendOK");
    
    AjaxShowFS = false;
}

function sendFS()
{
    if ($("txtSName").value == "")
    {
        alert("Please enter your name");
        return;
    }
    if ($("txtFName").value == "")
    {
        alert("Please enter your friend's name");
        return;
    }
    if ($("txtFEmail").value == "")
    {
        alert("Please enter your friend's email");
        return;
    }
    else if (checkMail($("txtFEmail").value) == false)
    {
        alert("Incorrect email address");
        return;
    }
    
	var pars = "strID=" + $("txtID").value + "&strName=" + $("txtSName").value + "&strFriend=" + $("txtFName").value + "&strEmail=" + $("txtFEmail").value;
	$("divFsend").style.display = "none";
	$("divFsendOK").style.display = "block";
	
	//alert(pars);
	GetAjaxValue("Send.Fsend", pars, null);
	
	$("txtSName").value = "";
	$("txtFName").value = "";
	$("txtFEmail").value = "";
}

function sendFS_Result(originalRequest)
{
	alert(originalRequest.responseText);
}

//-------------------------------------------- ASK A QUESTION: -----------------------------------------//

var AjaxShowAsk = false;

function showAsk()
{
    if (AjaxShowAsk == false)
    {
        new Effect.SlideDown("divAsk");
        
        AjaxShowAsk = true;
    }
}

function hideAsk()
{
    new Effect.SlideUp("divAsk");
    
    AjaxShowAsk = false;
}

function hideAskOK()
{
    new Effect.SlideUp("divAskOK");
    
    AjaxShowAsk = false;
}

function sendAsk()
{    
    if ($("txtName").value == "")
    {
        alert("Please enter your name");
        return;
    }
    if ($("txtCompany").value == "")
    {
        alert("Please enter your company");
        return;
    }
    
    if ($("cmbCountry").selectedIndex == 0)
    {
        alert("Please select your country");
        return;
    }
    
    if ($("cmbCountry").selectedIndex == 1)
    {
        if ($("txtSuburb").value == "")
        {
            alert("Please enter your suburb");
            return;
        }
        if ($("cmbState").selectedIndex == 0)
        {
            alert("Please select your state");
            return;
        }
    }
    
    if ($("txtPhone").value == "")
    {
        alert("Please enter your phone");
        return;
    }
    
    if ($("txtEmail").value == "")
    {
        alert("Please enter your email");
        return;
    }
    else if (checkMail($("txtEmail").value) == false)
    {
        alert("Incorrect email address");
        return;
    }
    
    if ($("cmbRegarding").selectedIndex == 0)
    {
        alert("Please select your subject");
        return;
    }
    
	var pars = "strID=" + $("txtID").value;
	
	pars = pars + "&strName=" + $("txtName").value;
	pars = pars + "&strCompany=" + $("txtCompany").value;
	
	pars = pars + "&strCountry=" + $("cmbCountry").value;
	pars = pars + "&strAddress=" + $("txtAddress").value;
	pars = pars + "&strSuburb=" + $("txtSuburb").value;
	pars = pars + "&strState=" + $("cmbState").value;
	pars = pars + "&strPost=" + $("txtPost").value;
	
	pars = pars + "&strPhone=" + $("txtPhone").value;
	pars = pars + "&strMobile=" + $("txtMobile").value;
	pars = pars + "&strEmail=" + $("txtEmail").value;
	
	pars = pars + "&strRegarding=" + $("cmbRegarding").value;
	pars = pars + "&strProduct=" + $("txtProduct").value;
	pars = pars + "&strQuestion=" + $("txtQuestion").value;
	
	$("divAsk").style.display = "none";
	$("divAskOK").style.display = "block";
	
	//alert(pars);
	GetAjaxValue("Send.Ask", pars, null);
	
	$("txtName").value = "";
    $("txtCompany").value = "";
    
    $("cmbCountry").selectedIndex = 0;
    $("txtAddress").value = "disabled";
    $("txtSuburb").value = "disabled";
    $("cmbState").selectedIndex = 0;
    $("txtPost").value = "disabled";
    
    $("txtPhone").value = "";
    $("txtMobile").value = "";
    $("txtEmail").value = "";
    
    $("cmbRegarding").selectedIndex = 0;
    $("txtProduct").value = "";
    $("txtQuestion").value = "";
}

function sendAsk_Result(originalRequest)
{
	alert(originalRequest.responseText);
}
