var SITE_SERVER_PATH = window.location.protocol+"//"+window.location.hostname; 
var SITE_PATH =  SITE_SERVER_PATH+'/';
var SECURE_SITE_PATH = 'https://'+window.location.hostname+'/';

/******************** general functions **********************/

function isBlank(strValue)
{
	 for(var i = 0; i < strValue.length; i++)
	 {
		 var c = strValue.charAt(i);
		 if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	 }
 	return true; 
}

function isValidInteger(strValue)
{
	var regex  = /^[0-9]+$/;
	var mat = regex.test(strValue);				
    if(!mat)
    {
		return false;
    }
	
	return true;
}
	
function isValidEmail(strEmail) 
 {
	 // assume an email address cannot start with an @ or white space, but it 
	 // must contain the @ character followed by groups of alphanumerics and '-' 
	 // followed by the dot character '.' 
	 // It must end with 2 or 3 alphanumerics. 
	 // 
	 var alnum="a-zA-Z0-9"; 
	 exp="^[^@\\s]+@(["+alnum+"+\\-]+\\.)+["+alnum+"]["+alnum+"]["+alnum+"]?$"; 
	 emailregexp = new RegExp(exp); 
	 result = strEmail.match(emailregexp); 
	 if (result != null) 
	 {
		 return true; 
	 }
	 else 
	 {
		 return false; 
	 }
 }	
	
 function isValidString(strVal) 
 {
	 var regex = /^[_]*[a-zA-Z_]+[a-zA-Z0-9_]+$/; 
	 if(!regex.test(strVal)) 
	 {
		 return false; 
	 }
	 else
	 {
		 return true; 
	 }
 }	

 function IsAlphaNumeric(strVal) 
 {
	 var regex = /^[a-zA-Z]+[0-9]+[a-zA-Z0-9]*$/; 
	 if(!regex.test(strVal)) 
	 {
		 return false; 
	 }
	 return true; 
 }
 
 function checkFileType(fld, strTypes) 
 {
	 var strTypeList="";
	 strArray = strTypes.split(" "); 
	 for (i = 0;i<strArray.length;i++) 
	 {
		 if ( i < strArray.length && i > 0) 
		 {
			 strTypeList += "|";
		 }
			strTypeList += "."+strArray[i];
	 }
	 exp="("+strTypeList+")$"; 
	 var regex = new RegExp(exp);
	 if(!regex.test(fld.value)) 
	 {
		 return false; 
	 }
	 return true; 
 }
	 
 function LTrim(str)
 {
	 if(str==null)
	{
		return str;
	}
	for(var i=0;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i++);
	return str.substring(i,str.length);
 }
 
 function RTrim(str)
 {
	 if(str==null)
	{
		return str;
	}
	for(var i=str.length-1;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i--);
	return str.substring(0,i+1);
 }
 
 function Trim(str)
 {
	 return LTrim(RTrim(str));
 }
 
 function stripHTMLTags(str) 
 {
	 var mystr=""; 
	 var chr=""; 
	 var skip=false; 
	 var skipcancel=false; 
	 for (x=0; x<str.length; x++) 
	 {
		 if (skipcancel==true)
		 {
			 skip=false;
		 } 
		 chr=str.charAt(x); 
		 if (chr=="<")
		 {
			 skip=true;skipcancel=false;
		 } 
		 else if (chr==">" && skip==true)
		 {
			 skipcancel=true;
		 } 
		 if (skip==false) 
		 {
			 mystr=mystr+chr; 
		 }
	 }
	 return mystr; 
 } 
	 
 function isValidTime(strTime) 
 {
	 var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/; 
	 var matchArray = strTime.match(timePat); 
	 if (matchArray == null) 
	 {
		 return false; 
	 }

	 hour = matchArray[1]; 
	 minute = matchArray[2]; 
	 second = matchArray[4]; 

	 if (isBlank(second)) 
	 {
		 second = null; 
	 }
	 
	 if (hour < 0  || hour > 23) 
	 {
		 return false; 
	 }

	 if (minute<0 || minute > 59) 
	 {
		 return false; 
	 }
	 
	 if (second != null && (second < 0 || second > 59)) 
	 { 
		 return false; 
	 }
	 return true; 
 }	 
 
 function isValidNumber(numval) 
 {
	 if (isBlank(numval))
	 {
		 return false;
	 }
	 var myRegExp = new RegExp("^[/+|/-]?[0-9]*[/.]?[0-9]*$"); 
	 return myRegExp.test(numval); 
 }
 
 function isValidNumber(numval) 
 {
	 if (isBlank(numval))
	 {
		 return false;
	 }
	 var myRegExp = new RegExp("^[/+|/-]?[0-9]*[/.]?[0-9]*$"); 
	 return myRegExp.test(numval); 
 }
 
  function isValidInterval(interval) 
 {
	 var strIntervals = new Array("yrs","year","years","mos","month","months","day","days","week","weeks","hrs","hour","hours","mins","min","minutes","secs","sec","second","seconds"); 
	 strArray = interval.split(" "); 
	 
	 // need at least two items 
	 if (strArray.length < 2) 
	 {
		 return false;
	 }
	 
	 // check all pairs of values to be valid intervals (e.g 2 hrs 5 mins) 
	 for (i = 0;i<strArray.length-1;i=i+2) 
	 {
		 if (isNaN(strArray[i]))
		 {
			 return false;
		 }
		 found=false; 
		 for (var x = 0;x<strIntervals.length;x++) 
		 {
			 if (strArray[i+1].toUpperCase() == strIntervals[x].toUpperCase()) 
			 {
				 found=true;
			 }
		 }
		 if (!found)
		 {
			 return false;
		 }
	 }
	 return true; 
	 }
 
