﻿// JScript File
function changeBackgroud(imageName,good)
{
var imageUrl='url(skins/skin_1/images/'+imageName+') repeat-x';
good.style.background=imageUrl;
}

function RateComment(ProductID,MyCustomerID,MyVote,RatersCustomerID)
{
    RateCommentFrm.location = 'RateComment.aspx?Productid=' + ProductID + '&VotingCustomerID=' + MyCustomerID + '&MyVote=' + MyVote + '&CustomerID=' + RatersCustomerID;
    document.getElementById('productHelpBox_'+RatersCustomerID).style.display='none';
    document.getElementById('productHelpThanks_'+RatersCustomerID).style.display='block';    
}

function validateRating()
{
var validateHTML = '';
var validateBool = true;
if(document.getElementById('rating').value==0)
{
validateHTML +='Please select your rating!\n';
document.getElementById('errorRating').innerHTML='<span class="errorText">Overall rating:*</span>'
validateBool = false;
}
if(document.getElementById('DropOwnership').value==0)
{
validateHTML +='Please select your Ownership!\n';
document.getElementById('errorOwnership').innerHTML='<span class="errorText">Ownership*</span>'
validateBool = false;
}
if(document.getElementById('DropKnowledge').value==0)
{
validateHTML +='Please select your Knowledge!\n';
document.getElementById('errorTech').innerHTML='<span class="errorText">Tech Knowledge*</span>'
validateBool = false;
}
if(document.getElementById('reviewPros').value.length==0)
{
validateHTML +='Please enter your Pros!\n';
document.getElementById('errorPros').innerHTML='<span class="errorText">Pros:*</span>'
validateBool = false;
}
else if (document.getElementById('reviewPros').value.length>1000)
{
validateHTML +='The length of Pros must be less than 1000 characters!\n';
document.getElementById('errorPros').innerHTML='<span class="errorText">Pros:*</span>'
validateBool = false;
}
if(document.getElementById('reviewCons').value.length==0)
{
validateHTML +='Please enter your Cons!\n';
document.getElementById('errorCons').innerHTML='<span class="errorText">Cons:*</span>'
validateBool = false;
}
else if (document.getElementById('reviewCons').value.length>1000)
{
validateHTML +='The length of Cons must be less than 1000 characters!\n';
document.getElementById('errorCons').innerHTML='<span class="errorText">Cons:*</span>'
validateBool = false;
}
if (document.getElementById('reviewThoughts').value.length>1000)
{
validateHTML +='The length of thoughts must be less than 1000 characters!\n';
document.getElementById('errorThoughts').innerHTML='<span class="errorText">Other thoughts:</span>'
validateBool = false;
}
if(document.getElementById('checkReviewGuidelines').checked==false)
{
validateHTML +='Please check the Product Review Guidelines!\n';
validateBool = false;
}
if(validateHTML.length!=0)
{
alert(validateHTML);
}

return validateBool;
}



function switchBanner(mainBox,displayBox)
{
var bannerArray = document.getElementById(mainBox).childNodes;
var displayArray = document.getElementById(displayBox).getElementsByTagName('div');
for(var i =0;i<bannerArray.length;i++)
{
if(bannerArray[i].tagName != null)
{
if(bannerArray[i].tagName.toUpperCase()=='DIV')            
{
bannerArray[i].style.display='none';
}
}
}
document.getElementById(displayBox).style.display='block';
if(displayBox == 'productManufacturerinfoBox')
{
document.getElementById('productManufacturerinfoBox2').style.display='block';
document.getElementById(mainBox).style.border='0px';
}
else
{
document.getElementById('productManufacturerinfoBox2').style.display='none';
document.getElementById(mainBox).style.border='1px solid #C6C6C6';
//document.getElementById(mainBox).style.borderTop='0px solid white';
}
}


function switchImage(mainBox,dispalyImage)
{
    var imgArray = document.getElementById(mainBox).getElementsByTagName('img');
    for (var i=0; i <imgArray.length;i++)
    {
        imgArray[i].src=imgArray[i].src.substring(0,imgArray[i].src.length-5) + '1.jpg';
    }
    document.getElementById(dispalyImage).src=document.getElementById(dispalyImage).src.substring(0,document.getElementById(dispalyImage).src.length-5) +'2.jpg';
}


function changePageNum(pageNum,increase,formName,plus)
{
if(plus)
{
document.getElementById('pagenum').value=pageNum-(-increase);
}
else
{
document.getElementById('pagenum').value=pageNum-increase;
}
formName.submit();
}

function checkall(objectName, ischecked)
{
var checkboxArray = document.getElementById(objectName).getElementsByTagName('input');
for(var i=0;i<checkboxArray.length;i++)
{
    if(checkboxArray[i].type=='checkbox' && checkboxArray[i].id != 'checkAll')
    {
        checkboxArray[i].checked = ischecked;
    }
}
}

function scRemoveSelected(objectName)
{
var checkboxArray = document.getElementById(objectName).getElementsByTagName('input');
for(var i=0;i<checkboxArray.length;i++)
{
    if(checkboxArray[i].type=='checkbox' && checkboxArray[i].id != 'checkAll' && checkboxArray[i].checked == true)
    {
        var quanName = 'Quantity_' + checkboxArray[i].id.replace('CheckBox_','');
        document.getElementById(quanName).value='0';
    }
}
}


function movetoWishList(SelectedValue)
{
    var selectedProduct = '';
    var checkboxArray = document.getElementById('scDisplayTable').getElementsByTagName('input');
    if(SelectedValue == 1)
    {
    for(var i=0;i<checkboxArray.length;i++)
    {
        if(checkboxArray[i].type=='checkbox' && checkboxArray[i].id != 'checkAll' && checkboxArray[i].checked == true)
        {
            selectedProduct += checkboxArray[i].id.replace('CheckBox_','') + ',';
        }
    }
    if(selectedProduct!='')
    {    
    //alert('wishlist.aspx?movetowishlist=1&selectedid=' + selectedProduct.substring(0,selectedProduct.length-1))
    self.location.href='wishlist.aspx?moveto=wishlist&selectedid='+selectedProduct.substring(0,selectedProduct.length-1);
    }
    }
}

function ClearSelected()
{
    var allCheckBox = document.getElementsByName('optionitem');
    for(var i = 0 ; i<allCheckBox.length;i++)
    {
        allCheckBox[i].checked=false;
    }
}


function OperateOption(Atag,ShoppingCartRecID,optionitemid)
{

    var RadioName= 'shoppingcartOptions_' +ShoppingCartRecID;    
    if(optionitemid==0)
    {
        document.getElementById(RadioName).style.display=(document.getElementById(RadioName).style.display='none'?'block':'none');
    }
    
    var allDiv = document.getElementById(RadioName).getElementsByTagName('div');
    Atag.innerHTML = (Atag.innerHTML=='(expand for options)'?'(hide options)':'(expand for options)');
    for (var i =1;i<allDiv.length;i++) //Get from the second div
    {
        if(allDiv[i].id !='checked')
        {
            allDiv[i].style.display = (allDiv[i].style.display=='none'?'block':'none');
        }
    }

}


function CountWords(obj, CountDiv)
{
    document.getElementById(CountDiv).innerHTML = obj.value.length;
}

function IdExists(idName){
  try{   
   if(document.getElementById(idName)){return true;}else{  return false;
    }
  }catch(e){
   return false;
  }
 } 
