function trim(str)
{
    if(!str || typeof str != 'string'){
    	str="";
    	return str;
    }
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function isNum(fld){
	return checkfld(fld,"0123456789.");
}
function checkfld(fld,str1){
	str=new String(str1);
	if (fld.value.length==0) return true;
	for (var i=0;i<fld.value.length;i++)
	{
		found=false;
		for (var j=0;j<str.length;j++)
			if((fld.value.substring(i,i+1))==(str.substring(j,j+1)))
			{
				found=true;
				break;
	        }
		if (!found)
		{
			return false;
		}
    }
	return true;
}

function trim1(str)
{
    if(!str || typeof str != 'string'){
    	str="";
    	return str;
    }
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'');
}
function isNum1(fld){
	return checkfld(fld,"0123456789- ");
}

function isEmail(obj)
{	
	str = obj.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
	{
		alert("Please enter a valid E-mail Id");
		obj.focus();
		return false;
	}
	return true;
}
function isNumber(val, msg)
	{
		if(val==""){
			alert('Please enter '+msg);
			return false;
		}
		if(isNaN(val))
		{
			alert('Please enter '+msg +' in numbers');
			return false;
		}
	return true;
	}

function getDepartmentDataNav(url)
{	
	var prodRow = $("#product_list");
	prodRow.html("<div style='float:left;color:#952E6E;font-weight:bold; height:300px; padding-top:150px; font-size:1.4em;text-align:center;'>Refreshing the list of products which meet your criteria.</span><div style='float:left;'><img src='"+sitePath+"sitecontent/images/ajaxupdator.gif' style='margin-left:350px; margin-top:25px;'/>");

	//document.deptForm.selectedItems.value=document.deptForm.selectedItems.value;
	//alert("pagenation::"+document.deptForm.selectedItems.value);
	
	//alert("department"+url);
	$.post(url, { fromAjax:'Y' },
			  function(data){	
					//alert(data);									
					document.getElementById("departmentData").innerHTML = data;					
					
			  }, "html");

}