/******************** toolline common functions ***********************/
function moveto(obj1, chars, obj2,e)
{
	if(obj1.value.length == chars )
		obj2.focus();
}

function showContent(id)
{
	
    if(document.getElementById('content'+id))	
	{
		document.getElementById('content'+id).style.display = '';
	}	

	for(i=1;i<=11;i++)
	{
		if ( i != id)
		{
			if(document.getElementById('content'+i))	
			{				
				document.getElementById('content'+i).style.display = 'none';			
			}
		}
	}	
}

function hideAllContent()
{	 
	for(i=1;i<=11;i++)
	{
		if(document.getElementById('content'+i))	
		{				
			document.getElementById('content'+i).style.display = 'none';			
		}
	}	
}


function MM_Open_Window(page) 
{
  
  if(page=="add_to_cart.php") {
    var height = "100";
  } else {
    var height = "280";
  }
  params = "top=300,left=400,width=500,height="+height+",resizable=0";
  var mywnd = window.open(page,'wnd',params);
}
 
 
function validateLogin() 
{
    
    var objEmail = document.getElementById('txtEmail');
    var objPassword = document.getElementById('txtPassword');
    var sub = true;
    
    if(objEmail.value=="" || objEmail.value==null) {
      alert("Email address can not be blank");
      objEmail.focus();
      sub = false;
      return false;      
    }
    
    if(sub) {    
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var email = objEmail.value;
       if(!email.match(emailRegEx)){
          alert("Please enter valid email address");
          objEmail.focus();
          sub = false;
          return false;             
       }
   }        
    
    if(objPassword.value=="" || objPassword.value==null) {
      alert("Password can not be blank");
      objPassword.focus();
      sub = false;
      return false;            
    }
    
    if(sub) {
      document.frmUserLogin.submit();	
    } else {
       return sub;
    }
    
}

//Function to change the view of product list
function chageProductList(id) 
{ 
    var frmObj = document.frmProductList;
    if(id!=0) {
        frmObj.no_of_prd.value = id;
        frmObj.submit();
    }
} 

function changeCategorytList(id)
{
	var frmObj = document.frmCategoryList;
    if(id!=0) {
        frmObj.no_of_cat.value = id;
        frmObj.submit();
    }
}

//Function to check valid price
function validatePrice(price)
{
	if(parseInt(Math.ceil(price)) != 0)
	{
		var regex=/^[0-9]+\.{0,1}[0-9]{0,2}$/;	
		var mat = regex.test(price);		
		if(!mat)
		{			
			return 0;
		}
	}
	return 1;
}

//Function to hide user message div on the pages
function hideUserMessage(id)
{
	if (document.getElementById(id))
	{
		setTimeout("document.getElementById('"+id+"').innerHTML = '';document.getElementById('"+id+"').style.display = 'none';",8000);
		
	}
}


// Function to display the product details
function displayProduct(win_title, $product_id,refreshMiniCart)
{
		var Xwidth  = 650;
		var Yheight = 450;
			
		var divPos = this._getDivCenterPosition(Xwidth, Yheight);
		var topPos  = divPos[0];
		var leftPos = divPos[1];
				
		var win = new Window({className: "spread", title: 'Toolline', 
							  top:topPos,left:leftPos, width:Xwidth, height:Yheight, 
							  url: "index.php?file=product_detail&prodID="+$product_id+"&rmc="+refreshMiniCart, showEffectOptions: {duration:0.5}})
		win.show();                                            
}

function displayFreeProduct(win_title, $product_id)
{
		var Xwidth  = 650;
		var Yheight = 450;
			
		var divPos = this._getDivCenterPosition(Xwidth, Yheight);
		var topPos  = divPos[0];
		var leftPos = divPos[1];
				
		var win = new Window({className: "spread", title: 'Toolline', 
							  top:topPos,left:leftPos, width:Xwidth, height:Yheight, 
							  url: "index.php?file=product_detail&prodID="+$product_id+"&freeProd=1", showEffectOptions: {duration:0.5}})
		win.show();                                            
}

