﻿// JScript File
////////////////////////////////////////////////////////////////////////
function AddOrUpdateHC ( sKey , sVal )
{
    try
    {
        if ( ExistsInHC( String (sKey)))
        {
            SetValueOfHC(String(sKey),String(sVal));
        }
        else
        {
            AddToHC( String(sKey), String(sVal));
        }
    }
    catch(ex)    
    {
        throw new cACTLException(ex.messag,'AddOrUpdateHC(sKey, sVal)');
    }    
}

function OnClickSideCategory(nCategoryID, cCategoryName)
{
    try
    {
        AddOrUpdateHC('nCategoryID',nCategoryID) 
        AddOrUpdateHC('nCategoryID',cCategoryName) 
        //oJSFW.
    }
    catch(ex)    
    {
        throw new cACTLException(ex.messag,'AddOrUpdateHC(sKey, sVal)');
    }   
    oJSFW.fnCancelEvent(event);
    return false;
}

function fnOpenWindow(sAction)
{
    oAry = fnGetPosition ( 550, 550 );
    var strOtherSettings = "status=no,scrollbars=yes,resizable=no,Left=" + String(oAry[0]) +"px,Top=" + String(oAry[1]) +"px,Width=550px,Height=550px";
    switch(sAction)
    {
        case "RETURNPOLICY":
            window.open('inc/ReturnPolicy.htm','',strOtherSettings);
            break;
        case "SIZINGCHART":
            window.open('inc/SizingChart.htm','',strOtherSettings);
            break;
        case "SECURITY":
            window.open('inc/Security.htm','',strOtherSettings);
            break;            
    }
    return null;
}

