/* Top Common Menu script */
var arr_url = tmp_rootpath.split('/');
// Temporarily commented due to 'navbar' is not available
if(arr_url[4] != 'registration')
{
	sfHover = function() 
	{ 
		var sfEls = document.getElementById("navbar").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) 
		{
			sfEls[i].onmouseover=function() {var list = this.getElementsByTagName("UL")[0];if(list){list.style.left  = "auto";}};
			sfEls[i].onmouseout=function() {var list = this.getElementsByTagName("UL")[0];if(list){list.style.left  = "-999em";}}
		}
	};
	if (window.attachEvent){window.attachEvent("onload", sfHover);}if (window.addEventListener){window.addEventListener("load", sfHover, false);};
}

function RedirectPage(product_link)
{
	if( product_link )
	{
		window.location = product_link;
	}
}

function openWin1(url)
{
	var j=window.open(url,"jj","left=20, top=20, width=550,height=600,scrollbars=1") 
}

function openWin2(url)
{
	var j=window.open(url,"jj","left=20, top=20, width=700,height=570,scrollbars=1") 
}

function openWin3(url)
{
	var j=window.open(url,"jj","left=20, top=20, width=500,height=300,scrollbars=1") 
}

function openWinlarge(url)
{
	var j=window.open(url,"jj","left=20, top=20, width=500,height=410,scrollbars=1") 
}



function openWin4(url)
{
var j=window.open(url,"jj","left=20, top=20, width=400,height=180,scrollbars=1") 
}
function openWin5(url)
{
var j=window.open(url,"jj","left=20, top=20, width=550,height=500,scrollbars=1") 
}

function openprint(url)
{
var j=window.open(url,"jj","left=20, top=20, width=900,height=900,scrollbars=1") 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function changebg(elementId)
{
	fmobj	=	document.form1;
	re = /bigform12/gi;
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];	
		if(e!=elementId)
			e.className = e.className.replace(re, '');
		else
			elementId.className += elementId.className+' bigform12';	
	}
	
	if(elementId.value.length>0)
		elementId.className += elementId.className+' bigform12';
}
function visibleMoreCat_presc(){
	if(document.getElementById("set_more_link").value == 0){
		document.getElementById("set_more_link").value = 1;
		document.getElementById("more_cat").style.display = "";
		document.getElementById("pres_dont").style.display ="none"
		
	}else{
		document.getElementById("set_more_link").value = 0;		
		document.getElementById("pres_dont").style.display =""
		document.getElementById("more_cat").style.display = "none";
	}
}
function visibleMoreCat(){
	
	if(document.getElementById("set_more_link").value == 0){
		document.getElementById("set_more_link").value = 1;
		document.getElementById("more_cat").style.display = "";
		document.getElementById("brandList").style.display = "none";
		document.getElementById("viewBrandLink").style.display = "none";
		document.getElementById("viewAllBrandLink").style.display = "";
		document.getElementById("backId").style.display = "";
		
		
		if(document.getElementById("pres_dont"))
		{
			document.getElementById("pres_dont").style.display = "none";
			document.getElementById("brandList").style.display = "";
			document.getElementById("viewBrandLink").style.display = "";
			document.getElementById("viewAllBrandLink").style.display = "none";
		}
	}else{
		document.getElementById("set_more_link").value = 0;
		document.getElementById("more_cat").style.display = "none";
		document.getElementById("brandList").style.display = "";
		document.getElementById("viewBrandLink").style.display = "";
		document.getElementById("viewAllBrandLink").style.display = "none";
		document.getElementById("backId").style.display = "";
		
		var newurl=document.getElementById("urlId").value+".html#a";
		window.location= newurl;
		
		
		if(document.getElementById("pres_dont"))
		{
			document.getElementById("pres_dont").style.display = "";
			document.getElementById("brandList").style.display = "none";
			document.getElementById("viewBrandLink").style.display = "";
			document.getElementById("viewAllBrandLink").style.display = "none";
		}
	}
}
function paging_submit(form_action,form_name)
{
	theForm = document.getElementById(form_name);
	theForm.action = form_action;
	theForm.submit();
}
function changeView(view_type,form_name) // for view changing
{
	theForm = document.getElementById(form_name);
	theForm.vi.value = view_type;
	theForm.submit();
}
function doPriceSort(sortField,form_name) //for paging script
{ 	
	theForm = document.getElementById(form_name);
	theForm.ps.value = sortField;
	theForm.submit();
}
function filltextbox(i)
{
	var qty = document.getElementById('qty_sel_'+i).value;
	if(isNaN(qty))
	{
		document.getElementById('qty_sel_'+i).style.display = 'none';
		document.getElementById('qty_'+i).style.display = '';
		document.getElementById('qty_'+i).value = '21';
	}
	else
	{
		document.getElementById('qty_'+i).value = qty;
	}
}