function cartAlert()
{
	var win = new Window({className: "spread", title: "Cart",
						  width:350, height:40, zIndex: 100, resizable: false, 
						  draggable:false, wiredDrag: false, minimizable:false, maximizable:false,
						  showEffectOptions: {duration:0.2}
						  })

	win.getContent().innerHTML= "<div style='padding:10px' align='center'><span style='font-size:12px;font-family:verdana,arial'><b>Product added to your cart.</b></span></div>"
	win.showCenter(); 
	
}

function _getDivCenterPosition(Xwidth, Yheight)
{	
		// First, determine how much the visitor has scrolled
		var scrolledX, scrolledY;
		if( self.pageYOffset ) 
		{
			scrolledX = self.pageXOffset;
			scrolledY = self.pageYOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) 
		{
			scrolledX = document.documentElement.scrollLeft;
			scrolledY = document.documentElement.scrollTop;
		} else if( document.body ) 
		{
			scrolledX = document.body.scrollLeft;
			scrolledY = document.body.scrollTop;
		}
		
		// Next, determine the coordinates of the center of browser's window
		
		var centerX, centerY;
		if( self.innerHeight ) 
		{
			centerX = self.innerWidth;
			centerY = self.innerHeight;
		} 
		else if( document.documentElement && document.documentElement.clientHeight ) 
		{
			centerX = document.documentElement.clientWidth;
			centerY = document.documentElement.clientHeight;
		} else if( document.body ) 
		{
			centerX = document.body.clientWidth;
			centerY = document.body.clientHeight;
		}
		
		// Xwidth is the width of the div, Yheight is the height of the
		// div passed as arguments to the function:
		var leftOffset = scrolledX + (centerX - Xwidth) / 2;
		var topOffset = scrolledY + (centerY - Yheight) / 2;		
		
		return [topOffset,leftOffset];
}

function searchProduct()
{
	if( isBlank(document.getElementById('search_keyword').value))
	{
		alert('Please enter the search keyword');
		document.getElementById('search_keyword').focus();
		return false;		
	}
	document.frmSearch.submit();
}

function searchProductCategory()
{
	/*if( isBlank(document.getElementById('search_cat_keyword').value))	
	{
		alert('Please enter the search keyword');
		document.getElementById('search_cat_keyword').focus();
		return false;		
	}*/
	if( isBlank(document.getElementById('selCategory').value))	
	{
		alert('Please select category');
		document.getElementById('selCategory').focus();
		return false;		
	}
	else
	{
		if(document.getElementById('advance_search'))
		{
				resetAdvanceSearch();
				Effect.Fade('advance_search');
//				changeAdvanceSearchArrow();
		}
		document.getElementById('productcat_search_action').value = 'category';  
		document.frmSearchProductCategory.submit();
	}
	
}

function changePaging(frm,val)
{
	if ( document.getElementById("paging") )
		document.getElementById("paging").value=val;
	frm.submit();
}

/**  adding to cart message **/
var strReturn ;
function addingItemToCartPopUp()
{  
	strReturn = Dialog.info("Adding To Cart", {width:250, height:40, opacity:0.7, showProgress: false}); 
}
                 
function closeAddingItemToCartPopUp()
{
	Dialog.closeInfo();	
}
/**  end adding to cart message **/  


/**  item added to cart **/  
function messagePopUp(in_str) {
    openInfoDialog();          
}                    

var timeout; 
function openInfoDialog() 
{ 
	if(strReturn)
		Dialog.closeInfo();
		
	strReturn = Dialog.info("Item Added To Cart", {width:250, height:40, opacity:0.9, showProgress: false}); 	
	
	timeout=3;
	setTimeout(infoTimeout, 700) 
} 


/**  card updated **/ 
function updatePopUp()
{
	strReturn = Dialog.info("Cart Updated", {width:250, height:40,  opacity:0.9, showProgress: false}); 		
	timeout=3;
	setTimeout(infoTimeout, 700) 
}
  
function infoTimeout() 
{ 
	timeout--; 
	if (timeout <= 0) 
	{ 
		Dialog.closeInfo();
	} 
	else
		setTimeout(infoTimeout, 700); 
}
/** end item added to cart, cart updated **/ 

function showProductByManufacturer(manufacturerVal)
{
	document.getElementById('search_category').value = '';
	document.getElementById('search_manufacturer').value = manufacturerVal;
	document.frmProductListByManfCat.submit();
}

function showProductByCategory(categoryVal)
{
	document.getElementById('search_manufacturer').value = '';
	document.getElementById('search_category').value = categoryVal;
	document.frmProductListByManfCat.submit();
}


function advanceSearch()
{	
	if(document.getElementById('selCategory') )
		document.getElementById('selCategory').value='';	
		
	if(document.getElementById('search_cat_keyword') )
		document.getElementById('search_cat_keyword').value='';	
	
	document.getElementById('hdnAction').value='advance_search';	
    document.getElementById('productcat_search_action').value = '';     
}