//Added by Ashish Chauhan on 16Oct2006
function fnClickSubmit(oEvent)
{
    var sControlIDString = String(GetValueOfHC("IDS"));
    //alert(sControlIDString);
    var oControlList = sControlIDString.split(",");
    var sFinalValue = "";
    var bForFlag = false;
    for ( var iCnt = 0 ; iCnt < oControlList.length ; iCnt++ )
    {
        var sSingleControlName = String(oControlList[iCnt]);
        var oSingleControlAry = sSingleControlName.split("_");
        var sType = String(oSingleControlAry[0]);
        var sID = String(oSingleControlAry[1]);
        var sMandatory = String(oSingleControlAry[2]);
        var oObj = oJSFW.fnGetElementById(sSingleControlName);
        bForFlag = false;
        switch ( sType )
        {
            case "STB": //Small Text Box
            case "LTB": //Last Text Box
                if ( sMandatory == "Y" && String(oObj.value).fnTrim() == "")
                {
                    oJSFW.fnAlert("Please enter " + String(oObj.title) + ".");
                    oObj.value = "";
                    oObj.focus();
                    //window.event.returnValue = false;
                    bForFlag = true;
                    break;
                }
                sFinalValue += String(oControlList[iCnt]) + "=" + String(oObj.value) + "|";
                break;
            case "DDL": //Drop down list box
                if ( String(oObj.value).fnTrim() == "" )
                {
                    oJSFW.fnAlert("Please select " + String(oObj.title) + ".");
                    oObj.focus();
                    //window.event.returnValue = false;
                    bForFlag = true;
                    break;
                }
                sFinalValue += String(oControlList[iCnt]) + "=" + String(oObj.value) + "|";
                break;
            case "CB":  //Checkbox
                var oChkCol = oJSFW.fnGetElementsByName(oControlList[iCnt]);
                var bFlag = false;
                if ( sMandatory == "Y")
                {
                    for ( var i = 0 ; i < oChkCol.length ; i++ )
                    {
                        if ( oChkCol[i].checked == true )
                        {
                            bFlag = true ;
                            break;
                        }                        
                    }
                    if ( bFlag == false )
                    {
                        oJSFW.fnAlert("Please select " + String(oChkCol[0].title) + ".");
                        //window.event.returnValue = false;
                        bForFlag = true;
                        break;
                    }
                }
                var sCBVal = "";
                for ( var i = 0 ; i < oChkCol.length ; i++ )
                {
                    if ( oChkCol[i].checked == true )
                    {
                        sCBVal += oChkCol[i].value + ",";
                    }                        
                }
                if ( sCBVal.length > 0 )
                {
                    sCBVal = sCBVal.substr(0,sCBVal.lastIndexOf(","));
                }                
                sFinalValue += String(oControlList[iCnt]) + "=" + String(sCBVal) + "|";
                break;
            case "RB": //Radio Button
                var oRBCol = oJSFW.fnGetElementsByName(oControlList[iCnt]);
                var bFlag = false;
                if ( sMandatory == "Y")
                {
                    for ( var i = 0 ; i < oRBCol.length ; i++ )
                    {
                        if ( oRBCol[i].checked == true )
                        {
                            bFlag = true ;
                            break;
                        }                        
                    }
                    if ( bFlag == false )
                    {
                        oJSFW.fnAlert("Please select " + String(oRBCol[0].title) + ".");
                        //window.event.returnValue = false;
                        bForFlag = true;
                        break;
                    }
                }
                var sRBVal = "";
                for ( var i = 0 ; i < oRBCol.length ; i++ )
                {
                    if ( oRBCol[i].checked == true )
                    {
                        sRBVal += oRBCol[i].value + ",";
                    }                        
                }
                if ( sRBVal.length > 0 )
                {
                    sRBVal = sRBVal.substr(0,sRBVal.lastIndexOf(","));
                }
                sFinalValue += String(oControlList[iCnt]) + "=" + String(sRBVal) + "|";
                break;
            case "MS":  //Multi select
                if ( sMandatory == "Y" )
                {
                    if ( String(oObj.value).fnTrim() == "" )
                    {
                        oJSFW.fnAlert("Please select " + String(oObj.title) + ".");
                        //window.event.returnValue = false;
                        bForFlag = true;
                        break;
                    }
                }
                var sMSVal = "";
                for ( var i = 0 ; i < oObj.options.length; i++ )
                {
                    if ( oObj.options[i].selected == true )
                    {
                        sMSVal += oObj.options[i].value + ",";
                    }
                }
                if ( sMSVal.length > 0 )
                {
                    sMSVal = sMSVal.substr(0,sMSVal.lastIndexOf(","));
                }
                sFinalValue += String(oControlList[iCnt]) + "=" + String(sMSVal) + "|";
                break;
            case "E":   //Email
				
                if ( sMandatory == "Y" && String(oObj.value).fnTrim() == "" )
                {
                    oJSFW.fnAlert("Please enter " + String(oObj.title) + ".");
                    oObj.focus();
                    //window.event.returnValue = false;
                    bForFlag = true;
                    break;
                }
                if (String(oObj.value).fnTrim() != "" &&  String(oObj.value).fnIsEmail() == false )
                {
                    alert("Please enter valid " + String(oObj.title) + ".");
                    oObj.focus();
                    //window.event.returnValue = false;
                    bForFlag = true;
                    break;
                }
                sFinalValue += String(oControlList[iCnt]) + "=" + String(oObj.value) + "|";
                break;
        }
        if ( bForFlag )
        {
            break;
        }
    }
    
    if ( bForFlag )
    {
        oEvent.returnValue=false;
        return false;
    } 
       
    if ( sFinalValue.length > 0 )
    {
        sFinalValue = sFinalValue.substr(0,sFinalValue.lastIndexOf("|"));
    }
    
    SetValueOfHC("FinalValue",sFinalValue);
    return true;
}

function fnSearchSubmit()
{
    var oSearchString = oJSFW.fnGetElementById("txtSearchString");
    if ( fnCheckBlank ( oSearchString, "search term") == true )
        return false;

    oJSFW.fnGetElementById("formsearch").action = "shop.aspx";
    oJSFW.fnGetElementById("formsearch").submit();
    return false; 
    
}

var checkOutProcessing = false;

