    function Product (sformId){
        this._formId = sformId;
        this._primItem = "";
        this._flagPrim = false;
        this._secItems = "";
        this._secItemProd = "";
        this._message = "";
        this._roductDetail = null;
    }
Product.prototype={
    _isAllAttributeSelected : function(){
        var list = document.forms[this._formId].elements;
        var validateItem = true;
        for( var i=0; i<list.length; i++)
        {
            if(list[i].id.indexOf('attributesValue') !=-1)
            {
                if(list[i].value==''){
                    validateItem = false;
                    break;
                }else{
                    var tmp = list[i].id.split('$');
                    var tmpId = tmp[1];
                    $('attr_'+tmpId).value = list[i].options[list[i].selectedIndex].text;
                }
            }
        }
        return validateItem;
    },

    _isCityAttributeSelected : function(){
        var list = document.forms[this._formId].elements;
        var validateItem = true;
        for( var i=0; i<list.length; i++)
        {
            if(list[i].id.indexOf('pcaShippingCity') !=-1)
            {
                if(list[i].value==''){
                    validateItem = false;
                    break;
                }else{
                    $('pcaHiddenShippingCity').value = list[i].options[list[i].selectedIndex].value;
                }
            }
        }
        return validateItem;
    },

        _isValidDate : function(){
            var selectedDateObj = $('pcaShippingDate');
            var currentDate = new Date();
            var selectedDate = selectedDateObj.value.split('/');
            var currentDateDay = "";
            var currentDateMonth = "";
            var currentDateMonthPlus = parseInt(currentDate.getMonth())+1+'';
            var currentDateYear = currentDate.getYear();
             var currentDateDayLength = currentDate.getDate()+'';
            if(parseInt(currentDateDayLength)==parseInt(1))
                currentDateDay = '0'+currentDate.getDate();
            else
                currentDateDay = currentDate.getDate();

            var currentDateMonthLength = currentDateMonthPlus.length;
            if(parseInt(currentDateMonthLength)==parseInt(1))
                currentDateMonth = '0'+parseInt(currentDate.getMonth()+1);
            else
                currentDateMonth = parseInt(currentDate.getMonth())+1;
            //alert("Current Date : "+currentDateDay+"  "+currentDateMonth+"  "+currentDateYear)
            //alert("Selected Date : "+selectedDate[0]+"  "+ selectedDate[1]+"   "+selectedDate[2]);
            var currentDateFinal = new Date(parseInt(currentDate.getYear()),parseInt(currentDateMonth-1),parseInt(currentDateDay))

            var selectedDateFinal = new Date(selectedDate[2],(selectedDate[1]-1),selectedDate[0]);
            if(selectedDateObj != null && selectedDateObj.value==''){
                alert('Please enter valid date');
                return false;
            }else{
                if(selectedDateFinal<currentDateFinal){

                alert('Please Select Date greater than current Date');
                return false;
                }
            }
            return true;
        },

    _checkMaxFreeProducts : function (statusIndex){
        if($('maxFreeProducts')!= null){
        var maxFree = $('maxFreeProducts').value;
        if(maxFree != 0)
        {
            var elels = document.forms['addToCartFrom'].elements;
            var selectedItems = 0;
            for(i=0;i<elels.length;i++){
                var elem = elels[i];
                if(elem.type == 'checkbox' && elem.id.indexOf('free') != -1 && elem.checked){
                    selectedItems++;
                }
            }

            if(selectedItems == 0)
            {
                  alert('Please choose '+ maxFree + ' free products from the list given below');
                  this._clearOthers();
                  return false;
            }else if(selectedItems > maxFree){
                alert('Cannot add more free products than allowed');
                this._clearOthers();
                return false;
            }else {
                var obj = $('freeProductItems'+statusIndex);
                if(obj != null){
                    try{
                        this._setProductItemValues(obj,statusIndex);
                    }catch(err){alert(err.message);}
                }
                return true;
            }
        }
        }
        return true;
    },

      // TODO another method has to be written for collecting messages in the format
      // MessageProvided1,ItemID1,AttributeID1:MessageProvided2,ItemID2,AttributeID2:

    _setProductItemValues :function(thisObj,setIndex){
        var index = thisObj.selectedIndex;

        $('freeItemId'+setIndex).value = $('freeItemId_'+index).title;
        $('freeItemMRPrc'+setIndex).value = $('freeItemMRPrc_'+index).title;
        $('freeItemOfferPrc'+setIndex).value = $('freeItemOfferPrc_'+index).title;
        $('freeItemDiscount'+setIndex).value = $('freeItemDiscount_'+index).title;
        $('freeItemImageURL'+setIndex).value = $('freeItemImageURL_'+index).title;
        $('freeItemTitle'+setIndex).value = $('freeItemTitle_'+index).title;
        $('freeItemAMTName'+setIndex).value = $('freeItemAMTName_'+index).title;
        $('freeItemAMTPOI'+setIndex).value = $('freeItemAMTPOI_'+index).title;

        $('multileMRP'+setIndex).update($('freeItemMRPrc_'+index).title);
        $('multileOffer'+setIndex).update($('freeItemOfferPrc_'+index).title);
        //$('multileDiscount').update($('freeItemDiscount_'+index).title);
        $('freePodImg'+setIndex).src = $('freeItemImageURL_'+index).title;
    },


    _clearOthers : function (){
        /*User can select the radio button after the selection of checkbox*/
        var formEles = document.forms[this._formId].elements;
        for(var i=0; i<  formEles.length;i++)
        {
            var element = formEles[i];
            if(element.type == "checkbox" && element.checked)
                element.checked = false;
        }
    },
    _isValidQty : function(){
        var qtyObj = $('itemqty');
        if(qtyObj !=null && qtyObj.value != ''){
            if(isNaN(qtyObj.value))
            {
                alert('Not a valid Number.');
                return false;
            }else if(parseInt(qtyObj.value) < 1 & parseInt(qtyObj.value) > 5){
                    alert('Please enter value below to 6.');
                return false;
            }
        }else{
            alert('Please enter valid quantity.');
            return false;
        }
        return true;
    },

    isCheckout : function(){
        var isValid = false;
        try{
                if($('pilrfnum') == null || $('pilrfnum').value == '' )
                {
                    alert("This Item can not be added."); return false;
                }

                isValid = this._isAllAttributeSelected()
                if(!isValid){
                    alert('Please select attribute for this product.');
                    return false;
                }

                isValid = this._isCityAttributeSelected()
                if(!isValid){
                    alert('Please select city for this product.');
                    return false;
                }

                isValid = this._isValidDate();
                if(!isValid)
                    return false;

                isValid = this._checkMaxFreeProducts();
                if(!isValid)
                    return false;

                /********************************************************************
                *    In FnP always quantity should be 1.    So following check removed.
                ********************************************************************/

                /*isValid = this._isValidQty();
                  if(!isValid)
                    return false;*/
                /********************************************************************/

              // This loop is for accumlating the items of the free products.
              // The titles of the radio buttons will be
              // in the format -- PrimaryProductID$RelatedProductID$RelatedItemID --
              // TO set the variables to no values for every method invocation.
              //initializeVariables(formName);

              //this._addSecondaryRadioItems();
             // this._addSecondaryNonRadioItems();
              //this._getHiddenFieldValue();
              //this._setMessageValues();

      }catch(exception){alert(exception.message)}
      return isValid;
    },
    showFormId : function(){
        alert(this._formId);
    },
    openImages : function(){
    }
}// product Oject OO finished


    function updateProductPrice(){
        try{
        var allIsmpaoRfNum = '';
        var elems = document.forms['addToCartFrom'].elements;
        var attCnt = 0;
        for( var i=0; i<elems.length; i++)
        {
            if(elems[i].id.indexOf('attributesValue') !=-1 )
            {    if(elems[i].value != null && elems[i].value.length>0)
                {
                    attCnt++;
                    allIsmpaoRfNum   += elems[i].value + '#';
                }
            }
        }

        if(attCnt != $('attribCount').value )
            return false;

        if(contextpath=='/')
        {
            contextpath='';
        }
        var url = contextpath+'/faces/tiles/components/product/itemPrice.jsp';


        var myAjax = new Ajax.Updater(
            'itemPriceDiv',
            url,
            {
                method: 'GET',
                parameters: {'allAttribute':allIsmpaoRfNum,'catalogueId':$('mctrfnum').value},
                onFailure:handleFail
            });
        }catch(exception){alert(exception.message);return false;}
    }
    function checkPNo(e)
    {
        var unicode= e.charCode? e.charCode : e.keyCode
        if ( unicode !=8 ){ //if the key isn't the backspace key (which we should allow)
        if ( unicode<=48 || unicode>53) //if not a number
            return false //disable key press
        }
    }
    function updateCart(isCart){
    	var inputElements = document.getElementsByTagName('input');
		var addOnCount = 0;  
		for(i=0;i<inputElements.length;i++){
			if(inputElements[i].type=='checkbox')
				if(inputElements[i].checked)
					++addOnCount;
		}
		// totalCartSize = Existing cart item + addons + mainproduct i.e. 1
		var totalCartSize = parseInt($('totalCartItems').value) + addOnCount + 1;
            if(!isRestricted()){
                        return false;
                }
        if(!chkForJustDial()){
            return false;
        }
        if(totalCartSize > 5){
            alert("You can have a maximum of only 5 products in the shopping cart at one time");
            return false;
        }



        var prod = new Product('addToCartFrom');
        if(!prod.isCheckout()){
            return false;
        }/*else{
            if(!getDateOfDelivery())
                return false;
        }*/
                if(contextpath=='/')
        {
            contextpath='';
        }
        var url = contextpath+'/faces/tiles/components/product/miniShoppingCart.jsp';

        if(isCart != null && isCart.length>0)
        $('isWishList').value= isCart;
        $('invoke:action').value = "BuyerMainNavigationActionBean.addToCartAction";
        var myAjax = new Ajax.Updater(
            'minishoppingcart',
            url,
            {
                method: 'GET',
                parameters: $('addToCartFrom').serialize(),
                onFailure:handleFail
            });
    }
    function chkForJustDial(){
        var jstDialCatalogueId = $('justDialCatalogueNumber').value;
        var currentCatalogueId = $('mctrfnum').value;
        var totalCartSize = $('totalCartItems').value;
        if(jstDialCatalogueId == currentCatalogueId && totalCartSize > 0){
            alert('You Can Buy one Product At One Time.');
            return false;
        }
        return true;
    }
    function handleFail(request){
        alert("Sorry. There was an error.");
    }

    function changeMiscInfo(sourceId){
        var o_targetDiv = "miscellaneous";
        $(o_targetDiv).innerHTML="";
        $(o_targetDiv).innerHTML = $(sourceId).innerHTML;
    }

    function changeTabColor(obj) {
        if($('liRelated')!=null) {$('liRelated').className='';}
        if($('liSimilar')!=null) {$('liSimilar').className='';}
        if($('liDetails')!=null) {$('liDetails').className='';}
        if($('liSpecification')!=null) {$('liSpecification').className='';}
        if($('liDiscounted_Product')!=null) {$('liDiscounted_Product').className='';}
        if($('liFree_Products')!=null) {$('liFree_Products').className='';}
        if($('liPayment_Option')!=null) {$('liPayment_Option').className='';}
        if($('liDelivery_Location')!=null) {$('liDelivery_Location').className='';}
        if($('liReviews_Rating')!=null) {$('liReviews_Rating').className='';}

        obj.className='selected';
    }

    function openImages(productId,catalogueID,ctx)
    {
        //alert("productId-->"+productId+"catalogueID-->"+catalogueID)
        var page = ctx ;
        if(ctx=='/')
        {
            ctx='';
        }
        if(productId==null)
        {
            alert("Please select Item")
        }else
        {
                        page += "/faces/tiles/productImages.jsp?productID="+productId+"&catalogueID="+catalogueID;
            var win_porp = "location=no, toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no,height=450,width=500";
            window.open(page, "pImages",win_porp);
        }
    }
    /*function goToSimpleAddress(){
            if(!isRestricted()){
                        return false;
                }
        var prod = new Product('addToCartFrom');
        if(!prod.isCheckout()){
            return false;
        }else{
            if(!getDateOfDelivery())
                return false;
        }

        $('isWishList').value= "N";
        $('invoke:action').value = "BuyerCheckoutActionBean.checkoutAction";
        $(addToCartFrom).action = '/fnp/faces/jsp/ccsimpleAddress.jsp';
        $(addToCartFrom).submit();
    }*/