function showHideAdvanceSearch()
{
	if(document.getElementById('advance_search') )
	{
		Effect.toggle('advance_search', 'blind');
	}
	changeAdvanceSearchArrow();
}

function changeAdvanceSearchArrow()
{
	if(document.getElementById('advImage'))
	{
		str = document.getElementById('advImage').src;
		str = str.split("/");
    	len = str.length;
	    str = str[len-1];
		
		if(str == 'double_right_arrow.gif')
		{
			document.getElementById('advImage').src = 'images/double_down_arrow.gif';
		}
		else
		{
			document.getElementById('advImage').src = 'images/double_right_arrow.gif';
		}
	}	
}
function resetAdvanceSearch()
{
	if(document.getElementById('adv_search_keyword'))	
		document.getElementById('adv_search_keyword').value = '';
	
	if(document.getElementById('phrase_typeAll') )
		document.getElementById('phrase_typeAll').checked = true;
		
	if(document.getElementById('phrase_typeAll') )
		document.getElementById('phrase_typeAll').checked = true;
		
	if(document.getElementById('adv_prodTitle') )
		document.getElementById('adv_prodTitle').checked = true;
		
	if(document.getElementById('adv_prodCode') )
		document.getElementById('adv_prodCode').checked = true;
		
	if(document.getElementById('adv_prodDesc') )
		document.getElementById('adv_prodDesc').checked = true;
		
	if(document.getElementById('adv_prodMan') )
		document.getElementById('adv_prodMan').checked = true;	
		
	if(document.getElementById('adv_categoryID') )
		document.getElementById('adv_categoryID').value = '';
		
	if(document.getElementById('adv_manufacturerID') )
		document.getElementById('adv_manufacturerID').value = '';
		
	if(document.getElementById('adv_price_from') )
		document.getElementById('adv_price_from').value = '';
		
	if(document.getElementById('adv_price_to') )
		document.getElementById('adv_price_to').value = '';	
		
	if(document.getElementById('hdnAction') )
		document.getElementById('hdnAction').value = '';	
        
    document.getElementById('advImage').src = 'images/double_right_arrow.gif';       
}


<!---- trial -->
var currentMenuID = '';
var prevMenuID = ''

/** function to show all the sub category **/
function ShowSubMenu(subMenuID)
{
	if(document.getElementById(subMenuID) )
	{	
		document.getElementById(subMenuID).style.display ='';
	}	
}

/** function to hide all the sub category **/
function hideSubMenu(subMenuID)
{		
	if(prevMenuID != '')
	{
		if(document.getElementById(prevMenuID) )
			document.getElementById(prevMenuID).style.display ='none';
	}	
	prevMenuID = subMenuID;
}

/** function to hide the other main category (level 1). We can create an array of all sub menu when the page loads in html**/
function hideOtherMainMenu(categoryName)
{
	hideSubMenu(prevMenuID);	
	prevMenuID = '';
	
	if(categoryName != '')
	{
		for (arrCategoryKey in arrMenuDivIds)
  		{
			if(arrCategoryKey != categoryName)
			{
				if(document.getElementById(arrCategoryKey))
					document.getElementById(arrCategoryKey).style.display = 'none';
			}
		}
	}	
}

function hideSubMenuLevel2(categoryName)
{
	hideSubMenu(prevMenuID);	
	prevMenuID = '';
	
	if(categoryName != '')
	{
		for (arrCategoryKey in arrMenuDivLev2)
  		{
			if(arrCategoryKey != categoryName)
			{
				if(document.getElementById(arrCategoryKey))
					document.getElementById(arrCategoryKey).style.display = 'none';
			}
		}
	}	
}


function showHideUSStates(country, stateElementID)
{
       
    if(country == 'United States')
    {
        if(document.getElementById('spanUSProvince'))
           document.getElementById('spanUSProvince').style.display = ''; 
           
        if(document.getElementById('spanOtherProvince'))
           document.getElementById('spanOtherProvince').style.display = 'none';    
    }
    else
    {
         if(document.getElementById('spanUSProvince'))
           document.getElementById('spanUSProvince').style.display = 'none'; 
           
        if(document.getElementById('spanOtherProvince'))
           document.getElementById('spanOtherProvince').style.display = '';
    }
}

function showHideUSStates(country, stateElementID,shippping)
{
   if(shippping == 1)     
   {
      usSpanID    = 'spanUSProvince_shipping';
      otherSpanID = 'spanOtherProvince_shipping';
   } 
   else
   {  
      usSpanID    = 'spanUSProvince';
      otherSpanID = 'spanOtherProvince';
   }
   
   if(country == 'United States')
    {
        if(document.getElementById(usSpanID))
           document.getElementById(usSpanID).style.display = ''; 
           
        if(document.getElementById(otherSpanID))
           document.getElementById(otherSpanID).style.display = 'none';    
    }
    else
    {
         if(document.getElementById(usSpanID))
           document.getElementById(usSpanID).style.display = 'none'; 
           
        if(document.getElementById(otherSpanID))
           document.getElementById(otherSpanID).style.display = '';
    }
}

