﻿
	 var ios = 0;
     var aos = 0;
     var counter = 0 ;

     function NewsletterValidator() {
         var inputs = document.getElementsByTagName("input");
         var oneSelected = false;
     
         for (var i = 5; i < inputs.length - 3; i++) {
             if (inputs[i].type == 'text') {
                 var msg = inputs[i].id.substring(33);
                 msg = $find(inputs[i].id.substring(0, 26) + "TextBoxWatermark" + msg)._watermarkText
                 if (inputs[i].value == '' || inputs[i].value == msg) {
                     $get('errormessage').innerHTML = "All fields marked * are required.";
                     return false;
                 }
             } else if (inputs[i].type == 'checkbox' && oneSelected == false) {
                 if (inputs[i].checked == true) {
                     oneSelected = true;
                 }
             }
         }
         if (oneSelected == false) {
             alert("To subscribe, you need to select at least one choice");
             return false
         }

         return true;
     
     }     
    function hidePopup() {
        $find("ctl00_ContentPlaceHolder1_AlwaysVisibleControlExtender1").get_element().style.display = 'none';
    }
    
    function CuteWebUI_AjaxUploader_OnPostback() {
        GetImages('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_ifrPhoto','ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_hListBoxArray','ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_hDeletedFiles');
    }

    function CreateNewAccount(frm, action, updateprogress) {
        var inputs = document.getElementsByTagName("input");
        var dropDowns= document.getElementsByTagName("select");
        var criteria = new Array;
        var icount = 0;

       for (var i = 5; i < inputs.length; i++) {
           if (inputs[i].value == '' && inputs[i].type != 'hidden' &&
                    inputs[i].id.indexOf("Company") == -1 &&
                    inputs[i].id.indexOf("dummyButton") == -1 &&
                    inputs[i].id.indexOf("Button1") == -1 &&
                    inputs[i].id.indexOf("Address2") == -1) {
               
           }
           else if (inputs[i].id.indexOf("Validator") == -1 && inputs[i].type != 'hidden' &&
                        inputs[i].id.indexOf("dummyButton") == -1 &&
                        inputs[i].id.indexOf("Button1") == -1) {
            
                criteria[icount] = inputs[i].value;
                icount += 1;
           }
       }

       criteria[icount + 1] = dropDowns[0].options[dropDowns[0].selectedIndex].value;
       criteria[icount + 2] = dropDowns[1].options[dropDowns[1].selectedIndex].value;
       criteria[icount + 3] = dropDowns[2].options[dropDowns[2].selectedIndex].value;
       criteria[icount + 4] = dropDowns[3].options[dropDowns[3].selectedIndex].value;

       //$get(updateprogress).style.display = "inline";
       //AutoComplete.CreateNewUserAccount(criteria, action, onCreateAccountSuccess, onCreateAccountFailed);
    }

    function copyBillingToShipping(chk) {
        var parent = "ctl00_ContentPlaceHolder1_account1_"
        var sState = $get(parent + 'ddlsState');
        var sCountry = $get(parent+'ddlsCountry');
        if (chk.checked == true) {
            $get(parent + 'TextBoxsCompany').value = $get(parent + 'TextBoxCompany').value;
            $get(parent + 'TextBoxsFirstname').value = $get(parent + 'TextBoxFirstname').value;
            $get(parent + 'TextBoxsLastname').value = $get(parent + 'TextBoxLastname').value;
            $get(parent + 'TextBoxsPhone').value = $get(parent + 'TextBoxPhone').value;
            $get(parent + 'TextBoxsAddress1').value = $get(parent + 'TextBoxAddress1').value;
            $get(parent + 'TextBoxsAddress2').value = $get(parent + 'TextBoxAddress2').value;
            $get(parent + 'TextBoxsCity').value = $get(parent + 'TextBoxbCity').value;
            sState.value = $get(parent + 'ddlbState').value;
            sCountry.value = $get(parent + 'ddlbCountry').value;
            $get(parent + 'TextBoxsZip').value = $get(parent + 'TextBoxbZip').value;
            //$get('bStateNonUS').value = '';
            sState.disabled = $get(parent + 'ddlbState').disabled;
        } else {
            $get(parent + 'TextBoxsCompany').value = '';
            $get(parent + 'TextBoxsFirstname').value = '';
            $get(parent + 'TextBoxsLastname').value = '';
            $get(parent + 'TextBoxsPhone').value = '';
            $get(parent + 'TextBoxsAddress1').value = '';
            $get(parent + 'TextBoxsAddress2').value = '';
            $get(parent + 'TextBoxsCity').value = '';
            //$get('bStateNonUS').value = '';
            sState.value = 'AL';
            sCountry.value = 'US';
            $get(parent + 'TextBoxsZip').value = '';
            sState.disabled = $get(parent + 'ddlbState').disabled;
        }
    }


