var _vzgoflowud="undefined";
 var _vzgoflowjsonArrayObj;

 function isArray(obj) {if (obj== _vzgoflowud || obj == null) return false;  return obj.constructor == Array;}
 function  dw(a){document.write(a)};

function vzgoflowpost2handler(params){
   var vzgoflow_ah = "/foryourhome/goflow/common/GenericHandlers/directordering.ashx";
   var hdnfieldvalue,productid;
   var promocodefound = false;
   var vzgoflowfrmhtml = "";
   try
   {
        vzgoflowfrmhtml = "<form name='vzgoflowfrm' id='vzgoflowfrm' method='post' action='"+vzgoflow_ah+"'>";
        for(var key in params) {
            if(key == "vzgoflow_products"){
                for(var ol=0;ol < params[key].product.length; ol++)
                {
                    if(params[key].product[ol].id != null)
                        hdnfieldvalue=productid = "id:" + params[key].product[ol].id;
                    if(params[key].product[ol].term != null)
                       hdnfieldvalue = hdnfieldvalue + "~term:" + params[key].product[ol].term;
                    if(params[key].product[ol].promo_offer_code != null){
                        hdnfieldvalue = hdnfieldvalue + "~promoinfo:";
                    for(var il=0;il < params[key].product[ol].promo_offer_code.length; il++)
                    {
                    if(params[key].product[ol].promo_offer_code[il].promoid!= null && params[key].product[ol].promo_offer_code[il].promoid != ''){
                        promocodefound = true;
                    if(params[key].product[ol].promo_offer_code[il].offerid!= null && params[key].product[ol].promo_offer_code[il].offerid != ''){
                       hdnfieldvalue = hdnfieldvalue +params[key].product[ol].promo_offer_code[il].promoid+'-' +params[key].product[ol].promo_offer_code[il].offerid + "|";
}
                                                                                                 else{
                                                                                                                hdnfieldvalue = hdnfieldvalue +params[key].product[ol].promo_offer_code[il].promoid+'-' + ''+ "|";
                                                                                                }
                                                                               }
                                                  }

                                                }
                                                if(promocodefound)
                                                                vzgoflowfrmhtml = vzgoflowfrmhtml + "<input type='hidden' name='"+key+ol+"' value='"+hdnfieldvalue+"' >";
                                                else
                                                                vzgoflowfrmhtml = vzgoflowfrmhtml + "<input type='hidden' name='"+key+ol+"' value='"+productid+"' >";
                                  }
                                 }
                                 else {
                                                hdnfieldvalue = params[key];
                                                if(params[key] != null && params[key] != '')
                                                                vzgoflowfrmhtml = vzgoflowfrmhtml + "<input type='hidden' name='"+key+"' value='"+hdnfieldvalue+"'>";
                                 }
                   }
                   if(vzgoflowfrmhtml != "")
                    vzgoflowfrmhtml= vzgoflowfrmhtml+"</form>";
                  
                   //alert ('vzgoflowfrmhtml -' + vzgoflowfrmhtml);
                   document.body.innerHTML = document.body.innerHTML + vzgoflowfrmhtml;
                   document.vzgoflowfrm.submit();
   }
   catch(err)
   {       
   }
 }




 function vzgoflowsetpostdata()
 {
    vzgoflowjsonArrayObj = {
        //Mandatory Fields - vzgoflow_promo_offer_code is optional for stand alone products & registration.  Vzgoflow_productid is not needed for registration
         'vzgoflow_clientid': 'Moxie'  // -- or Onecms
        ,'vzgoflow_flowtype'  : 'TBUN'
        ,'vzgoflow_promotext' : 'Triple Play with $150 off' // -- example se<A HREF="http://localhost/content/CommonTemplates/Templates/">http://localhost/content/CommonTemplates/Templates/</A>t value based on promo displayed.
        ,'vzgoflow_pagename' : 'Verizon Home Page' // -- Origination page name
        ,'vzgoflow_promolocation' : 'Default'  // possible values right,left,top,bottom,center -- HBX requires this info
        ,'vzgoflow_products':{
              product:
                [
           {'id':'T901','promo_offer_code': [ { "promoid": "PR10000021", "offerid": "OF10000095" },
                      { "promoid": "PR10000038", "offerid": "OF10000105" },
                      { "promoid": "PR10000039", "offerid": "OF10000105" }  ]
           },
           {'id':'T902','promo_offer_code': [ { "promoid": "", "offerid": "OF10000095" },
                      { "promoid": "PR10000038", "offerid": "OF10000105" }]

           }
          ]
    }

        //Non Mandatory Fields
        ,'vzgoflow_couponcode': 'xxxx'
        ,'vzgoflow_tn': 'xxx-xxx-xxxx'
        // if TN is supplied address fields are not Required.
        ,'vzgoflow_address1' : ''
        ,'vzgoflow_address2': ''
        ,'vzgoflow_city': ''
        ,'vzgoflow_state': ''
        ,'vzgoflow_zip': ''
      };

    vzgoflowpost2handler(vzgoflowjsonArrayObj);
 }					
		