function showHideUSPhone(country, shippping)
{
   if(shippping == 1)     
   {
      usSpanID    = 'spanUSPhone_shipping';
      otherSpanID = 'spanOtherPhone_shipping';
	  
	  mobileUSSpanID 	= 'spanUSMobile_shipping';
	  mobileOtherSpanID = 'spanOtherMobile_shipping';
   } 
   else
   {  
      usSpanID    = 'spanUSPhone';
      otherSpanID = 'spanOtherPhone';
	  
	  mobileUSSpanID 	= 'spanUSMobile';
	  mobileOtherSpanID = 'spanOtherMobile';
   }
   
   if(country == 'United States')
    {
        if(document.getElementById(usSpanID))
           document.getElementById(usSpanID).style.display = ''; 
           
        if(document.getElementById(otherSpanID))
           document.getElementById(otherSpanID).style.display = 'none'; 
		   
		
		 if(document.getElementById(mobileUSSpanID))
           document.getElementById(mobileUSSpanID).style.display = ''; 
           
        if(document.getElementById(mobileOtherSpanID))
           document.getElementById(mobileOtherSpanID).style.display = 'none'; 
		   
    }
    else
    {
         if(document.getElementById(usSpanID))
           document.getElementById(usSpanID).style.display = 'none'; 
           
        if(document.getElementById(otherSpanID))
           document.getElementById(otherSpanID).style.display = '';
		   
		if(document.getElementById(mobileUSSpanID))
           document.getElementById(mobileUSSpanID).style.display = 'none'; 
           
        if(document.getElementById(mobileOtherSpanID))
           document.getElementById(mobileOtherSpanID).style.display = '';   
    }
}

function isValidUSPhoneFormat(phone_no)
{
	if(Trim(phone_no) != '')
	{
		if(!isValidNumber(phone_no))
		{
			return false;
		}
		if(phone_no.length != 10)
		{
			return false;
		}
	}	
	
	return true;
}



function checkValidInternationalFormat(phone_withoutext)
{
        var checkOK  = "0123456789+";
		var checkStr = phone_withoutext;
		var allValid = true;
		var allNum   = "";
		
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
	
			if(ch == '+' && i !=0)
			{
				return false;
			}
	
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
				if (ch != ",")
					allNum += ch;
		}
		
		if (!allValid)
		{
			return false;
		}
        
        if(phone_withoutext.length < 10)
        { 
            return false;
        }
    
    return true;
}
   
function setFlowerTab(value)
{
	document.cookie = "flowertabs="+value+";path=/" //cookie value is domain wide (path=/)
}

function loadPage()
{
	location.href = SITE_PATH+'index.php?file=storefront';
}	

function dealerLogin()
{
	if ( isBlank( Trim(document.getElementById('user_name').value) ) )
	{
		alert('Please enter email address');
		document.getElementById('user_name').focus();
		return false;
	}
	else
	{
		if ( ! isValidEmail(document.getElementById('user_name').value) )
		{
			alert('Please enter a valid email address');
			document.getElementById('user_name').focus();
			return false;
		}	
	}
	
	
	if ( isBlank( Trim(document.getElementById('user_password').value) ) )
	{
		alert('Please enter password');
		document.getElementById('user_password').focus();
		return false;
	}
	
	document.getElementById('hdnDealerAction').value = 'dealer_login';	
}

function getScreenSize ()
{
	if( document.body ) 
	{
		centerX = document.body.clientWidth;
		centerY = document.body.clientHeight;
	}
		
	document.getElementById('overlay').style.width=centerX+"px" //set up veil over page
	document.getElementById('overlay').style.height=centerY+"px" //set up veil over page
	document.getElementById('overlay').style.left=0 //Position veil over page
	document.getElementById('overlay').style.top=0 //Position veil over page
}


/************************* toolline common ajax functions ********************/
function callAJAX(URL,params,OnsuccessFunction, asycn ) 
 {
   var ajax = new Ajax.Request(
     URL , {     
     method: 'post' ,
     postBody:  params ,
     asynchronous: true , 
     onSuccess: eval(OnsuccessFunction),
     on500: renderError
     }    
   );    
 } 
 
 