//    function onCreateAccountSuccess() {
//        window.location = "Default.aspx";
//    }

//    function onCreateAccountFailed(msg) {
//        $get("ctl00_ContentPlaceHolder1_labelMsg").innerHTML = msg._message;
//    }
        
    function EndGetData(arg)
    {
     document.getElementById("Grid").innerHTML = arg;
    }
    
    function DisplaySaveTemplate() {
    
        $get("ctl00_ContentPlaceHolder1_eBayItem1_LabelHeader").innerHTML = "Create New Template";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_Label1").innerHTML = "Please enter a name for your template. <br /><span style='font-size: 0.8em; color: #727272'>Note: using the same template name will overwright the old one.</span>";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_hTag").value= "template";
        $get("divRow").style.display= "block";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_TextBoxRowName").value = "New Template"
        $get("divFCK").style.display= "none";
        $find("PopupInputBox").show();
    }
    
    function NewRow() {
    
        $get("ctl00_ContentPlaceHolder1_eBayItem1_LabelHeader").innerHTML = "Create New Row";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_Label1").innerHTML = "Please write a description of a new row below and press Ok.";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_hTag").value= "";
        $get("divRow").style.display= "block";
        
        $get("divFCK").style.display= "none";
        $find("PopupInputBox").show();
    }

    function DisplayPasteTable() {
    
        $get("ctl00_ContentPlaceHolder1_eBayItem1_LabelHeader").innerHTML = "Paste To Table";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_Label1").innerHTML = "Pleaes paste the existing HTML to the space provided and click 'Ok'. <br /><span style='font-size: 0.8em; color: #727272'>Note: all existing information on the table will be over-written.</span>";
        $get("ctl00_ContentPlaceHolder1_eBayItem1_hTag").value= "paste";
        $get("divRow").style.display= "none";
        
        $get("divFCK").style.display= "block";
        $find("PopupInputBox").show();
    }
    
    function PasteToTable() 
    {
        
    }
    
    function GetImages(frame,hListBoxArray,hDeletedFiles) {
     var rv = null; 

     // if IE 
     
     if (document.all){ 
        
         rv = document.frames[document.frames.length-1].document; 
         if (rv.title != 'Untitled Page') rv = document.frames[0].document; 
     } else { 
       // if contentDocument exists, W3C compliant (Mozilla) 
       rv = document.getElementById(frame).contentDocument; 
       
     } 
    
        $get(hListBoxArray).value = rv.getElementById("hListBoxArray").value
        $get(hDeletedFiles).value = rv.getElementById("hDeletedFiles").value
        scrollTo(0,0);
    }
    
    function CheckValidation() {
        var titleTextBox = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_TitleTextBox');
        var startingPrice = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_StartingPriceTextBox');
        var radioButton2 = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_RadioButton2');
        var radioButton1 = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_RadioButton1');
        var buyNowTextBox = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_BuyNowTextBox');
              
     
        if (titleTextBox != null && titleTextBox.value == '') { 
                alert('Please enter the title for the item.'); 
                titleTextBox.focus(); 
                return false;
        }
        
        if (startingPrice != null && startingPrice.value == '' && startingPrice.disabled == false) 
        { 
                alert('Starting Price cannot be left empty.'); 
                startingPrice.focus(); 
                return false;
        } 
        
        if (radioButton2!=null && radioButton2.checked == true && buyNowTextBox.value == '') 
            { 
                alert('Buy Now Price cannot be left empty.'); 
                buyNowTextBox.focus();
                return false; 
            }
   
     }
  
    function checkPrices() {
        var bestOfferCheckBox = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_BestOfferCheckBox');
        var startingPrice = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_StartingPriceTextBox');
        var radioButton2 = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_RadioButton2');
        var radioButton1 = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_RadioButton1');
        var buyNowTextBox = $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_BuyNowTextBox');
        
        if (radioButton2!=null && radioButton2.checked == true) {
            if (startingPrice.value != '') buyNowTextBox.value = startingPrice.value; 
            startingPrice.disabled = true; 
            startingPrice.value = '';
            $get('ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_isDisabled').value="true";
        }

        if (bestOfferCheckBox!=null && bestOfferCheckBox.checked == true) {
            radioButton2.checked = true; 
            radioButton1.disabled = true; 
            startingPrice.disabled = true; 
            if (startingPrice.value != '') buyNowTextBox.value = startingPrice.value; 
            startingPrice.value = ''} 
        else if (radioButton2!=null) radioButton1.disabled= false; 

       if (radioButton1!=null && radioButton1.checked == true) startingPrice.disabled = false;     
       
    }
        
    function createTextBox(rowIndex)
    {
        var textbox = document.createElement('input');
        textbox.setAttribute('id','other_'+rowIndex);
        textbox.setAttribute('name','other$'+rowIndex);
        textbox.setAttribute('type','text');
        return textbox;
    }
    
    function CreateOtherBox(the_box, tblId,hHiddenField,rowIndex) {
        var the_ddlbox = $get(the_box.id);
        var tblBodyObj = document.getElementById(tblId).tBodies[0];
        
        if (the_box.type == 'checkbox') {
            var label
            var labels = document.getElementsByTagName( "label" );
            for ( var i = 0; i < labels.length; i++ ) {
                if (labels[i].htmlFor == the_box.id)
                {
                    label = labels[i];
                    break;
                } // end if
            } //next
        
            if (label.innerHTML == "Other" && the_box.checked == true )
            
                {
    	            var newCell = tblBodyObj.rows[rowIndex].getElementsByTagName("td")[1];
                    var textbox = createTextBox(rowIndex);
	                newCell.appendChild(textbox);
	                textbox.focus()                
                } // end if
            else if (label.innerHTML == "Other" && the_box.checked == false ){
            	    var allRows = tblBodyObj.rows[rowIndex].getElementsByTagName("td")[1];
    	            
		            if (allRows.lastChild.id.indexOf("other") > -1) {
			            allRows.removeChild (allRows.lastChild);
		            }    	            
                
            } // end if
            
        } // end if
        
        else 
            if (the_ddlbox.options[the_ddlbox.selectedIndex].text =="Other")
            {

	            //var newCell = tblBodyObj.rows[rowIndex].insertCell(-1);
	            var newCell = tblBodyObj.rows[rowIndex].getElementsByTagName("td")[1];
                var textbox = createTextBox(rowIndex);
	            newCell.appendChild(textbox);
	            textbox.focus()
            }
            else
            {
	            var allRows = tblBodyObj.rows[rowIndex].getElementsByTagName("td")[1];
    	            
		            if (allRows.childNodes.length > 2 && allRows.childNodes[2].id.indexOf("other") > -1) {
			            allRows.removeChild (allRows.lastChild);
		            }

	        }
            
             setHiddenField (the_ddlbox.id, hHiddenField);
        }
    
    
    function setHiddenField(feature, hHiddenField)
    {
        var the_box = $get(feature);
        hHiddenField = 'ctl00_ContentPlaceHolder1_eBayItem1_Wizard1_'+hHiddenField;
        if (the_box.type=="checkbox") {
          $get(hHiddenField).value = the_box.checked
        }
        else $get(hHiddenField).value = the_box.options[the_box.selectedIndex].text
    }
    
    function insertOldSchool(theSel, newText, newValue)
    {
      if (theSel.length == 0) {
        var newOpt1 = new Option(newText, newValue);
        theSel.options[0] = newOpt1;
        theSel.selectedIndex = 0;
      } else if (theSel.selectedIndex != -1) {
        var selText = new Array();
        var selValues = new Array();
        var selIsSel = new Array();
        var newCount = -1;
        var newSelected = -1;
        var i;
        for(i=0; i<theSel.length; i++)
        {
          newCount++;
          if (newCount == theSel.selectedIndex) {
            selText[newCount] = newText;
            selValues[newCount] = newValue;
            selIsSel[newCount] = false;
            newCount++;
            newSelected = newCount;
          }
          selText[newCount] = theSel.options[i].text;
          selValues[newCount] = theSel.options[i].value;
          selIsSel[newCount] = theSel.options[i].selected;
        }
        for(i=0; i<=newCount; i++)
        {
          var newOpt = new Option(selText[i], selValues[i]);
          theSel.options[i] = newOpt;
          theSel.options[i].selected = selIsSel[i];
        }
      }
    }

    function appendOldSchool(theSel, newText, newValue)
    {
      if (theSel.length == 0) {
        var newOpt1 = new Option(newText, newValue);
        theSel.options[0] = newOpt1;
        theSel.selectedIndex = 0;
      } else if (theSel.selectedIndex != -1) {
        var selText = new Array();
        var selValues = new Array();
        var selIsSel = new Array();
        var newCount = -1;
        var newSelected = -1;
        var i;
        for(i=0; i<theSel.length; i++)
        {
          newCount++;
          selText[newCount] = theSel.options[i].text;
          selValues[newCount] = theSel.options[i].value;
          selIsSel[newCount] = theSel.options[i].selected;
          
          if (newCount == theSel.selectedIndex) {
            newCount++;
            selText[newCount] = newText;
            selValues[newCount] = newValue;
            selIsSel[newCount] = false;
            newSelected = newCount - 1;
          }
        }
        for(i=0; i<=newCount; i++)
        {
          var newOpt = new Option(selText[i], selValues[i]);
          theSel.options[i] = newOpt;
          theSel.options[i].selected = selIsSel[i];
        }
      }
    }

    function removeOldSchool(theSel)
    {
      var selIndex = theSel.selectedIndex;
      if (selIndex != -1) {
        for(i=theSel.length-1; i>=0; i--)
        {
          if(theSel.options[i].selected)
          {
            theSel.options[i] = null;
          }
        }
        if (theSel.length > 0) {
          theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
        }
      }
    }

    function buttonDelete_onclick(the_listbox,hdeletedFiles) {
        var the_listbox = $get(the_listbox);
        var selectedIndex = the_listbox.options.selectedIndex;
        if (selectedIndex == -1) return false
                
        var currentItem = the_listbox.options[selectedIndex].text;      
        
        if (hdeletedFiles!=undefined) $get(hdeletedFiles).value += currentItem + "|";
        removeOldSchool(the_listbox);
        
        getElementsByType("hidden",the_listbox);
        
    }
    	
    function buttonUpDown_onclick(bttn, the_listbox) {
        var the_listbox = $get(the_listbox);
        var selectedIndex = the_listbox.options.selectedIndex;
        if (selectedIndex == -1) return false
        
        var currentItem = the_listbox.options[selectedIndex].text;
            
        if (bttn.value == 'Up') {
            if (selectedIndex == 0) return false 
            
            removeOldSchool(the_listbox);
            insertOldSchool(the_listbox,currentItem,currentValue);
            the_listbox.options.selectedIndex = selectedIndex-1;

        } else {
            if (selectedIndex + 1 == the_listbox.length) return false 
            removeOldSchool(the_listbox);
            the_listbox.options.selectedIndex = selectedIndex;
            appendOldSchool(the_listbox,currentItem,currentValue);
            the_listbox.options.selectedIndex = selectedIndex+1;
            
        }
        
        getElementsByType("hidden",the_listbox) //$find('ctl00_ContentPlaceHolder1_eBayItem1_hListBoxArray');
            
    }

    function getElementsByType(type, the_listbox) {
        var _input = document.getElementsByTagName("input");
        var k=0;
        for (var i=0;i<_input.length;i++) {
            if (_input[i].type==type && _input[i].id.indexOf('hListBoxArray')>-1) {
                var hListArray = _input[i] //$find('ctl00_ContentPlaceHolder1_eBayItem1_hListBoxArray');
                hListArray.value = '';
            
                for (var i = 0; i<the_listbox.options.length; i++) {
                    hListArray.value += the_listbox.options[i].text+'|';
                }
                return true;
            }
        }
    }
