// Global Scripts

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];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function LargeImage() { //v3.0
  var i,j=0,x,a=LargeImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SwapImage() { //v3.0
	agt = navigator.userAgent.toLowerCase();
	is_gecko = (agt.indexOf('gecko') != -1);
//	if (is_gecko){
  		var i,j=0,x,a=SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
//	}
}

function buyitem(){
 var oObj = MM_findObj('buybutton');
 var pObj = MM_findObj('buytext');
 oObj.className= 'hidebuy';
 pObj.className= 'showbuy';
}


function MM_checkbox(id){
  var cObj = MM_findObj(id);
  if(!cObj) return;

	if(cObj.checked == true)  {
	   cObj.checked = false;
	} else {
	   cObj.checked = true;
	}
}

function showTable(id,img)
{
  var oObj = document.getElementById(id)
 
  var iObj = document.getElementById(img)
 
  if(!oObj) return;
     if(oObj.className=='blockTableShow'){
		oObj.className='blockTableHide';
		if(iObj){
		MM_swapImage(img,'','images/buttons/button_arrow_down.gif',1)
		}
	 }else{
		oObj.className='blockTableShow';
		if(iObj){
		MM_swapImage(img,'','images/buttons/button_arrow_up.gif',1)
		}
	}
}

function hideTable(id)
{
  var oObj = document.getElementById(id)
  if(!oObj) return;
     oObj.className= 'blockTableHide';
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function showPopup(id,img)
{
  var oObj = document.getElementById(id);
  var iObj = document.getElementById(img);

  if(!oObj) return;
   
   var styleObject = document.getElementById(id).style;
   
    if(styleObject) {
  //   styleObject.visibility = 'visible';
     if(styleObject.display == "block"){
		styleObject.display = 'none';
		if(iObj){
		MM_swapImage(img,'','images/buttons/button_arrow_down.gif',1);
		}
	 }else{
		styleObject.display = 'block';
		if(iObj){
		MM_swapImage(img,'','images/buttons/button_arrow_up.gif',1);
		}
	}
	//return true;
	}

}

function showcatPopup(id,img)
{
  var oObj = document.getElementById(id);
  var iObj = document.getElementById(img);

  if(!oObj) return;
   
   var styleObject = document.getElementById(id).style;
   
    if(styleObject) {
		styleObject.display = 'block';
	}

}


function hidecatPopup(id,img)
{
  var oObj = document.getElementById(id);
  var iObj = document.getElementById(img);

  if(!oObj) return;
   
   var styleObject = document.getElementById(id).style;
   
    if(styleObject) {
		styleObject.display = 'none';
	}

}



function resize_current(wth,hgt){
if (!wth) return;
if (!hgt) return;
  window.resizeTo(wth, hgt);
}


function toggle_brands(){
	
	  var oObj = MM_findObj('LeftBrand');

if(!oObj) return;
   
 //  var styleObject = document.getElementById('ccountry').style;
   var styleObject = oObj.style;
   
    if(styleObject) {
  //   styleObject.visibility = 'visible';
     if(styleObject.display == "block"){
		styleObject.display = 'none';
	 }else{
		styleObject.display = 'block';
	}
	//return true;
	}

}

	
	
function ccdrop()
{
 // var oObj = document.getElementById('ccountry');
  var oObj = MM_findObj('ccountry');
 
 if(!oObj) return;
   
 //  var styleObject = document.getElementById('ccountry').style;
   var styleObject = oObj.style;
   
    if(styleObject) {
  //   styleObject.visibility = 'visible';
     if(styleObject.display == "block"){
		styleObject.display = 'none';
	 }else{
		styleObject.display = 'block';
	}
	//return true;
	}

}

function setC(id, txt){
  var cObj = MM_findObj('cctbox');
   if(!cObj) return;

 	var tObj = MM_findObj('ccttxt');
  	var fObj = MM_findObj('cart_quantity');
	cObj.value = id;
	tObj.value = txt;
	ccdrop();
	
	fObj.submit();	// cart_quantity is the form.
}

function setcCal(){
	calMgr.swapImg(dateAvailable,'.imgDown',true);dateAvailable.show();
}

function setcDate(txt){
 	var tObj = MM_findObj('ddttxt');
	tObj.value = txt;
}
function setcDrop(txt){
 	var tObj = MM_findObj('ccttxt');
	tObj.value = txt;
}


function submitCompare()
{
  	var tObj = MM_findObj('p_compare');
	var pObj = tObj.value;
	var comError = 'false';
	var comCount = 0;
	
	if (pObj > 0){
		pObj ++;
		
		for(i=1; i<pObj; i++) {
		
			var tick_ob_name = 'compare[' + i + ']';
			
			var cObj = MM_findObj(tick_ob_name);
		
			if (cObj.checked == true) {
				comCount ++;
			}
		}
		
		if (comCount > 0){
				comError = 'false';
		}else{
				comError = 'true';
		}
	
	}else{
		comError = 'true';
	}


	if (comError == 'true'){
			alert('Please select 2 or more items to compare by clicking on the small compare tick box next to each product before clicking the compare button');
	}else{
	 document.product_compare.submit();
	}
}

function showvis(id){
	   var styleitem = MM_findObj(id)
	   var styleObject = styleitem.style;
   
    if(styleObject) {
     styleObject.visibility = 'visible';
	}
}

function dsShow(){
  var sObj = MM_findObj('dsHPless');
   var hObj = MM_findObj('dsHPmore');

 	if(!sObj) return;
    if(!hObj) return;

   var stylehObject = hObj.style;
   var stylesObject = sObj.style;
   
    if(stylehObject) {
		stylehObject.display = 'none';
	 }
	 
    if(stylesObject) {
		stylesObject.display = 'block';
	}
	
	$("#dsHPsclText").slideToggle("normal");
}

function dsHide(){
  var sObj = MM_findObj('dsHPmore');
   var hObj = MM_findObj('dsHPless');

 	if(!sObj) return;
    if(!hObj) return;

   var stylehObject = hObj.style;
   var stylesObject = sObj.style;
   
    if(stylehObject) {
		stylehObject.display = 'none';
	 }
	 
    if(stylesObject) {
		stylesObject.display = 'block';
	}
	
	$("#dsHPsclText").slideToggle("normal");
}

function bookmarksite(siteurl, sitetitle){
if (document.all)
window.external.AddFavorite(siteurl, sitetitle);
else if (window.sidebar)
window.sidebar.addPanel(sitetitle, siteurl, "")
}



function dsFShow(){
  var sObj = MM_findObj('dsFLTless');
   var hObj = MM_findObj('dsFLTmore');
   var oObj = MM_findObj('topfilterBox');

 	if(!sObj) return;
    if(!hObj) return;
    if(!oObj) return;

	hObj.className='filtMoreHide';
	sObj.className='filtLessShow';
	oObj.className='SHOWitall';

//	$("#dsHPsclText").slideToggle("normal");
}

function dsFHide(){
  var sObj = MM_findObj('dsFLTmore');
   var hObj = MM_findObj('dsFLTless');
   var oObj = MM_findObj('topfilterBox');

 	if(!sObj) return;
    if(!hObj) return;
    if(!oObj) return;

	
	hObj.className='filtLessHide';
	sObj.className='filtMoreShow';
	oObj.className='SHOWitless';
	
//	$("#dsHPsclText").slideToggle("normal");
}

function dsChangeWish(dspid, dsbid){
				$(".dsWishSide").slideUp("fast");
						 var content_show = dspid;
						 var content_bracket = dsbid;
							$.ajax({
							method: "get",url: "http://www.theplasmacentre.com/wish_ajax.php",data: "products_id="+content_show+"&bracket+id=" + content_bracket +"&bp=76",
							success: function(html){ //so, if data is retrieved, store it in html
							$(".dsWishSide").html(html);
							$(".dsWishSide").slideDown("fast"); //animation
							//show the html inside .content div
					 }
				 }); //close $.ajax(
}

function bfsShow(){
  var sObj = MM_findObj('bfHPless');
   var hObj = MM_findObj('bfHPmore');

 	if(!sObj) return;
    if(!hObj) return;

   var stylehObject = hObj.style;
   var stylesObject = sObj.style;
   
    if(stylehObject) {
		stylehObject.display = 'none';
	 }
	 
    if(stylesObject) {
		stylesObject.display = 'block';
	}
	
	$("#bfnInputOther").slideToggle("normal");
}

function bfsHide(){
  var sObj = MM_findObj('bfHPmore');
   var hObj = MM_findObj('bfHPless');

 	if(!sObj) return;
    if(!hObj) return;

   var stylehObject = hObj.style;
   var stylesObject = sObj.style;
   
    if(stylehObject) {
		stylehObject.display = 'none';
	 }
	 
    if(stylesObject) {
		stylesObject.display = 'block';
	}
	
	$("#bfnInputOther").slideToggle("normal");
}

function dsDivShow(id){
  var sObj = MM_findObj(id);

 	if(!sObj) return;

   var stylesObject = sObj.style;
   
		stylesObject.display = 'block';
}

function dsDivHide(id){
  var sObj = MM_findObj(id);

 	if(!sObj) return;

   var stylesObject = sObj.style;
   
		stylesObject.display = 'none';
}


function dsChangeCompare(id, dspid, dschange, rpage){
	  var cObj = MM_findObj(id);
		  if(!cObj) return;
		
		if (dschange == 'yes'){
			
			if(cObj.checked == true)  {
				   	cObj.checked = false;
			   var content_job = 'remove';
			} else {
			   		cObj.checked = true;
			   	var content_job = 'add';
			}
		}else{
			if(cObj.checked == true)  {
			   var content_job = 'add';
			} else {
			   	var content_job = 'remove';
			}
		}
		
		 var content_show = dspid;
			$.ajax({
					method: "get",url: "http://www.theplasmacentre.com/compare_ajax.php",
					data: "products_id="+content_show+"&operat=" + content_job,
					success: function(html){ //so, if data is retrieved, store it in html
						if (content_job == 'remove'){
								// alert('Item Removed.');
						}else{
								// alert('Item Added.');
						}
					}
			}); //close $.ajax(
			
		if (rpage == 'newpage'){
			document.product_compare.submit();
		}
}


function dsRemoveCompare(id, dspid, dschange, rpage){
	  var cObj = MM_findObj(id);
		
		if(!cObj) return;
		
		 var content_job = 'remove';
		 var content_show = dspid;
		
		cObj.checked = false;
		
			$.ajax({
					method: "get",url: "http://www.theplasmacentre.com/compare_ajax.php",
					data: "products_id="+content_show+"&operat=remove",
					success: function(html){ //so, if data is retrieved, store it in html
							if (rpage == 'newpage'){
								document.product_compare.submit();
							}
					}
			}); //close $.ajax(
			
}