function callAJAX_async(URL,params,OnsuccessFunction, asycn ) 
 {
   var ajax = new Ajax.Request(
     URL , {     
     method: 'post' ,
     postBody:  params ,
     asynchronous: false , 
     onSuccess: eval(OnsuccessFunction),
     on500: renderError
     }    
   );    
 } 
 
 function renderError()
 {
   alert('ERROR');
 } 
 
 
 /**************************** ADD ITEM **************************************/
  
 /** Function to add the item in cart **/
 function AddInCart(server_path,prod_id,prod_part_no) 
 { 
    $('shopping_cart_inner').style.display = 'none';
    $('progress_bar1').style.display 	   = '';
	
	addingItemToCartPopUp();
	
    var OnSuccess = "UpdateCartBox";   
    var params 	  = "file=shopping_cart&action=add&pid="+prod_id+"&prod_part_no="+prod_part_no+"&AjaxView=true";    
	
	callAJAX(server_path+'index.php',params,OnSuccess);  
	displayViewCartInHeader(server_path);
 } 
 
 /** Callback function for add to cart **/
 function UpdateCartBox(transport) 
 {
	$('shopping_cart_inner').style.display = '';
    $('progress_bar1').style.display 	   = 'none';
	$('shopping_cart_inner').innerHTML     = transport.responseText;

	setTimeout(messagePopUp,2000);
 }
 
function UpdateCartBox2(transport) 
{
	$('shopping_cart_inner').style.display = '';
    $('progress_bar1').style.display 	   = 'none';
	$('shopping_cart_inner').innerHTML     = transport.responseText;
    updatePopUp('1 item added in cart');
 }
 
 
 function prodAddInCart(server_path,prod_id,prod_part_no,refreshMiniCart)
 {
	var OnSuccess = "prodUpdateCartBox";   
    params = "file=shopping_cart&action=add&pid="+prod_id+"&prod_part_no="+prod_part_no+"&AjaxView=true";    

	addingItemToCartPopUp();
	
	if(refreshMiniCart == 1) 
	{
		callAJAX(server_path+'index.php',params);   
		parent.window.refreshMiniCart(server_path);		
	}
	else
	{		
		callAJAX(server_path+'index.php',params,OnSuccess);   	
		displayViewCartInHeader(server_path);	
	}
	
	setTimeout(messagePopUp,2000);
 }
 
 /*** for the add to cart in popup page **/ 
 function prodAddInCart2(server_path,prod_id,prod_part_no,refreshMiniCart)
 {
    var OnSuccess = "prodUpdateCartBox";   
    params = "file=shopping_cart&action=add&pid="+prod_id+"&prod_part_no="+prod_part_no+"&AjaxView=true";    

    addingItemToCartPopUp();      
     
    if(refreshMiniCart == 1) 
    {
        callAJAX_async(server_path+'index.php',params);   
        window.opener.refreshMiniCart2(server_path);        
    }
    else
    {        
        callAJAX(server_path+'index.php',params,OnSuccess);       
        displayViewCartInHeader(server_path);    
    }
    
    setTimeout(messagePopUp,2000);
 }
 
 function refreshMiniCart2(server_path) 
 {   
    $('shopping_cart_inner').style.display = 'none';
    $('progress_bar1').style.display = '';
    var OnSuccess = "UpdateCartBox2";   
    params = "file=cart&action=reloadMiniCart&AjaxView=true";
    callAJAX_async(server_path+'index.php',params,OnSuccess);
    displayViewCartInHeader(server_path);    
 }
 /*** end of for the add to cart in popup page **/    
 
 function prodUpdateCartBox(transport) 
 {  
    messagePopUp();	
 }
 
 /**************************** DELETE ITEM **************************************/
 
 /** function to delete the product in the cart **/
 function deleteItemInCart(server_path,prod_id,prod_part_no) { 
   // $('viewcart_inner').style.display = 'none';
    $('progress_bar1').style.display = '';
    var OnSuccess = "updateCartView";   
    params = "file=cart&action=del&pid="+prod_id+"&AjaxView=true";
    callAJAX(server_path+'index.php',params,OnSuccess);  
	refreshMiniCart(server_path);
   
 } 
 
  /** Callback function to delete item in cart **/
 function updateCartView(transport)
 {
	//$('viewcart_inner').style.display = '';
    $('progress_bar1').style.display = 'none';
    $('viewcart_inner').innerHTML = transport.responseText; 
	
 }
 
 /**************************** UPDATE ITEM **************************************/
  
 function updateCartItems(server_path)
 {
	
	var len = document.frmCart.item_code.length;
	var params = "file=cart&action=update";
	var OnSuccess = "updateCartView";   
	if(len) 
	{
		for (i=0;i<len;i++) 
		{
			var p_code = document.frmCart.item_code[i];		          
			var quan = eval("document.frmCart.quantity"+p_code.value);			
			params = params+"&pcode"+i+"="+p_code.value+"&quant"+p_code.value+"="+quan.value;
		}
	}
	else 
	{
		len = 1;	
		i = 0;
		var p_code = document.frmCart.item_code;
		var quan = eval("document.frmCart.quantity"+p_code.value);
		params = params+"&pcode"+i+"="+p_code.value+"&quant"+p_code.value+"="+quan.value;
	}
	params = params + "&len="+len;
 	callAJAX(server_path+'index.php',params,OnSuccess); 
	refreshMiniCart(server_path);
	
 }
 
 /********************** REFRRESH MINI CART ****************************************/
 
 
 /** function to delete the product in the cart **/
 function refreshMiniCart(server_path) 
 { 
  
    $('shopping_cart_inner').style.display = 'none';
    $('progress_bar1').style.display = '';
    var OnSuccess = "UpdateCartBox2";   
    params = "file=cart&action=reloadMiniCart&AjaxView=true";
    callAJAX(server_path+'index.php',params,OnSuccess);
	displayViewCartInHeader(server_path);	
 }             
 
 function displayViewCartInHeader(server_path)
 {	
	var OnSuccess = "reloadViewCartInHeader";   
	params = "file=cart&action=cartItems&AjaxView=true";
    callAJAX(server_path+'index.php',params,OnSuccess);
 }
 
 function reloadViewCartInHeader(transport)
 {
	if(transport.responseText.indexOf('success')  > 0)
    {		
		if(document.getElementById('cart_icon'))
		   	document.getElementById('cart_icon').style.display = '';
	}
	else
	{
		if(document.getElementById('cart_icon'))	
			document.getElementById('cart_icon').style.display = 'none';
	}	
 }
 
 function getSubcategories(server_path,categoryID,curlevel, nextlevel)
 {
	var OnSuccess = "Update";   
	
	if(categoryID != '')
	{
	 	if($('cat_level_'+nextlevel))		
			$('cat_level_'+nextlevel).innerHTML = '<img src="images/loading3.gif">';
		
		params = "file=category&hdnAction=ajaxCategories&AjaxView=true&catid="+categoryID+"&clevel="+curlevel+"&nextlevel="+nextlevel;
		callAJAX_async(server_path+'index.php',params, function(transport)
														 {	
														 	if($('cat_level_'+nextlevel))
																$('cat_level_'+nextlevel).innerHTML = transport.responseText; 		 
														 } );
	}
 }

