var Ajax= new sack();

function  displayinfo()
{
	eval(Ajax.response);
}

function openCloseDiv(site_url,catid)
{
    if (document.getElementById('div_'+catid).style.display == '')
    {
        document.getElementById('img_'+catid).src = site_url+'/images/bullet_green_arrow_right.gif';
        document.getElementById('div_'+catid).style.display = 'none';
    }
    else if (document.getElementById('div_'+catid).style.display == 'none')
    {
        document.getElementById('img_'+catid).src = site_url+'/images/bullet_green_arrow_down.gif';
        document.getElementById('div_'+catid).style.display = '';
    }
}

function showTextPer()
{
	if( document.getElementById('txt_per').style.display == 'none')
	{
		if(document.getElementById('chk_per').checked == 'false')
		{
			document.getElementById('chk_per').checked = 'true';
		}
		document.getElementById('txt_per').style.display = '';
	}
	else 
	{
		if(document.getElementById('chk_per').checked == 'true')
		{
			document.getElementById('chk_per').checked = 'false';
		}
		document.getElementById('txt_per').style.display ='none';
	}
	return false;

}

function addToCart(imgName,imgCode,imgPrice)
{
    frm = document.Form_Name;
	if(GenValidation(frm.txt_qnty,'Quantity','','') == '')
	{
		return false;
	}
	else
	{
		document.getElementById('hide_name').value = imgName ;
		document.getElementById('hide_code').value = imgCode;
		document.getElementById('hide_price').value = imgPrice;
		document.Form_Name.submit();
        return true;
	}
}

function showCart(site_url,sess_cart)
{
  	 if(sess_cart != 0) 
	 {
		window.location.href = site_url+'/wedding-store/product/view-cart.html';
        return true;
	 } 
	 else 
	 {
		alert('Please add at least one item to the cart.');
		return false;
	 } 	
}

function validateAddtoCart()
{
    frm = document.Form_Name;
    var minqty = parseInt(document.getElementById('hid_MinQty').value);
    var buyingqty = parseInt(document.getElementById('txt_quantity').value);

    if (GenValidation (frm.txt_quantity,'Quantity','','') == '')
    {
        return false;
    }
    else if(buyingqty < minqty)
    {
        alert('You cannot buy at this quantity.');
        document.getElementById('txt_quantity').value = minqty;
        return false;
    }
	else if(OnlyNumbers(frm.txt_quantity)=='')
    {
        return false;
    }
	else if(document.getElementById('sel_color'))
	{
		if(document.getElementById('sel_color').value == 0)
		{
			alert('Please select color.');
			document.getElementById('sel_color').focus();
			return false;
		}
	}
    else
    {
        return true;
    }
}

////******* FUNCTION FOR EXPLODING A STRING INTO AN ARRAY ******////////

function explodeArray(item,delimiter)
{
    tempArray=new Array(1);
    tempArray1=new Array(1);
    var Count=0;
    var tempString=new String(item);
    while (tempString.indexOf(delimiter)>-1)
    {
        tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
        tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
        Count=Count+1;
    }
    tempArray[Count]=tempString;
    var i = 0,j=0;
    
    while (i < tempArray.length) // storing the array elements into another array by removing nulls
    {
        if (tempArray[i] != '')
        {
            tempArray1[j] = tempArray[i];
            j++;
        }
        i++;
    }
    
    return tempArray1;
}

function getProductSearchPage(site_url)
{
    var keyword = document.getElementById('txt_keyword').value;

    if (keyword == '')
    {
        alert('Please enter a keyword');
        document.getElementById('txt_keyword').focus();
        return false;
    }
    else
    {

        for (var x=0; x<keyword.length; x++) // replaces all commas with spaces
        {
            keyword = keyword.replace(","," ");
        }
               
        /*var keyword_arr = new Array();
        keyword_arr = explodeArray(keyword,' '); // explodes string into array also removes spaces
        var newkeyword = '';
        var i=0;
       
        while (i<keyword_arr.length) 
        {
            newkeyword += keyword_arr[i]+"-";
            i++;
        }

        newkeyword = newkeyword.substr(0,newkeyword.length-1);
		*/
		
		newkeyword = escape(escape(ltrim(rtrim(keyword))));
		
        document.Form_Name.action = site_url+'/wedding-store/search/'+newkeyword+'.html';
        document.Form_Name.submit();
        return true;
    }
    
}

function appendColor(color)
{
    var arr = color.split('-')
    document.getElementById('hide_name').value += ' - '+arr[1];
}