function getDepartmentData(url,range)
{	
	var prodRow = $("#product_list");
	prodRow.html("<div style='float:left;color:#952E6E;font-weight:bold; height:300px; padding-top:150px; font-size:1.4em;text-align:center;'>Refreshing the list of products which meet your criteria.</span><div style='float:left;'><img src='"+sitePath+"sitecontent/images/ajaxupdator.gif' style='margin-left:350px; margin-top:25px;'/>");
	var url1 = url.replace("/sort/priceh2l", "").replace("/sort/rating", "").replace("/sort/price", "").replace("/sort/rnd", "");
	var mytool_array=url1.split("/");
	var part_num=0;
	var html = "";
	html = html+ "<style>";
	html = html+".refersh{float:left; color:#953735;  width:554px; font-size:13px; padding-top:30px; text-align:center; font-family:'Lucida Grande','Lucida Sans Unicode',Arial,Verdana,sans-serif;}";
	html = html+".refersh p{margin-top:15px;}";
	html = html+".refersh p.para{margin-bottom:15px;}";
	html = html+"ul.rfrsh{margin:0px; padding:0px; margin-bottom:15px; width:145px; list-style-type:none; margin-left:auto; margin-right:auto; border:1px solid #d99694; color:#000}";
	html = html+"ul.rfrsh li{text-align:left; font-size:12px; font-weight:normal;  text-align:center; line-height:18px;}";
	html = html+"ul.rfrsh li.first{margin:0px; padding:0px; background-color:#e6b9b8; color:#000000; font-size:11px; line-height:24px; text-align:center;}";
	html = html+ "</style>";
	if(mytool_array[4].indexOf("?")>0)
	{
		html=html+"<div class='refersh'><p align='center'><img src='"+sitePath+"sitecontent/images/ajaxupdator.gif'/></p><p class='para'>Refreshing the list of "+mytool_array[4].substring(0,mytool_array[4].indexOf("?"))+"<br />to match your criteria.</p>";
	}else
	{
		html=html+"<div class='refersh'><p align='center'><img src='"+sitePath+"sitecontent/images/ajaxupdator.gif'/></p><p class='para'>Refreshing the list of "+mytool_array[4]+"<br />to match your criteria.</p>";
	}
	var flag=0;
	var rCount=0;
	var cat = "";
	while (part_num < mytool_array.length)
	 {
		if (range.indexOf(mytool_array[part_num]) >0)
		{
			if(html.indexOf(mytool_array[part_num])<0)
			{
				if(rCount>0)
				{
					html=html+"</ul>";
					
				}
				html=html+"<ul class='rfrsh'>";
				html =html+"<li  class='first'>"+mytool_array[part_num].replace("h2l","")+"</li>";
				cat = mytool_array[part_num];
				rCount++;
				flag=1;
			}
		}else if(flag==1)
		{
			var attVal_array=mytool_array[part_num].split("+");
			var index=0;
			while (index < attVal_array.length)
			 {
			    if(cat == "Price"){
			       var attributeValue = ""
			       if(attVal_array[index].indexOf("=") > -1){
			           attributeValue = attVal_array[index].replace("=","< &#163;");
			       }
			       if(attVal_array[index].indexOf("_") > -1){
			           attributeValue = attVal_array[index].replace("_","> &#163;");
			       }
			       if(attVal_array[index].indexOf("-") > -1){
			          attributeValue = "&#163;"+attVal_array[index].replace("-"," - &#163;");
			       }
			       if(attributeValue.indexOf("?")<0)
		    		{
			    	   html =html+"<li>"+attributeValue+"</li>";
		    		}else
		    		{
		    			if(attVal_array[index].indexOf("=") > -1){
					           attributeValue = attVal_array[index].replace("=","< &#163;");
					       }
		    			
		    		   html =html+"<li>"+attributeValue.substring(0,attributeValue.indexOf("?"))+"</li>";
		    		}
			       
			      
			    }else{
			    	if(attVal_array[index]!="sort" || attVal_array[index]!="h2l")
			    	{
			    		if(attVal_array[index].indexOf("?")<0)
			    		{
			    			html =html+"<li>"+attVal_array[index].replace("-"," ")+"</li>";
			    		}else
			    		{
			    			html =html+"<li>"+attVal_array[index].replace("-"," ").substring(0,attVal_array[index].indexOf("?"))+"</li>";
			    		}
			    		
			    	}
			    }
				index++;
			 }
			
		}
	  part_num+=1;
	  }
	html=  html+"</ul><p>Click on any of the links on the left<br />to change your criteria</p></div>";
	prodRow.html(html);
	
	//document.deptForm.selectedItems.value=document.deptForm.selectedItems.value;
	//alert("pagenation::"+document.deptForm.selectedItems.value);
	
	//alert("department"+url);
	$.post(url, { fromAjax:'Y' },
			  function(data){	
					//alert(data);									
					document.getElementById("departmentData").innerHTML = data;					
					
			  }, "html");

}



function displayProducts(url,searchTerm){
	//alert("hiProduct");
	$.post(url,
			{	
				searchTerm:searchTerm
			},
			function(data)
			{	//alert(data);
				$("#productdata").fadeIn("slow");
				$("#productdata").html(data);					
			},
	"html" );
}
function displayReviews(url,searchTerm){
	//alert("hi");
	$.post(url,
			{	
				searchTerm:searchTerm
			},
			function(data)
			{
				$("#reviewdata").fadeIn("slow");
				$("#reviewdata").html(data);					
			},
	"html" );
}
function displayHelpTopics(url,searchTerm){
	//alert("hihelp");
	$.post(url,
			{	
				searchTerm:searchTerm
			},
			function(data)
			{	//alert(data);
				$("#helpdata").fadeIn("slow");
				$("#helpdata").html(data);					
			},
	"html" );
}


function removeThickBoxEvents() 
{
       $('.thickbox').each(function(i) {
           $(this).unbind('click');
       });
}

function bindThickBoxEvents() 
{	
    removeThickBoxEvents();
    tb_init('a.thickbox, area.thickbox, input.thickbox');
}

function clear_form_elements(ele) {

	alert("ele "+ele);
    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

function ClearValue(frmName) {

var frmName=frmName;
var myContainer = document.getElementById(frmName);

var options = myContainer.getElementsByTagName('input');

for (i = 0; i < options.length; i++) {

var opt = options[i];

if (opt.type == 'text') {

opt.value = "";

}

else if (opt.type == 'checkbox' || opt.type == 'radio') {

if (opt.checked) {

opt.checked = false;


}
}

}

var options = myContainer.getElementsByTagName('textarea');

for (i = 0; i < options.length; i++) {

var opt = options[i];

opt.value = "";

}

var options = myContainer.getElementsByTagName('select');

for (i = 0; i < options.length; i++) {

var opt = options[i];

opt.selectedIndex = -1;

}

}