/*********************** Limit Textarea content ***********/
maxL=150;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}
/*********************** Limit Textarea content ***********/
function CountLeft(field, count, max) {
	
 // if the length of the string in the input field is greater than the max value, trim it 
 if (field.value.length > max)
	 field.value = field.value.substring(0, max);
 else
 {
	 // calculate the remaining characters  
	 count.value = max - field.value.length;
	 
	 if(bName == "Netscape")
	 {	
		 document.getElementById('myCounter').textContent = count.value;
	 }
	 else
	 {
		 document.getElementById('myCounter').innerText = count.value;
	 }
 }
}

function detectSearchEnter(e,funname)
{ 
    
  var keynum;
  var returnVal;
  if(window.event) // IE
  {
     keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
     keynum = e.which;
  }

  if(keynum == 13)
  {
    returnVal = funname(); 
  }
  
  return returnVal;
}

function openProductDetailWindow(strUrl)
{
   document.cookie = 'lastVisitedPage = productlist; path=/; domain=toolline.com';   

   window.open(strUrl,"_blank","height=500,width=600,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no");
   
   return false;
}

function openStoreFrontProductDetailWindow(strUrl)
{ 
  document.cookie = 'lastVisitedPage = storefront; path=/; domain=toolline.com'; 
 
  window.open(strUrl,"_blank","height=500,width=600,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no");
}


/******************************** cancel order ***********************************************/
function cancelOrder()
{ 
   Dialog.confirm({url: "index.php?file=cancelorder", options: {method: 'get'}},
                  {className:"darkspread", width:520,  
                   title: "Cancel Order",   
                   okLabel: "Send", cancelLabel: "Cancel", 
                   onOk:function(win)
                   { 
                     if (isBlank($('cancel_comment').value)) {
                        $('cancelorder_error_msg').innerHTML='Please enter your feedback'; 
                        $('cancelorder_error_msg').show(); 
                        Windows.focusedWindow.updateHeight(); 
                     } else {
                         
                         saveCancelOrderMessage();
                     }
                    
                    // new Effect.Shake(Windows.focusedWindow.getId()); 
                    return false;
                   }
                 }
    ); 
}