function goToSimpleAddress(){
    if(!isRestricted()){
    return false;
    }
    var prod = new Product('addToCartFrom');
    if(!prod.isCheckout()){
                    return false;
    }/*else{
                    if(!getDateOfDelivery())
                                    return false;
    }*/

    $('isWishList').value= "N";
    $('invoke:action').value = "BuyerCheckoutActionBean.checkoutAction";
    if(contextpath=='/')
    {
        contextpath='';
    }
    var url = contextpath+'/faces/tiles/components/product/miniShoppingCart.jsp';

    var myAjax = new Ajax.Updater('minishoppingcart',url,
    {
        method: 'GET',
        parameters: $('addToCartFrom').serialize(),
        onSuccess : handleQuichCheckout,
        onFailure:handleFail
    });
    }
    function handleQuichCheckout(transport){
        if(200 == transport.status){
        var responce = transport.responseText;
        if(responce.indexOf('ItIsHoliday')!=-1){
                        return false;
        }
        else{
            if(contextpath=='/')
            {
                contextpath='';
            }
        var loginuserId = $('loginuserId').value;
        if(loginuserId!=null && loginuserId != '')
        window.location.href = contextpath+'/faces/jsp/ccsimpleAddress.jsp';
        else
        window.location.href = contextpath+'/faces/jsp/checkoutLogin.jsp';

        }
        }
    }


    /**
    This will change the main image of the product when user click on the small images
    */
    function changeMainImg(newImg,which)
    {

        var form = document.forms[0];
        var ele =null;
        if(which=='main')
        {
            ele = document.getElementById("mainImg");
            ele.src = newImg;
            //document.getElementById('divImage').src=ele.src;
        }else{
        ele = document.getElementById("popupedLargeImg");
        ele.src = newImg;
        //document.getElementById('divImage').src=ele.src;
        }
    }
    function processReview(ctx , reviewType , pid, sid) {
        var path = ctx ;

        var w = 950;
        var h = 510;
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);

        if(ctx=='/')
        {
            ctx='';
        }
        var winProps ='toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left;

        if(reviewType == 'writeProductReview' && pid != null){
            path += "/faces/jsp/writeProductReview.jsp?pbirfnum="+pid;
            path += '&action=WriteProductReviewActionBean.writeProductReview_initAction';
        }
        else if( sid != null ){

            if(reviewType == 'writeSellerReview'){
                if($('_isLogged') != null && $('_isLogged').innerHTML == 'false'){
                alert('Please Login to write reviews.');
                return false;
                }
                 path += "/faces/jsp/writeSellerReview.jsp?ssirfnum=" + sid
                 path +='&action=WriteSellerReviewActionBean.writeSellerReview_initAction';
            }else if(reviewType == 'viewSellerReviews'){
                path +="/faces/jsp/sellerInfo.jsp?ssirfnum="+ sid;
            }
        }

        chld = window.open(path,'parent',winProps);
        return false;
}
function isRestricted(){
        if($('restrictedCategoryFlag').value == 'true'){
                alert('This product is not available currently. You can buy this during the same occasion next time');
                return false;
        }
        else{
                return true;
        }
}
function setRelatedPbiRfNum(){
    var pbis="";
    var list = document.getElementsByTagName('input');
    for(var i=0;i<list.length;i++){
        if(list[i].type=="checkbox" && list[i].id.indexOf("related_chk_box") != -1 && list[i].checked){
            var chkID = list[i].id;
            pbis = pbis + chkID.substring(chkID.indexOf("@")+1,chkID.length) + "#@";
        }
    }
    if(pbis != ""){
        pbis = pbis.substring(0,pbis.length-2);
    }
    $('relatedProductsPbis').value = pbis;
}