function filltextbox_search(i)
{
		
	var qty = document.getElementById('qty_sel_'+i).value;
	if(isNaN(qty))
	{
		document.getElementById('qty_sel_'+i).style.display = 'none';
		document.getElementById('qty_'+i).style.display = '';
		document.getElementById('qty_'+i).value = '21';
		showTotalPrice(i);
	}
	else
	{
		document.getElementById('qty_'+i).value = qty;
		showTotalPrice(i);
	}
}
/* Screen Resolution detection and set the variable for flash and div */
//to set dropdown position
var Left=0;
//alert(screen.width);
if(screen.width == 1088)
{
	image_name = 1024;
	width	   = 600;
	Left = 538;
}	
else if(screen.width == 1152)
{
	image_name = 1024;
	width	   = 600;
	Left = 602;
}	
else if(screen.width == 1280)
{
	image_name = 1200;
	width	   = 864;
	Left = 731;
}	
else if(screen.width >= 1300 && screen.width <= 1399)
{
	image_name = 1400;
	width	   = 1024;
	Left = 800;	
}	
else if(screen.width >= 1400 && screen.width <= 1499)
{
	image_name = 1400;
	width	   = 1024;
	Left = 900;	
}	
else if(screen.width >= 1600 && screen.width <= 1699)
{
	image_name = 1400;
	width	   = 1024;
	Left = 900;		
}	
else if(screen.width >= 1700 && screen.width <= 1799)
{
	image_name = 1400;
	Left = 1000;		
	Left = 1000;		
}	
else
{
	image_name = 1024;
	width	   = 600;
	Left = 473;
}	