function saveCancelOrderMessage()
{    
    params = 'file=cancelorder&ac=email&cancel_comment='+escape($('cancel_comment').value);
    
    cancelordermsg = '<p align="center">Your order has not been placed. <br><br> Please call us at 1-800-303-1223 for any assistance. </p>';   
   
    // update the title
    Windows.focusedWindow.setTitle('Saving your feedback');  
    
    // hide the message and text area and show processing area                
    $('cancelorder_feedback').hide();
    $('cancelorder_error_msg').hide();
    
    // $('cancelorder_user_msg').innerHTML = '<p align="center">Saving your message.</p>';
    $('cancelorder_user_msg').innerHTML = '<img src="images/cancel_order-loader.gif">';
    $('cancelorder_user_msg').show();
                             
    // hide the send and cancel button                                                                         
    document.getElementsByClassName('darkspread_buttons')[0].style.display= 'none';  
                                                      
    // update the size of the window
    Windows.focusedWindow.setSize(520, 100);   
       
    new Ajax.Request(SITE_PATH+'index.php', {     
                            method: 'post' ,
                            postBody: params,
                            asynchronous: true , 
                            onSuccess: function (response) { 
                                
                                if(response.responseText.indexOf('success') > 0) {                                    
                                    // update the title
                                    Windows.focusedWindow.setTitle('Thank You!');
                                
                                    // show the successful message
                                    $('cancelorder_feedback').hide();
                                    $('cancelorder_error_msg').hide();  
                                
                                    $('cancelorder_user_msg').innerHTML = cancelordermsg;
                                    $('cancelorder_user_msg').show(); 
                               
                                    // update the size of the window 
                                    Windows.focusedWindow.setSize(520, 90);    
                                }
                                
                                setTimeout(closeDialogBox, 3000); 
                                   
                            },
                            on500: renderError
                         }    
        );   
}

function closeDialogBox()
{
    Dialog.cancelCallback();
    setTimeout("window.location = 'index.php?file=cart'", 2000); 
}
/******************************** end of cancel order ***********************************************/ 

/******************************** email this link ***********************************************/
function shareThisLink(productID, pageType)
{ 
   if (pageType == 'product') {
       divTitle = 'Share This Product';
   }
   else {
       divTitle = 'Share This Page';  
   }
   
   Dialog.confirm({url: SITE_PATH+"index.php?file=share_link", options: {method: 'get'}},
                  {className:"darkspread", width:530, height:380,  
                   title: divTitle,   
                   okLabel: "Send", cancelLabel: "Cancel", 
                   onOk:function(win)            
                   { 
                        if (isBlank($('sender_name').value)) {
                            $('sendlink_error_msg').innerHTML='Please enter your name'; 
                            $('sendlink_error_msg').show();                                                       
                            Windows.focusedWindow.updateHeight();   
                        }    
                        else if (isBlank($('receiver_email').value)) {    
                            $('sendlink_error_msg').innerHTML='Please enter recipient\'s email address';
                            $('sendlink_error_msg').show();                                                       
                            Windows.focusedWindow.updateHeight();   
                        }
                        else if (!isValidEmail($('receiver_email').value)) {
                            $('sendlink_error_msg').innerHTML='Please enter valid recipient\'s email address';
                            $('sendlink_error_msg').show();                                                       
                            Windows.focusedWindow.updateHeight();   
                        }   
                        else {                                 
                         sendLinkEmail(productID, pageType);
                        }                                         
                     
                        return false;
                   }
                 }    
         ); 
}

function sendLinkEmail(productID, pageType)
{    
    // generate the post variable strings
    params = 'file=share_link&ac=email&sender='+escape($('sender_name').value)+'&receiver='+$('receiver_email').value;
    params += '&message='+escape($('message').value)+"&productID="+productID+"&pageType="+pageType;
    
    if (!isBlank($('searchProductURL').value)) {
        params += '&currentPageURL='+escape($('searchProductURL').value); 
    } else {
        params += '&currentPageURL='+escape($('currentPageURL').value); 
    }           
    
    cancelordermsg = '<p align="center">Email sent successfully. <br><br> Please call us at 1-800-303-1223 for any assistance. </p>';   
   
    // update the title
    Windows.focusedWindow.setTitle('Sending Email');  
    
    // hide the message and text area and show processing area                
    $('sendlink_section').hide();
    $('sendlink_error_msg').hide();
        
    $('sendlink_user_msg').innerHTML = '<img src="images/cancel_order-loader.gif">';
    $('sendlink_user_msg').show();
                             
    // hide the send and cancel button                                                                         
    document.getElementsByClassName('darkspread_buttons')[0].style.display= 'none';  
                                                      
    // update the size of the window
    Windows.focusedWindow.setSize(520, 100);   
       
    new Ajax.Request(SITE_PATH+'index.php', {     
                            method: 'post' ,
                            postBody: params,
                            asynchronous: true , 
                            onSuccess: function (response) { 
                                
                                if(response.responseText.indexOf('success') > 0) {                                    
                                    // update the title
                                    Windows.focusedWindow.setTitle('Thank You!');
                                
                                    // show the successful message
                                    $('sendlink_section').hide();
                                    $('sendlink_error_msg').hide();  
                                
                                    $('sendlink_user_msg').innerHTML = cancelordermsg;
                                    $('sendlink_user_msg').show(); 
                               
                                    // update the size of the window 
                                    Windows.focusedWindow.setSize(520, 100);    
                                }                                
                                setTimeout(closeShareDialogBox, 3000); 
                                   
                            },
                            on500: renderError
                         }    
        );   
}

function closeShareDialogBox()
{
    Dialog.cancelCallback();    
}
/******************************** end of email this link ***********************************************/