//Added - ONECMS fuction to set the JSon Array Object from XML, called from onecms Pages
//Please dont remove this function.
 function setGoFlowJSonArray(bundleid,xmlSource)
 {

    if (window.DOMParser) {
        parser=new DOMParser();
        xmlDoc=parser.parseFromString(xmlSource,"text/xml");
    } else  { // Internet Explorer 
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async="false";
        xmlDoc.loadXML(xmlSource); 
    }
    
    var x=xmlDoc.getElementsByTagName("BANNER");    
    var ArrayProductID = [];
    var ArrayTerm = [];
    var ArrayServiceInfo = [];
    var ArrayPromoID = [];
    var ArrayOfferID = [];
    var strJSon;    
    
    try {    
            for (var i=0;i<x.length;i++) 
            {    
                if (x[i].attributes.getNamedItem('ID').value == bundleid)
                {   			
                    strJSon = "{ " ;
                    //strJSon = strJSon + "'vzgoflow_clientid' : '" + "" + "'," ;
                    strJSon = strJSon + "'vzgoflow_clientid' : 'ONECMS',";
                                                                                  
                    var vzGoFlowType = x[i].getElementsByTagName("VZGOFLOW_FLOWTYPE")[0].childNodes[0].nodeValue;
                    strJSon = strJSon + "'vzgoflow_flowtype' : '" + vzGoFlowType ;
									                                                   
                    var vzGoFlowPromoTxt = x[i].getElementsByTagName("VZGOFLOW_PROMOTEXT")[0].childNodes[0].nodeValue;
                    strJSon = strJSon + "'," + "'vzgoflow_promotext' : '" + vzGoFlowPromoTxt ;
                                                                 
                    var vzGoFlowPageName = x[i].getElementsByTagName("VZGOFLOW_PAGENAME")[0].childNodes[0].nodeValue;
                    strJSon = strJSon + "'," + "'vzgoflow_pagename' : '" + vzGoFlowPageName ;			
                                      
                    var vzGoFlowPromoLoc = x[i].getElementsByTagName("VZGOFLOW_PROMOLOCATION")[0].childNodes[0].nodeValue;
                    strJSon = strJSon + "'," + "'vzgoflow_promolocation' : '" + vzGoFlowPromoLoc ;                        
                    			
                    var products = x[i].getElementsByTagName("PRODUCT");
                    strJSon = strJSon + "'," + " 'vzgoflow_products':{  product: [ " ;
                                                              
                    for(var a=0;a < products.length;a++)
                    {
                        if (a!=0)
                            strJSon = strJSon + ",";               
                        
                        ArrayProductID[a] = products[a].attributes.getNamedItem('ID').value;
                        ArrayTerm[a] = products[a].attributes.getNamedItem('TERM').value;
                        
                        strJSon = strJSon + " {'id': '" + ArrayProductID[a] + "', 'term' : '" +  ArrayTerm[a] + "', 'promo_offer_code': [ ";
                        
                        //strJSon = strJSon + " {'id': '" + ArrayProductID[a] + "', 'promo_offer_code': [ ";                                  
                        
                        ArrayServiceInfo[a] = products[a].attributes.getNamedItem('SERVICEINFO').value;                               
                        //var promooffer = products[a].childNodes; //not working with Firefox
                        var promooffer = products[a].getElementsByTagName("PROMO_OFFER_CODE");                                                
                        for (b=0;b<promooffer.length;b++)
                        {
                            if (b!=0)
                                strJSon = strJSon + "," ;                    
                            ArrayPromoID[b] = promooffer[b].attributes.getNamedItem('PROMOID').value;
                            ArrayOfferID[b] = promooffer[b].attributes.getNamedItem('OFFERID').value;
                            strJSon = strJSon + " { 'promoid': '" + ArrayPromoID[b] + "', 'offerid': '" + ArrayOfferID[b] + "' }";
                        }
                        strJSon = strJSon + "]  }" ;
                    } 
                    strJSon = strJSon + "]  }" ;
                    strJSon = strJSon + "," +  "'vzgoflow_couponcode' : '" + "" ;
                    strJSon = strJSon + "'," +  "'vzgoflow_tn' : '" + "" ;
                    strJSon = strJSon + "'," +  "'vzgoflow_address1' : '" + "" ;
                    strJSon = strJSon + "'," +  "'vzgoflow_address2' : '" + "" ;
                    
                    strJSon = strJSon + "'," +  "'vzgoflow_city' : '" + "" ;
                    strJSon = strJSon + "'," +  "'vzgoflow_state' : '" + "" ;
                    strJSon = strJSon + "'," +  "'vzgoflow_zip' : '" + "" + "'}" ;                             
                }    
        }    
    } catch (ex)
    {
    
    }                   
    //alert (strJSon);
    var vzgoflowjsonArrayObj = eval('(' + strJSon + ')');    
    //alert ('vzgoflowjsonArrayObj - ' + vzgoflowjsonArrayObj);    
    vzgoflowpost2handler(vzgoflowjsonArrayObj);
 }


 
