// Microdirect JavaScript Util functions
// Version 1.0  - RFG Feb 2004
// Version 1.1  - RFG Apr 2004
// 				 			  AddToBasket, IncTxtBox and DecTxtBox Functions Added
//                Added referer to URL as IE6 has a problem with passing referer to aspx script??????
// Version 1.2  - Added New Accessories Layer

function popUpWindow(strURL, strName, intHeight, intWidth) {
	window.open(strURL,strName,'dependent=1,toolbar=0,titlebar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + intWidth + ',height=' + intHeight);
}

function AddToBasketHome(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,RecShownMore,RecShowed,Price) {
  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Company_Id=' + CompanyId+ '&Company_Name=' + CompanyName+ '&Quantity=' + 1+ '&ProductName=' + ProductName+ '&FormName=' + FormName+ '&ModelId=' + ModelId+ '&ModelName=' + ModelName+ '&CatCode=' + CatCode+ '&CatCodeCaption=' + CatCodeCaption+ '&PageNo='+PageNo+ '&RecShownMore='+RecShownMore+ '&RecShowed='+RecShowed+ '&Price='+Price;
//  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}

function AddToBasket(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,RecShownMore,RecShowed,PKID) {
  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Company_Id=' + CompanyId+ '&Company_Name=' + CompanyName+ '&Quantity=' + document.getElementById('T'+lngProductID).value+ '&ProductName=' + ProductName+ '&FormName=' + FormName+ '&ModelId=' + ModelId+ '&ModelName=' + ModelName+ '&CatCode=' + CatCode+ '&CatCodeCaption=' + CatCodeCaption+ '&PageNo='+PageNo+ '&PKID='+PKID+ '&RecShownMore='+RecShownMore+ '&RecShowed='+RecShowed;
//  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}

function AddToBasket_Product(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,RecShownMore,RecShowed,PKID,Price) {
  //alert (Price)
  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Company_Id=' + CompanyId+ '&Company_Name=' + CompanyName+ '&Quantity=' + 1+ '&ProductName=' + ProductName+ '&FormName=' + FormName+ '&ModelId=' + ModelId+ '&ModelName=' + ModelName+ '&CatCode=' + CatCode+ '&CatCodeCaption=' + CatCodeCaption+ '&PageNo='+PageNo+ '&PKID='+PKID+ '&RecShownMore='+RecShownMore+ '&RecShowed='+RecShowed+ '&Price='+Price;
//  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}

function RemoveFromBasket(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,PKID) {

  window.location.href='RemoveFromBasket.asp?ProductID=' + lngProductID + '&Company_Id=' + CompanyId+ '&Company_Name=' + CompanyName+ '&Quantity=' + document.getElementById('T'+lngProductID).value+ '&ProductName=' + ProductName+ '&FormName=' + FormName+ '&ModelId=' + ModelId+ '&ModelName=' + ModelName+ '&CatCode=' + CatCode+ '&CatCodeCaption=' + CatCodeCaption+ '&PageNo='+PageNo+ '&PKID='+PKID;
//  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}

function RemoveFromBasket_Product(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,PKID) {

  window.location.href='RemoveFromBasket_Product.asp?ProductID=' + lngProductID + '&Company_Id=' + CompanyId+ '&Company_Name=' + CompanyName+ '&Quantity=' + document.getElementById('T'+lngProductID).value + '&ProductName=' + ProductName+ '&FormName=' + FormName+ '&ModelId=' + ModelId+ '&ModelName=' + ModelName+ '&CatCode=' + CatCode+ '&CatCodeCaption=' + CatCodeCaption+ '&PageNo='+PageNo+ '&PKID='+PKID;
//  window.location.href='AddToBasket.asp?ProductID=' + lngProductID + '&Quantity=' + document.getElementById('T'+lngProductID).value + '&referer='+location.href;
}


function IncTxtBox(objTxtBox,lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,RecShownMore,RecShowed,PKID,i,qty,Price) {
  var intValue=document.getElementById(objTxtBox).value;
	intValue++;
  document.getElementById(objTxtBox).value=intValue;
  //myarray(i)=qty
  //alert ( document.getElementById(objTxtBox).value )
  //alert (qty)
  //session("CartItemQtyNumArray")=myarray;

	AddToBasket_Product(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,RecShownMore,RecShowed,PKID,Price)
	
}


function DecTxtBox(objTxtBox,lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,PKID) {
  var intValue=document.getElementById(objTxtBox).value;
	if (intValue>=2) {
	  RemoveFromBasket_Product(lngProductID,CompanyId,CompanyName,ProductName,FormName,ModelId,ModelName,CatCode,CatCodeCaption,PageNo,PKID)
	  intValue--;
    document.getElementById(objTxtBox).value=intValue;
	
	}	
	
}

function isNumberPress() {
  if (((event.keyCode > 47 && event.keyCode < 58) ||
       (event.keyCode > 95 && event.keyCode < 106)) && 
       !event.shiftKey       || 
       (event.keyCode == 37) ||
	   (event.keyCode == 39) || 
       (event.keyCode == 46) || 
       (event.keyCode == 8)  || 
       (event.keyCode == 9))
  {
    return true;
  }
  else
    return false;
}

function intDown() {
  if (navigator.appVersion.indexOf("Mac")==-1) {
    if (isNumberPress())
		  event.returnValue = true;
	  else
	  {
      event.keyCode      = 0; // Set to zero so don't handle
      event.cancelBubble = true;
      event.returnValue  = false;
    }
  }
}

function intDownWithPeriod() {
  if (isNumberPress() || ((event.keyCode == 190 || event.keyCode == 110)&& event.srcElement.value.indexOf(".")==-1))    
    event.returnValue  = true;
	else
	{
    event.keyCode = 0; // Set to zero so don't handle
    event.cancelBubble = true;        
    event.returnValue  = false;
  }
}

function textCounter(field, maxlimit) { 
  if (field.value.length > maxlimit) // if too long...trim it! 
    field.value = field.value.substring(0, maxlimit); 
    // otherwise, update 'characters left' counter 
  else 
    field.title = maxlimit - field.value.length; 
} 


function NewWindow(mypage,myname,w,h,scroll,pos) {
//  if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
  //if(pos=="center"){
  LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
  //}
  //else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);
}

function swapLayers(id, objThis) {	
	for (var intI=0; intI<arrLayers.length; intI++) {
	  if (arrLayers[intI]==id) { 
		  document.getElementById(id).style.display='block';
		}	else { 
		  document.getElementById(arrLayers[intI]).style.display='none';	
		}
	}
	return true;
}

function changePic(objThis) {
  var thisCtrl;

  document.tabDescription.src='../../IMAGES/My Pictures/tabDescription-off.gif'
//  document.tabSpecifications.src='../images/IMAGES/My Pictures/tabSpecifications-off.gif'
  //document.tabComments.src='/images/productinfo/tabcomments-off.gif'
  document.tabDetails.src='../../IMAGES/My Pictures/tabdetails-off.gif'
//	document.tabAccessories.src='../images/IMAGES/My Pictures/tabAccessories-off.gif'
	thisCtrl=eval("document." + objThis);
	thisCtrl.src='../../IMAGES/My Pictures/' + objThis + '.gif';
	return true;
}

function swapImage(num) {
	if (document.images) {
		document.swap.src = image_list[num].src;
	}
	
	if (image_list.length>1) {
  	for (var intI=0; intI<image_list.length; intI++) {
    	document.getElementById('thumb'+intI).src='../images/IMAGES/My Pictures/thumb' + (intI+1) + '-off.gif';
  	}
	  document.getElementById('thumb'+num).src='../images/IMAGES/My Pictures/thumb' + (num+1) + '-on.gif';
	}
	return true;
}