function setRankingStar(feed,hook,ratingFor)
{   var fullStar = 0;
fullStar = Math.floor(feed) ;


var star = Math.round(feed);
var totalStar = 5;
var fadStar = 0;

var halfStar = feed - fullStar ;


 if(halfStar > 0.5)
    {
    halfStar = 1;
    }

fadStar = totalStar - (fullStar + halfStar);

var fargment = document.createDocumentFragment();
fargment.appendChild(document.createTextNode(ratingFor))
var image = null;

for(var i = 1 ; i<= fullStar; i++)
{
    image = document.createElement("IMG");
    image.src = "/media/images/OctaShop/star_1.gif";

    image.id=""+i
    fargment.appendChild(image);

}

if(halfStar > 0)
{
    image = document.createElement("IMG");
    image.src = "/media/images/OctaShop/star_2.gif";
    image.id=""+i
    fargment.appendChild(image);
}
for(var i = 1 ; i<= fadStar; i++)
{
    image = document.createElement("IMG");
    image.src = "/media/images/OctaShop/star_3.gif";
    image.id=""+i
    fargment.appendChild(image);
}
var starTag = document.getElementById(hook);
starTag.appendChild(fargment);}

function setRelatedPbiRfNumNew(pbirfnum){

	//alert(pbirfnum);
   /* var pbis=document.getElementById('addonselectpbi').value;
	alert()
    var list = document.getElementsByTagName('input');
    for(var i=0;i<list.length;i++){
        if(list[i].type=="checkbox" && list[i].id.indexOf("related_chk_box") != -1 && list[i].checked){
            var chkID = list[i].id;
            pbis = pbis + chkID.substring(chkID.indexOf("@")+1,chkID.length) + "#@";
        }
    }
    if(pbis != ""){
        pbis = pbis.substring(0,pbis.length-2);
    } */

	$('relatedProductsPbis').value  = null;
	if(pbirfnum != null){
    $('relatedProductsPbis').value = pbirfnum; 
    updateCartAddOn('N');
	return true;
	}
	else
	
		return false;

	
}



function updateCartAddOn(isCart){
            if(!isRestricted()){
                        return false;
                }
        if(!chkForJustDial()){
            return false;
        }
         if($('totalCartItems').value >= 5){
            alert("You can have a maximum of only 5 products in the shopping cart at one time");
            return false;
        }



        var prod = new Product('addToCartFrom');
        if(!prod.isCheckout()){
            return false;
        }/*else{
            if(!getDateOfDelivery())
                return false;
        }*/
                if(contextpath=='/')
        {
            contextpath='';
        }
        var url = contextpath+'/faces/tiles/components/product/miniShoppingCart.jsp';

        if(isCart != null && isCart.length>0)
        $('isWishList').value= isCart;
        $('invoke:action').value = "BuyerMainNavigationActionBean.addToCartAddOnAction";
        var myAjax = new Ajax.Updater(
            'minishoppingcart',
            url,
            {
                method: 'GET',
                parameters: $('addToCartFrom').serialize(),
                onFailure:handleFail
            });
    }





