

var isIE, isNs;
isIE = false;
isNs = false;
if (navigator.appName == "Netscape") {isNs=true;}else{isIE= true;}

function btOnMouserOver(obj)
{
    obj.style.background="url(/Library/Image/newImage/"+obj.className+"2.gif) no-repeat"; 
}
function btOnMouserOut(obj)
{
    obj.style.background="url(/Library/Image/newImage/"+obj.className+"1.gif) no-repeat"; 
}
    
function preloadImages()
{	  
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}
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 roll(id, newSrc) {
    var theImage = MM_findObj(id);
    if (theImage)theImage.src = newSrc;

}

function show(object) {
  var obj = MM_findObj(object);
  if (obj != null)
	{
    obj = (obj.style) ? (obj.style):obj;
    if (isNs)
			obj.display = "table-row";
		else
			obj.display = "block";
    
   }
}

function hide(object) {
  var obj = MM_findObj(object);
	if (obj != null)
	{
     obj = (obj.style) ? (obj.style):obj;
	  
			obj.display = "none";
    
	}
}

function showhide(object)
{
	var obj = MM_findObj(object);
  if (obj != null)
	{
    obj = (obj.style) ? (obj.style):obj;
            
    if (obj.display == "none")
    {
		if (isNs)
			obj.display = "table-row";
		else
			obj.display = "block";
	}
	else
		obj.display = "none";
			
   }   
  }


function showhideRP(object1, object2)
{		
	if (object1.checked)
		show(object2);
	else
		hide(object2);		
}


function calcRP(object1, object2)
{	
				
	var obj1 = MM_findObj('lblOTotalPrice');
	var obj2 = MM_findObj('lblRPValue');
	var obj3 = MM_findObj('lblNTotalPrice');
	var obj4 = MM_findObj('RewardPoint1_hdnORPUsed');
	var obj5 = MM_findObj('RewardPoint1_hdnValRPPerDollar');
	var obj6 = MM_findObj('RewardPoint1_hdnTotalPrice');	
	if (object1 != null && object1.selectedIndex != 0)	
	{		
		show(object2);		
		var orpValue = (parseFloat(obj4.value) * parseFloat(obj5.value));		
		var oTotalPrice = (parseFloat(obj6.value) + orpValue);
		obj1.innerHTML = "$" + Math.round(oTotalPrice * 100) / 100;		
		var rpValue = parseFloat(object1.options[object1.selectedIndex].value) * parseFloat(obj5.value);		
		obj2.innerHTML = "$" + Math.round(rpValue * 100) /100;		
		var nTotalPrice = (parseFloat(obj6.value) + orpValue - rpValue);
		obj3.innerHTML = "$" + Math.round(nTotalPrice * 100) / 100;		
	}
	else
		hide(object2);
	
}


function checkCCPaymentOption()
{	
	var obj = MM_findObj('PaymentOption1:rblPaymentOption');	
	if (obj[0].checked)
	{					
		show('tblCreditCardForm');
	}
	else
	{		
		hide('tblCreditCardForm');
	}
}

function popUp(txt)
{
	winPopUp = window.open(txt, "", "left=200, top=200, width=200,height=187");				
}

function open_popup_window(url, win_width, win_height, resize, scrollbars)
{
   newWindow=window.open(url,'popup', 'menubar=no,toolbar=no,resizable=yes,scrollbars='+scrollbars+',width='+win_width+',height='+win_height);
}	

function MYS_sd_same_as_above()
{	
	var obj;	
	obj = MM_findObj('ShippingDetail1_cbSameAsAbove');
	
	if (obj != null)
	{
		var obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10, obj11, obj12;		
		obj1 = MM_findObj('ShippingDetail1_tbSAddress1');
		obj2 = MM_findObj('ShippingDetail1_ddlSStates');
		obj3 = MM_findObj('ShippingDetail1_tbSSuburb');
		obj4 = MM_findObj('ShippingDetail1_tbSPostcode');
		obj5 = MM_findObj('ShippingDetail1_tbBAddress1');
		obj6 = MM_findObj('ShippingDetail1_ddlBStates');
		obj7 = MM_findObj('ShippingDetail1_tbBSuburb');
		obj8 = MM_findObj('ShippingDetail1_tbBPostcode');			
		obj9 = MM_findObj('ShippingDetail1_tbBName');
		obj10 = MM_findObj('ShippingDetail1_tbSName');
		obj11 = MM_findObj('ShippingDetail1_tbBCName');
		obj12 = MM_findObj('ShippingDetail1_tbSCName');
			
		if (obj1 != null && obj2 != null && obj3 != null && obj4 != null &&
				obj5 != null && obj6 != null && obj7 != null && obj8 != null && obj9 != null &&
				obj10 != null && obj11 != null && obj12 != null)
		{
			if (obj.checked)
			{					
				obj1.value = obj5.value;
				obj2.selectedIndex = obj6.selectedIndex;
				obj3.value = obj7.value;
				obj4.value = obj8.value;	
				obj10.value = obj9.value;
				obj12.value = obj11.value;			
				
			}
			else
			{				
				obj1.value = '';
				obj2.selectedIndex = 0;
				obj3.value = '';
				obj4.value = '';	
				obj10.value = '';
				obj12.value = '';										
			}				
		}					
	}		
}