function fnCheckoutProcessing(blnProcessing){
    checkOutProcessing = blnProcessing;
    
    if (checkOutProcessing){
        oJSFW.fnGetElementById("btnBuyNow").src = "img/bn_processing.gif";
    } else {
        oJSFW.fnGetElementById("btnBuyNow").src = "img/bn_buy_a.gif";
    }
}

function fnCheckoutSubmit() //function will be called from checkout page.
{    
    if (!checkOutProcessing){
        fnCheckoutProcessing(true);
    } else {
        return false;
    }
        
    var sFirstName, sLastName , sEmail, sPhoneNumber, sAddress, sCity, sState, sZip , sCountry;
    var sIsShipping ;
    var sShipFirstName, sShipLastName, sShipEmail, sShipPhoneNumber, sShipAddress, sShipCity, sShipState, sShipZip, sShipCountry;
    var sPaymentType;
    var sCardType, sCardNo, sCardVerNo, sCardname, sCardExpireMonth, sCardExpireYear

    var oFirstName = oJSFW.fnGetElementById("txtFirstName");
    var oLastName = oJSFW.fnGetElementById("txtLastName");
    var oEmail = oJSFW.fnGetElementById("txtEmail");
    var oPhone = oJSFW.fnGetElementById("txtPhone");
    var oAddress = oJSFW.fnGetElementById("txtAddress") ;
    var oCity = oJSFW.fnGetElementById("txtCity") ;
    var oState = oJSFW.fnGetElementById("txtState") ;
    var oZip = oJSFW.fnGetElementById("txtPostcode") ;
    var oCountry = oJSFW.fnGetElementById("selCountry");

    
    var oShipFirstName = oJSFW.fnGetElementById("txtShipFirstName");
    var oShipLastName = oJSFW.fnGetElementById("txtShipLastName");
    var oShipEmail = oJSFW.fnGetElementById("txtShipEmail");
    var oShipPhone = oJSFW.fnGetElementById("txtShipPhone");
    var oShipAddress = oJSFW.fnGetElementById("txtShipAddress") ;
    var oShipCity = oJSFW.fnGetElementById("txtShipCity") ;
    var oShipState = oJSFW.fnGetElementById("txtShipState") ;
    var oShipZip = oJSFW.fnGetElementById("txtShipPostcode") ;
    var oShipCountry = oJSFW.fnGetElementById("selShipCountry");
    
    if ( fnCheckBlank ( oFirstName, "first name") == true ){
        fnCheckoutProcessing(false);
        return false;
    }
    if ( fnCheckBlank ( oLastName, "last name") == true ){
        fnCheckoutProcessing(false);
        return false;
    }
    if ( fnCheckBlank ( oEmail, "email") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    else
    {
        if ( String(oEmail.value).fnIsEmail() == false )
        {
            oJSFW.fnAlert("Please enter valid email.");
            fnCheckoutProcessing(false);
            return false; 
        }
    }
    if ( fnCheckBlank ( oPhone, "Phone number") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    if ( fnCheckBlank ( oAddress, "address") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    if ( fnCheckBlank ( oCity, "city") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    if ( fnCheckBlank ( oState, "state") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    if ( fnCheckBlank ( oZip, "Postal Code/Zipcode") == true ){
        fnCheckoutProcessing(false);
        return false; 
    }
    
    oShipCheckbox = oJSFW.fnGetElementById("cbxShipping"); 
    var sOverseas = String(GetValueOfHC("Overseas"));
      
    sFirstName = String(oFirstName.value).fnTrim();
    sLastName = String(oLastName.value).fnTrim();
    sEmail = String(oEmail.value).fnTrim();
    sPhoneNumber = String(oPhone.value).fnTrim();
    sAddress = String(oAddress.value).fnTrim();
    sCity = String(oCity.value).fnTrim();
    sState = String(oState.value).fnTrim();
    sZip = String(oZip.value).fnTrim();
    sCountry = String(oCountry.value).fnTrim();
    
//    if ( oShipCheckbox.checked == true)
    if ( oShipCheckbox.checked == true || sOverseas == "true")
    {
        if ( fnCheckBlank ( oShipFirstName, "shipping first name") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipLastName, "shipping last name") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipEmail, "shipping email") == true ){
            fnCheckoutProcessing(false);
            return false;  
        }
        else
        {
            if ( String(oEmail.value).fnIsEmail() == false )
            {
                oJSFW.fnAlert("Please enter valid email.");
                fnCheckoutProcessing(false);
                return false; 
            }
        }
            
        if ( fnCheckBlank ( oShipPhone, "shipping Phone number") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipAddress, "shipping address") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipCity, "shipping city") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipState, "shipping state") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        if ( fnCheckBlank ( oShipZip, "shipping Postal Code/Zipcode") == true ){
            fnCheckoutProcessing(false);
            return false; 
        }
        
        sShipFirstName = String(oShipFirstName.value).fnTrim();
        sShipLastName = String(oShipLastName.value).fnTrim();
        sShipEmail = String(oShipEmail.value).fnTrim();
        sShipPhoneNumber = String(oShipPhone.value).fnTrim();
        sShipAddress = String(oShipAddress.value).fnTrim();
        sShipCity = String(oShipCity.value).fnTrim();
        sShipState = String(oShipState.value).fnTrim();
        sShipZip = String(oShipZip.value).fnTrim();
        sShipCountry = String(oShipCountry.value).fnTrim();

    }
    else  //if checkbox not selected
    {
        sShipFirstName = sFirstName ;
        sShipLastName = sLastName ;
        sShipEmail = sEmail ;
        sShipPhoneNumber = sPhoneNumber ;
        sShipAddress = sAddress ;
        sShipCity = sCity ;
        sShipState = sState ;
        sShipZip = sZip ;
        sShipCountry = sCountry ;
    }
    
    SetValueOfHC("FirstLastName", sFirstName + " " + sLastName);
    SetValueOfHC("Email", sEmail);
    SetValueOfHC("PhoneNumber",sPhoneNumber );
    SetValueOfHC("Address",sAddress );
    SetValueOfHC("City", sCity);
    SetValueOfHC("State", sState);
    SetValueOfHC("Zip", sZip);
    SetValueOfHC("Country", sCountry);

    if ( sIsShipping == true )
        SetValueOfHC("IsShipping", "true" );
    else
        SetValueOfHC("IsShipping", "false" );

    SetValueOfHC("ShipFirstLastName", sShipFirstName + " " + sShipLastName);
    SetValueOfHC("ShipEmail", sShipEmail);
    SetValueOfHC("ShipPhoneNumber", sShipPhoneNumber);
    SetValueOfHC("ShipAddress", sShipAddress);
    SetValueOfHC("ShipCity", sShipCity);
    SetValueOfHC("ShipState", sShipState);
    SetValueOfHC("ShipZip", sShipZip);
    SetValueOfHC("ShipCountry", sShipCountry);
        
    if(ExistsInHC('ShippingCountry'))
    {
        if(GetValueOfHC('ShippingCountry') != 'Australia')
        {
            var oPaymentType = oJSFW.fnGetElementsByName("rdoPaymentType");
            if(oPaymentType[0].checked == true)
            {
                sPaymentType = oPaymentType[0].value;
            }
            else if(oPaymentType[1].checked == true)
            {
                sPaymentType = oPaymentType[1].value;
            }
            else
            {
                alert("Please select Payment Type.");
                fnCheckoutProcessing(false);
                return false; 
            }
        }
        else
        {
            sPaymentType = "1";
            
            var oCardType = oJSFW.fnGetElementById("txtCardType");
            var oCardNo = oJSFW.fnGetElementById("txtCardNo");
            var oCardVerNo = oJSFW.fnGetElementById("txtCardVerNo");
            var oCardName = oJSFW.fnGetElementById("txtCardName");
            var oCardExpireMonth = oJSFW.fnGetElementById("txtCardExpireMonth");
            var oCardExpireYear = oJSFW.fnGetElementById("txtCardExpireYear");
            
            if (eval(
				CheckField(5, oCardType, 'Please choose from the Credit Card Type list') &&
				CheckField(1, oCardNo, 'Please enter the Credit Card Number') &&
				CheckField(3, oCardNo, 'Please ensure the Credit Card Number is numeric') &&
				CheckField(1, oCardName, 'Please enter the Credit Card Holder\'s Name') &&
				CheckField(5, oCardExpireMonth, 'Please specify the Credit Card Expiry Month') &&
				CheckField(5, oCardExpireYear, 'Please specify the Credit Card Expiry Year') &&
				true)) {
				    SetValueOfHC("CardType", String(oCardType.value).fnTrim());
                    SetValueOfHC("CardNo", String(oCardNo.value).fnTrim());
                    SetValueOfHC("CardName", String(oCardName.value).fnTrim());
                    SetValueOfHC("CardMonth", String(oCardExpireMonth.value).fnTrim());
                    SetValueOfHC("CardYear", String(oCardExpireYear.value).fnTrim());
			} else {
                fnCheckoutProcessing(false);
                return false; 
		    }
        }
        
        SetValueOfHC('PaymentType', sPaymentType);
    }
    
    oJSFW.fnGetElementById("formcheckout").action = "CheckOut.aspx";
    oJSFW.fnGetElementById("formcheckout").submit();
    return false;
}

function fnCheckBlank ( oObj , sMsg )
{
    if ( String(oObj.value).fnTrim() == "")
    {
        alert("Please enter " + sMsg + ".");
        oObj.focus();
        return true;
    }
}


function fnClickOnChkBox ( oObj ) //When user clicks on shipping checkbox.
{
    var oTblShipping = oJSFW.fnGetElementById("tdShipping");
    
    if ( oObj.checked == true )
    {
        oTblShipping.style.display = "block" ;
        oJSFW.fnGetElementById("head4").style.display = "block";       
    }
    else
    {
        oTblShipping.style.display = "none" ;
        oJSFW.fnGetElementById("head4").style.display = "none";
    }
    
    fnCheckShipping();

}

function fnCheckShipping(){

	var oShippingChk = oJSFW.fnGetElementById("cbxShipping");
	var oBillCountry = oJSFW.fnGetElementById("selCountry");
    var oShipCountry = oJSFW.fnGetElementById("selShipCountry");
    
    var oAusShipping = oJSFW.fnGetElementById("AusShipping");
    var oIntShipping = oJSFW.fnGetElementById("IntShipping");
    var oAusTotal = oJSFW.fnGetElementById("AusTotal");
    var oIntTotal = oJSFW.fnGetElementById("IntTotal");
    
    if (oShippingChk.checked == true){
		if (String(oShipCountry.value).fnTrim() == "Australia"){
			oAusShipping.style.display = "inline";
			oAusTotal.style.display = "inline";
			oIntShipping.style.display = "none";
			oIntTotal.style.display = "none";
		} else {
			oAusShipping.style.display = "none";
			oAusTotal.style.display = "none";
			oIntShipping.style.display = "inline";
			oIntTotal.style.display = "inline";
		}
	} else {
		if (String(oBillCountry.value).fnTrim() == "Australia"){
			oAusShipping.style.display = "inline";
			oAusTotal.style.display = "inline";
			oIntShipping.style.display = "none";
			oIntTotal.style.display = "none";
		} else {
			oAusShipping.style.display = "none";
			oAusTotal.style.display = "none";
			oIntShipping.style.display = "inline";
			oIntTotal.style.display = "inline";
		}
	}
    return false;
}




///////////////////////////////////////////////////////////////////////////

//Added by Nirav Patel on 30Oct2006
function fnGetPosition ( iWidth, iHeight )
{
	var iAvailWidth, iAvailHeight ;
	
	var oAryLeftTop = new Array();
	iAvailWidth = screen.availWidth ;
	iAvailHeight = screen.availHeight; 
	oAryLeftTop[0] = (iAvailWidth / 2 ) - (iWidth / 2 );
	oAryLeftTop[1] = (iAvailHeight / 2 ) - (iHeight / 2 );
	return oAryLeftTop ;
}





////////////////////////////////Following block for Career Page
function OpenWindow(url)
{
	var options, wndNam, wndWidth, wndHeight;
	options = "";
	wndName = "New_Popup";
	wndWidth = 600;
	wndHeight = 310;
    
    xPos = ((screen.availHeight/2) - (wndHeight/2));
    yPos = ((screen.availWidth/2) - (wndWidth/2));
    
    window.open(url, wndName, options + ",width=" + wndWidth + ",height=" + wndHeight + ",left=" + yPos + ",top=" + xPos);
    
    // Don't follow the Anchor Link
    return false;
}

function checkForm(oForm) {

	if (oForm.Position.value.length == 0 || oForm.Date.value.length == 0 || oForm.Surname.value.length == 0 || oForm.GivenNames.value.length == 0 || oForm.Address.value.length == 0 || oForm.Postcode.value.length == 0 || oForm.Suburb.value.length == 0 || oForm.BussinessPhone.value.length == 0 || oForm.PrivatePhone.value.length == 0 || oForm.DOB.value.length == 0 || oForm.Email.value.length == 0) {
		alert('Please complete all fields under the \'personal details\' section');
		oForm.Position.focus();
		return false;
	} else if ((oForm.FormerEmployer1.value.length > 0 && (oForm.From1.value.length == 0 || oForm.To1.value.length == 0 || oForm.Duties1.value.length == 0 || oForm.Reasons1.value.length == 0)) || (oForm.FormerEmployer2.value.length > 0 && (oForm.From2.value.length == 0 || oForm.To2.value.length == 0 || oForm.Duties2.value.length == 0 || oForm.Reasons2.value.length == 0)) || (oForm.FormerEmployer3.value.length > 0 && (oForm.From3.value.length == 0 || oForm.To3.value.length == 0 || oForm.Duties3.value.length == 0 || oForm.Reasons3.value.length == 0)) || (oForm.FormerEmployer4.value.length > 0 && (oForm.From4.value.length == 0 || oForm.To4.value.length == 0 || oForm.Duties4.value.length == 0 || oForm.Reasons4.value.length == 0))) {
		alert('Please complete all fields for each of the employees you provided under the \'employment history\' section');
		oForm.From1.focus();
		return false;
	} else if (oForm.Comments.value.length == 0 && !oForm.CanWork_MorningsMon.checked && !oForm.CanWork_MorningsTue.checked && !oForm.CanWork_MorningsWed.checked && !oForm.CanWork_MorningsThur.checked && !oForm.CanWork_MorningsFri.checked && !oForm.CanWork_MorningsSat.checked && !oForm.CanWork_MorningsSun.checked && !oForm.CanWork_AnoonMon.checked && !oForm.CanWork_AnoonTue.checked && !oForm.CanWork_AnoonWed.checked && !oForm.CanWork_AnoonThur.checked && !oForm.CanWork_AnoonFri.checked && !oForm.CanWork_AnoonSat.checked && !oForm.CanWork_AnoonSun.checked && !oForm.CanWork_EveningMon.checked && !oForm.CanWork_EveningTue.checked && !oForm.CanWork_EveningWed.checked && !oForm.CanWork_EveningThur.checked && !oForm.CanWork_EveningFri.checked && !oForm.CanWork_EveningSat.checked && !oForm.CanWork_EveningSun.checked && !oForm.CanWork_AnytimeByMutual.checked && !oForm.CanWork_FullTime.checked) {
		alert('Please provide information under the \'suitability of working hours\' section');
		oForm.Comments.focus();
		return false;
	} else if (oForm.Specific_Qualities.value.length == 0) {
		alert('Please enter information for the \'List here the particular qualities you will bring to the company\' question');
		oForm.Specific_Qualities.focus();
		return false;
	} else if (!oForm.TermsAndConditions.checked) {
		alert('Please tick the box under the \'declaration of authenticity\' section');
		oForm.Specific_Qualities.focus();
		return false;
	} else {
		return true;
	}
}

function NavProd(){
    //Over-ridden in shop.js file
    return false;
}



