/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|
|               Copyright (c) 2007 Prosodie
|               Author BILLIOT Clement
|               SeoData javascript librairies
|
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/**
 * @author cbilliot
 * @version 0.1
 * @fileoverview Javascript librairies useful to get datas from the ecommerce website (products, orders, pages, cart information, etc...)
 * @
 * */


/**
 * Page info constructor
 * @class Page info constructor
 * @param {String} pageName The current page name
 * @constructor
 */
function SeoDataJs(pageName) {
        this.pageName=pageName;
}

/**
 * Order info constructor
 * @class Order info constructor
 * @param String orderId The current page name
 * @param String orderTotal The total order
 * @constructor
 */
function SeoDataOrderJs(orderId, orderTotal, orderShipping, orderTaxTotal) {
        this.orderId=orderId;
        this.orderTotal=orderTotal;
        this.orderShipping=orderShipping;
        this.orderTaxTotal=orderTaxTotal;
        this.getOrderSubTotal=function() {
                var orderSubTotal = 0.0;
                if (this.orderTotal != "undefined") {
                        orderSubTotal = parseFloat(this.orderTotal);
                        if (this.orderShipping != "undefined") {
                                orderSubTotal = orderSubTotal - parseFloat(this.orderShipping);
                        }
                        if (this.orderTaxTotal != "undefined") {
                                orderSubTotal = orderSubTotal - parseFloat(this.orderTaxTotal);
                        }
                }

                //alert("SeoDataOrderJs.getOrderSubTotal() : orderSubTotal = " + orderSubTotal);
                return orderSubTotal;
        }
}

/**
 * Product info constructor
 * @param String productId The productId
 * @param String productName The product name
 * @param String productPrice The product price
 * @param String productURL The product URL
 * @constructor
 */
function SeoDataProductJs(productId, productName, productPrice, productURL ) {
        this.productId=productId;
        this.productName=productName;
        this.productPrice=productPrice;
        this.productURL=productURL;
}

/**
 * Category info constructor
 * @class Category info constructor
 * @param String categoryId The categoryId
 * @param String categoryName The category name
 * @param String categoryURL The category URL
 * @constructor
 */
function SeoDataCategoryJs(categoryId, categoryName, categoryURL ) {
        this.categoryId=categoryId;
        this.categoryName=categoryName;
        this.categoryURL=categoryURL;
}

/**
 * Cart Item info constructor
 * @class Cart Item info constructor
 * @param String productId The cart item productId
 * @param String name The product name
 * @param String description The product description
 * @param String parentCategory The parent category
 * @param String price The product price
 * @param String quantity The cart item quantity
 * @constructor
 */
function SeoDataCartItemJs(productId, name, description, parentCategory, price, quantity ) {
        this.productId=productId;
        this.name=name;
        this.description=description;
        this.parentCategory=parentCategory;
        this.price=price;
        this.quantity=quantity;
}

/**
 * User info constructor
 * @class User info constructor
 * @param String title The user's title
 * @param String lastName The user's lastName
 * @param String firstName The user's firstName
 * @param String streetNumber The user's street number
 * @param String address The user's address
 * @param String postalCode The user's postal code
 * @param String city The user's city
 * @param String phoneNumber The user's phone number
 * @param String email The user's email
 * @constructor
 */
function SeoDataUserJs(title, lastName, firstName, streetNumber, address, postalCode, city, country, phoneNumber, email, state ) {
        this.title=title;
        this.lastName=lastName;
        this.firstName=firstName;
        this.streetNumber=streetNumber;
        this.address=address;
        this.postalCode=postalCode;
        this.city=city;
        this.country=country;
        this.phoneNumber=phoneNumber;
        this.email=email;
        this.state=state;
        this.toString = function toStringUser(){
                document.write(this.title+" "+this.lastName+" "+this.firstName);
        }
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  \
|               Google Analytics Use Case
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

/**
 * formatItemsGA
 * CartItem formatting for Google analytics
 * @class CartItems formatting for Google analytics
 * @param Array of seoDataCarItem
 * @param SeoDataOrderJs seoDataOrderJs
 * @type String
 * @see #SeoDataCarItem
 * @see #SeoDataOrderJs
 */
 function formatItemsGA(seoDataCarItems, seoDataOrderJs) {
        for(var i in seoDataCarItems){
                var seoDataCartItem = seoDataCarItems[i];
                document.write("UTM:I|"+seoDataOrderJs.orderId+"|"+seoDataCartItem.productId+"|"+seoDataCartItem.name+"|"+seoDataCartItem.parentCategory+"|"+seoDataCartItem.price+"|"+seoDataCartItem.quantity);
        }
 }

/**
 * formatOrderGA
 * @class Order datas formatting for Google analytics
 * @param SeoDataOrderJs seoDataOrderJs
 * @param SeoDataUserJs seoDataUserJs
 * @type String
 * @see #SeoDataOrderJs
 * @see #SeoDataUserJs
 */
 function formatOrderGA(seoDataOrderJs, seoDataUserJs) {
        document.write("UTM:I|"+seoDataOrderJs.orderId+"||"+seoDataOrderJs.orderTotal+"|"+seoDataOrderJs.orderTaxTotal+"|"+seoDataOrderJs.orderShipping+"|"+seoDataUserJs.city+"|"+seoDataUserJs.postalCode+"|"+seoDataUserJs.country);
 }

 /**
 * @class Render the whole javascript formatting code on the confirm page for Google analytics
 * @param SeoDataOrderJs seoDataOrderJs
 * @param SeoDataUserJs seoDataUserJs
 * @param Array seoDataCarItems
 * @type String
 * @see #SeoDataOrderJs
 * @see #SeoDataUserJs
 * @see #SeoDataCarItem
 */
 function renderOrderGA(seoDataOrderJs, seoDataUserJs, seoDataCarItems ) {
        alert("renderOrderGA");
        document.write("<form style='display:none;' name='utmform'><textarea id='utmtrans'>");
        formatOrderGA(seoDataOrderJs, seoDataUserJs);
        formatItemsGA(seoDataCarItems, seoDataOrderJs);
        document.write("</textarea></form>");
 }


