function show()
{
}

//generate url for sarch

function gotoSearch()
{
	var searchTxt = document.getElementById('search').value;
	if(checkHTMLCode(searchTxt))
	{
		alert('HTML code not allowed!');
		document.getElementById('search').focus();
		document.getElementById('search').select();
		return false;
	}
	if(searchTxt=="")
	{
		alert('Please enter keyword to search');
		document.getElementById('search').focus();
		return false;
	}
	else
	{
		var url = '/search/';
		// replace space with + sign
		searchTxt = searchTxt.replace(' ','+');
		
		url+=searchTxt+'.htm';
		document.search_form.action= escape(url);
		document.search_form.submit();
		//return true;
	}
}


//make number in quantity
function checkNumber(numVal,id)
{

//alert(document.getElementById(id).value);
 if(document.getElementById(id).numVal == '')
  {
	alert("Quantity cant be left blank");
	document.getElementById(id).focus();
	document.getElementById(id).select();
	return false;
  }

if(validateNumeric(numVal) == false)
  {
	alert('Quantity must be in numbers');
	//document.getElementById(id).value = 1;
	document.getElementById(id).focus();
	document.getElementById(id).select();
	return false;
  }
  else
  {
	  return true;
  }
}

//validate number
function validateNumeric( str )
{
	str = trimAll(str);
	return str != "" ? /^\s*\+*\-*\d*\.?\d*\s*$/.test( str ) : false;
	
	//var 
	//var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

	//check for numeric characters
 //	return objRegExp.test(strValue);
	
}

function trimAll( strValue ) {
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}


// validate contact us form
function contactus()
{	

	var cname = document.contact.cname.value ;
	if(checkHTMLCode(cname))
	{
		alert("Oops! HTML Code not allowed...");
		document.contact.cname.focus();
		document.contact.cname.select();
		return false;	
	}
	if ((cname == null)||(cname == "")){
		alert("Please enter your name.");
		document.contact.cname.focus();
		document.contact.cname.select();
		return false;	
	}
	
	var email = document.contact.email.value ;
	if(checkHTMLCode(email))
	{
		alert("Oops! HTML Code not allowed...");
		document.contact.email.focus();
		document.contact.email.select();
		return false;	
	}
	if ((email == null)||(email == "")){
		alert("Please enter your email address.");
		document.contact.email.focus();
		document.contact.email.select();
		return false;	
	}	
	
	if (echeck(email)==false){
		alert("Please enter your valid email address.");
		document.contact.email.focus();
		document.contact.email.select();
		return false;
	}
	if(checkHTMLCode(document.contact.subject.value))
	{
		alert("Oops! HTML Code not allowed...");
		document.contact.sub.focus();
		document.contact.sub.select();
		return false
	}
	if(document.contact.subject.value == 0){
		alert("Please Select Subject.");
		document.contact.subject.focus(); 
		return false;	
	}	
	if(checkHTMLCode(document.contact.ordcode.value))
	{
		alert("Oops! HTML Code not allowed...");
		document.contact.ordcode.focus();
		document.contact.ordcode.select();
		return false
	}
	
   if((document.contact.ordcode.value == "")&& (document.contact.invid.value == "true"))
   {
		alert("Please enter OrderCode. ");
		document.contact.ordcode.focus();
		document.contact.ordcode.select();
		return false;	

   }
	
	if(checkHTMLCode(document.contact.message.value))
	{
		alert("Oops! HTML Code not allowed...");
		document.contact.message.focus();
		document.contact.message.select();
		return false
	}			
	if(document.contact.message.value != ""  ){
		if(document.contact.message.value.length >= 500){
		alert("Only 500 characters are allowed in Message.");
		document.contact.message.focus();
		document.contact.message.select();
		return false;
		}
	}
	
}
function checkHTMLCode(value)
{
	var regex = new RegExp("<[^>]*>")
	return regex.test(value)
}

//check email validation
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	  return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	     return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	     return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
		
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
 	 
 	 return true					
}


//bookmark
function bookmark()
{
	var url=window.location;
	var title = '';
	if (window.sidebar) // firefox
	{ 
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all ) //MSIE
	{ 
		window.external.AddFavorite( url, title);
	}
	else
	{
		alert("Sorry, your browser doesn't support this");
	}
}


//brand detail tabs ajax code here
 var xmlhttp;
 if (window.XMLHttpRequest)
  {
	// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
  }
 else
  {
	 // code for IE6, IE5
	 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

//show brand products by letter
function ShowProducts(brandid,letter)
{
	 
	 //alert(brandid+letter);
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("div_container3").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/product/brandGridView.php";
	url=url+"?brandid="+brandid;
	url=url+"&letter="+letter;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//show category products by letter
function ShowCatProducts(catid,letter)
{	 
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("cat_products").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/category/showcat-products.php";
	url=url+"?catid="+catid;
	url=url+"&letter="+letter;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//show sub category products by letter
function ShowSubCatProducts(subcatid,letter)
{
	 
	 //alert(brandid+letter);
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("subcat_products").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/category/showsubcat-products.php";
	url=url+"?subcatid="+subcatid;
	url=url+"&letter="+letter;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//show brand products by select in search result page
function showBrandProdustcs(searchTxt, view)
{
	 var brandIndex = document.getElementById('brandNames').selectedIndex;
	 var brandValue = document.getElementById('brandNames')[brandIndex].value;
	 //alert(brandValue);
	 //alert(searchTxt+view);
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("div_container1").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/webroot/searchgrid-view.php";
	url=url+"?bname="+brandValue;
	url=url+"&search="+searchTxt;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


//show all brand products
function ShowBDetailGridProducts(brandid)
{	 
	 //alert(brandid+letter);
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("div_container3").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/product/brandGridView.php";
	url=url+"?brandid="+brandid;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//show all category products
function showAllCProducts(catid)
{	 
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("cat_products").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/category/showcat-products.php";
	url=url+"?catid="+catid;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//show all subcategory products
function showAllSCProducts(subcatid)
{	 
	 xmlhttp.onreadystatechange=function()
	 {
		if(xmlhttp.readyState==4)
		{
			//alert(xmlhttp.responseText);
			document.getElementById("subcat_products").innerHTML=xmlhttp.responseText;
		}
	 }
	
	var url="/controllers/category/showsubcat-products.php";
	url=url+"?subcatid="+subcatid;

	//alert(url);
	
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


//end of calling ajax


//show all brand products
/*function getBrandProducts()
{	 
	document.search_cret_form.action='/search-result.html';
	document.search_cret_form.submit();
}*/

//validate popup form fields

function validateMember()
{
	var email = document.form_process.email.value;
	document.getElementById('member').value = 'new';
	if(checkHTMLCode(email))
	{
		alert("Oops! HTML Code not allowed...");
		document.form_process.email.focus();
		document.form_process.email.select();
		return false;	
	}
	if ((email == null)||(email == "")){
		alert("Please enter your email address.");
		document.form_process.email.focus();
		document.form_process.email.select();
		return false;	
	}	
	
	if (echeck(email)==false){
		alert("Please enter your valid email address.");
		document.form_process.email.focus();
		document.form_process.email.select();
		return false;
	}
	if ((form_process.pass.value==null)||(form_process.pass.value=="")){
		alert("Password is a mandatory");
		form_process.pass.focus();
		return false;
	}
	else
	{
		return true;
	}
}