function MYSRate(no, root)
{
	var i, obj;
	MYSStarHighLight(no, root);
	obj = MM_findObj('ReviewItem1_tbRate');
	if (obj != null)
	{		
		obj.value = no;
	}	
}

function MYSStarRestore(root)
{	
	var i, obj;		
	obj = MM_findObj('ReviewItem1_tbRate');
	if (obj != null)
	{
		if (obj.value == '')
		{
			for (i = 1; i <= 5; i++)
			{
				obj = MM_findObj('imgS' + i);
				if (obj != null)
				{
					obj.src = "/" + root + "Library/Image/starOut.gif";
				}
			}
			obj = MM_findObj('spRateTitle');
			if (obj != null)
			{
				obj.innerHTML = "";
			}	
			
		}
	}
}

function MYSStarHighLight(no, root)
{	
	var i, obj;
	obj = MM_findObj('ReviewItem1_tbRate');
	if (obj != null)
	{
		obj.value = '';
	}
	for (i = 1; i <= parseInt(no); i++)
	{
		obj = MM_findObj('imgS' + i);
		if (obj != null)
		{
			obj.src = "/" + root + "Library/Image/starOvr.gif";
		}
	}
	
	obj = MM_findObj('spRateTitle');
	if (obj != null)
	{
		switch(parseInt(no))
		{
			case 1:
				obj.innerHTML = "Very Bad";
				break;
			
			case 2:
				obj.innerHTML = "Bad";
				break;
				
			case 3:
				obj.innerHTML = "Average";
				break;
			
			case 4:
				obj.innerHTML = "Good";
				break;
			
			case 5:
				obj.innerHTML = "Excelent";
				break;
				
				
		}
	}
}

function showHideTransaction(id)
{
	showhide('trTransaction' + id);
	var imgO = MM_findObj('img' + id)
	var imgA = new Array();
	if (imgO != null)
	{
		imgA = imgO.src.split("/")
		if (imgA[imgA.length - 1] == 'sqr_plus.gif')
		{
			imgA[imgA.length - 1] = 'sqr_dot.gif';
			imgO.src = imgA.join("/");
		}
		else
		{
			imgA[imgA.length - 1] = 'sqr_plus.gif';
			imgO.src = imgA.join("/");
		}
	}
}

function showHideTransaction2(id)
{
	showhide('trNTransaction' + id);
	var imgO = MM_findObj('imgN' + id)
	var imgA = new Array();
	if (imgO != null)
	{
		imgA = imgO.src.split("/")
		if (imgA[imgA.length - 1] == 'sqr_plus.gif')
		{
			imgA[imgA.length - 1] = 'sqr_dot.gif';
			imgO.src = imgA.join("/");
		}
		else
		{
			imgA[imgA.length - 1] = 'sqr_plus.gif';
			imgO.src = imgA.join("/");
		}
	}
}

function modifyItemQuantity(o, qty)
{
	var obj = MM_findObj(o);		
	var oldVal = 0;
	if (obj != null)
	{		
		oldVal = Number(obj.value);
		obj.value = oldVal + Number(qty);
	}
		
}





// extra ajax for only item detail
var xmlHttp2;
function getPostcode()
{		
	xmlHttp2=GetXmlHttpObject2();
	if (xmlHttp2==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 	
	
	var postcode = MM_findObj('item_postcode').value;			
	var totalPrice = MM_findObj('item_price').value;
	var weight = MM_findObj('item_weight').value;		
	
	var url="Library/Include/GetFreight.aspx";		
	var parameters = "weight=" + encodeURI(weight.toString());
	parameters+= "&postcode=" + encodeURI(postcode.toString());	
	parameters+= "&total_price=" + encodeURI(totalPrice.toString());
	xmlHttp2.onreadystatechange=stateFChanged ;
	xmlHttp2.open("POST",url,true);		
	xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp2.setRequestHeader("Content-length", parameters.length);	
	xmlHttp2.setRequestHeader("Connection", "close");	
	xmlHttp2.send(parameters);	
}


function GetXmlHttpObject2()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");		
	}
	
	if (objXMLHttp == null)
	{
		objXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	return objXMLHttp;
}


function stateFChanged() 
{ 
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
	{ 		
		MM_findObj("item_freight").innerHTML="Cost: $" + xmlHttp2.responseText + " (only apply for 1 quantity)" ;
	} 
} 