/* Text block default change and search functions*/
function alertSize()
{
	var a=new Array();
	var b=0,myHeight=0;
	if(typeof(window.innerWidth)=='number')
	{
		b=window.innerWidth;myHeight=window.innerHeight
	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
	{
		b=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight
	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
	{
		b=document.body.clientWidth;myHeight=document.body.clientHeight
	}
	a[0]=b;a[1]=myHeight;
	return a
}

function clearSearchField(objText)
{
	if(trimAll(objText.value) == "Search by title, author or ISBN")
	{
		objText.value='';
	}
	else if(trimAll(objText.value) == "Enter medicine name here")
	{
		objText.value='';
	}	
	else if(trimAll(objText.value) == "Enter Email Address")
	{
		objText.value='';
	}
	else if(trimAll(objText.value) == "Please Enter Your Name")
	{
		objText.value='';
	}
	else if(trimAll(objText.value) == "Please Enter Your Email")
	{
		objText.value='';
	}
	else if(trimAll(objText.value) == "Please Enter Your Review")
	{
		objText.value='';
	}
	else if(trimAll(objText.value).substr(18,8)=='feedback')
	{
		objText.value=''
	}
	objText.select();
}

function defaultText(objText,TextFor)
{

	if(isWhitespace(objText.value) && TextFor=="")
	{
		objText.value='Search by title, author or ISBN';  	
	}
	else if(isWhitespace(objText.value) && TextFor == 'newsletter')
	{
		objText.value='Enter Email Address';  	
	}
	else if(isWhitespace(objText.value)&&TextFor=='suggestion')
	{
		
		objText.value='Please enter your feedback here, we very much appreciate customer feedback. We may not be able to respond to all comments but we endeavor to reply to all suggestions.'
	}
}

function TopSearch(keyword)
{
	document.getElementById('id_txt_search').value = keyword;
	document.frm_top_search.action = tmp_rootpath+"search_results.php";
	document.frm_top_search.submit();
}

function doSearch(objForm)
{
	if(document.getElementById('txt_search').value == 'Search by title, author or ISBN')
	{
		if(alert("Please enter a title or keyword(s)"))
		{
			objForm.txt_search.value = "";
			objForm.txt_search.focus();
		}
		return false;
	}
	else if( document.getElementById('txt_search').value == '' )
	{
		alert('Please enter a title or keyword(s)');
		objForm.txt_search.value = "";
		objForm.txt_search.focus();
		return false;
	}
	else
	{
		objForm.submit();
	}
}
/* Preload images */
	function MM_preloadImages()
	{
		//v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	MM_preloadImages(""+tmp_rootpath+"images/tabs/home.gif", ""+tmp_rootpath+"images/tabs/home_hover.gif", ""+tmp_rootpath+"images/tabs/browse_genres.gif", ""+tmp_rootpath+"images/tabs/browse_genres_hover.gif", ""+tmp_rootpath+"images/tabs/best_sellers.gif", ""+tmp_rootpath+"images/tabs/best_sellers_hover.gif", ""+tmp_rootpath+"images/tabs/bargain_books.gif", ""+tmp_rootpath+"images/tabs/bargain_books_hover.gif", ""+tmp_rootpath+"images/tabs/coming_soon.gif", ""+tmp_rootpath+"images/tabs/coming_soon_hover.gif",  ""+tmp_rootpath+"images/tabs/New_Releases.gif", ""+tmp_rootpath+"images/tabs/New_Releases_hover.gif", ""+tmp_rootpath+"images/tabs/recommendations.gif", ""+tmp_rootpath+"images/tabs/recommendations_hover.gif", ""+tmp_rootpath+"images/tabs/offers.gif", ""+tmp_rootpath+"images/tabs/offers_hover.gif");

/*
		MM_preloadImages(""+tmp_rootpath+"images/link_home_over.gif",""+tmp_rootpath+"images/link_prescriptions_over.gif",""+tmp_rootpath+"images/link_embarrassing_over.gif",""+tmp_rootpath+"images/link_medicines_over.gif",""+tmp_rootpath+"images/link_sexual_health_over.gif",""+tmp_rootpath+"images/link_health_over.gif",""+tmp_rootpath+"images/link_toiletries_new_over.gif",""+tmp_rootpath+"images/link_vitamins_over.gif",""+tmp_rootpath+"images/link_beauty_over.gif",""+tmp_rootpath+"images/link_for_men_over.gif",""+tmp_rootpath+"images/link_fragrances_over.gif",""+tmp_rootpath+"images/link_offers_new_over.gif",""+tmp_rootpath+"images/Loader.gif", ""+tmp_rootpath+"images/buttons/arrow_down.gif",""+tmp_rootpath+"images/link_baby_over.gif",""+tmp_rootpath+"images/link_electricals_over.gif",""+tmp_rootpath+"images/link_travel_over.gif",""+tmp_rootpath+"images/link_pets_new_over.gif",""+tmp_rootpath+"images/scholl_about.gif",""+tmp_rootpath+"images/scholl_about_over.gif",""+tmp_rootpath+"images/scholl_news_blogs.gif",""+tmp_rootpath+"images/scholl_news_blogs_over.gif",""+tmp_rootpath+"images/scholl_resource.gif",""+tmp_rootpath+"images/scholl_resource_over.gif",""+tmp_rootpath+"images/scholl_reviews.gif",""+tmp_rootpath+"images/scholl_reviews_over.gif",""+tmp_rootpath+"images/scholl_shop.gif",""+tmp_rootpath+"images/scholl_shop_over.gif",""+tmp_rootpath+"images/pop_up_bg.gif",
		
		""+tmp_rootpath+"images/tabs/home.gif", ""+tmp_rootpath+"images/tabs/home_hover.gif", ""+tmp_rootpath+"images/tabs/browse_genres.gif", ""+tmp_rootpath+"images/tabs/browse_genres_hover.gif", ""+tmp_rootpath+"images/tabs/best_sellers.gif", ""+tmp_rootpath+"images/tabs/best_sellers_hover.gif", ""+tmp_rootpath+"images/tabs/bargain_books.gif", ""+tmp_rootpath+"images/tabs/bargain_books_hover.gif", ""+tmp_rootpath+"images/tabs/coming_soon.gif", ""+tmp_rootpath+"images/tabs/coming_soon_hover.gif",  ""+tmp_rootpath+"images/tabs/New_Releases.gif", ""+tmp_rootpath+"images/tabs/New_Releases_hover.gif", ""+tmp_rootpath+"images/tabs/recommendations.gif", ""+tmp_rootpath+"images/tabs/recommendations_hover.gif", ""+tmp_rootpath+"images/tabs/offers.gif", ""+tmp_rootpath+"images/tabs/offers_hover.gif", ""+tmp_rootpath+"images/tabs/browse_subjects.gif", ""+tmp_rootpath+"images/tabs/browse_subjects_hover.gif",
		""+tmp_rootpath+"images/1.jpg", ""+tmp_rootpath+"images/2.jpg", ""+tmp_rootpath+"images/3.jpg"
		);
*/

function getSelectedFieldValue(field_value)
{
	var ajaxRequest1;  // The variable that makes Ajax possible!
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest1 = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try{
			ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest1.onreadystatechange = function()
	{
		if(ajaxRequest1.readyState == 4)
		{
			document.getElementById("frmSearchItems").innerHTML=""+ajaxRequest1.responseText+"";
			//document.getElementById("result").innerHTML="";
		}
	}
	var url = tmp_rootpath+"get_search_result.php?field_value="+field_value;
	ajaxRequest1.open("GET", url, true);
	ajaxRequest1.send(null); 
}

// START - For Roll over products //
function AjaxMoveProducts(type)
{
	try
	{ 
		// Opera 8.0+, Firefox, Safari
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// Internet Explorer Browsers 
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				// Something went wrong 
				alert("Your browser broke!"); 
				return false; 
			}
		}
	}

	if(type.length > 0)
	{
		var url = "ajax_products2.php";
		var param = "type="+type;
		xmlhttp.open('POST', url, true); 

		/* The Callback function */
		xmlhttp.onreadystatechange = function()
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				var objDetails = xmlhttp.responseText;
				if(objDetails != null)
				{
					document.getElementById('id_prd_list').innerHTML = objDetails;
				}				
			}
		}
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);
		return false;
	}
}
// END - For Roll over products //

function change_view(val, frmName)
{
	var frmObj = document.getElementById(frmName);
	frmObj.hid_view.value = val;
	frmObj.submit();
}
function search_filter(val, frmName)
{
	if (val != "")
	{
		var frmObj = document.getElementById(frmName);
		frmObj.hid_sort.value = val;
		frmObj.submit();
	}
}
function monthFilterForComingSoon(val, frmName)
{	
	var frmObj = document.getElementById(frmName);
	frmObj.hid_CSmonth.value = val;
	frmObj.submit();	
}
function weekFilterForNewRelease(val, frmName)
{
	var frmObj = document.getElementById(frmName);
	frmObj.hid_NRweek.value = val;
	frmObj.submit();	
}
function fnRecPerPage(val, frmName)
{
	if (val != "")
	{
		var frmObj = document.getElementById(frmName);
		frmObj.hid_recPerPage.value = val;
		frmObj.submit();
	}
}


