﻿// JScript File
function dispMsg(msgStr)
{
	status=msgStr;
}

function chIm(OldImage, NewImage)
{
	if (document.images && loaded)
	{
		document.images[OldImage].src = eval(NewImage).src;	
	}
}

var newwindow = ''
function popitup(url) 
{
	if (newwindow.location && !newwindow.closed) 
	{
		newwindow.location.href = url;
		newwindow.focus();
	}
	else 
	{ 
		newwindow=window.open(url,'PCS','width=350,height=350,resizable=0,scrollbars=1');
	}
}

function popitup2(url) 
{
	if (newwindow.location && !newwindow.closed) 
	{
		newwindow.location.href = url;
		newwindow.focus();
	}
	else 
	{ 
		newwindow=window.open(url,'PCS','width=550,height=550,resizable=0,scrollbars=1');
	}
}

function UpdateCity(radioValue, elementId)
{
    document.getElementById(elementId).value = radioValue;
	
	if (document.getElementById("ctl00_ContentPlaceHolder1_CheckBox1").checked == 'checked')
	{
		document.getElementById("<%=TextBoxCity2.ClientID%>").value = radioValue;
	}
	else if (document.getElementById("ctl00_ContentPlaceHolder1_CheckBox2").checked == 'checked')
	{
		document.getElementById("ctl00_ContentPlaceHolder1_TextBoxShippCity").value = radioValue;
	}
}

function onlyDigits(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
function autoTab( input,len, e )
{ 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; 
	if( input.value.length >= len && !containsElement( filter, keyCode ))
	{ 
		input.value = input.value.slice( 0, len ); 
		input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	}
	return true; 
}

function clickButton(e,buttonid) {
    debugger;
    var bt = document.getElementById(buttonid);
    if (typeof(bt) == 'object') {
        if (navigator.appName.indexOf("Netscape") > -1) {
            if(e.keyCode == 13) {
                if (bt && typeof(bt.click) == 'undefined') {
                    bt.click =  addClickFunction1(bt);
                }
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > -1) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

function addClickFunction1(bt) {
    debugger;
    var result = true;
    if (bt.onclick) result = bt.onclick();
    if (typeof(result) == 'undefined' || result) {
        eval(bt.getAttribute('href'));
    }
}

function FocusButton(FormID)
{

     if(document.getElementById("TextBoxSearch").value != null)
     {
        document.getElementById("SearchImageGo").click();
     }
     if(event.keyCode==13)
     {   
        document.getElementById(FormID).click();
     }
}

function FocusButton(e)
{
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
 
    if(code==13)
    {    	                                	    
        Search();
    	return false; 
    }
}
function Search()
{

    e = document.getElementById("TextBoxSearch")

    if (e.value != "")
    {
          link = "/newpcs/Search-" + URLencode(e.value) + "-PCS-Part.aspx";
  	  window.location = link;
	  return false;   
	
    }
    else
	 return false; 

}

function containsElement( arr, ele )
{
	var found = false, index = 0; 
	while( !found && index < arr.length ) 
		if( arr[index] == ele )
		{ 
			found = true; 
		}
		else
		{ 
			index++; 
		}
	return found; 
} 

function getIndex( input )
{ 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 )
		if ( input.form[i] == input )
		{
			index = i; 
		}
		else
		{
			i++; 
		}
	return index; 
} 
function mo(o){o.className=='menu_head_off'?o.className='menu_head_on': o.className=o.className; }
function mx(o){o.className=='menu_head_on'?o.className='menu_head_off': o.className=o.className; } 
function UpdatePrice(valueprice)
{
	var shipprice, temp;
	temp = valueprice.split("-");
	shipprice = temp[1];
	if (shipprice == null)
		shipprice = "0.00";
	if(shipprice == "To be determined")
	{
		document.getElementById("ShippingPrice").value = "To be determined";
		document.getElementById("TotalPrice").value = "To be determined";
	}
	else
	{
		document.getElementById("ShippingPrice").value = formatCurrency(parseFloat(shipprice));
		document.getElementById("TotalPrice").value = parseFloat(shipprice) + formatValue(parseFloat(document.getElementById("SubTotalPrice").value.replace("$", "").replace(",", ""))) + formatValue(parseFloat(document.getElementById("TaxPrice").value.replace("$", "")));
		document.getElementById("TotalPrice").value = formatCurrency(document.getElementById("TotalPrice").value);
	}
}
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if(cents < 10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0,num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	return (((sign)?'' : '-') + '$' + num + '.' + cents);
}

function formatValue(value)
{
	return Math.round(value*100)/100;
}

function checkme()
{
document.BtnRegister.disabled='false'
return true;
}
function Buy(item, qty)
{
    link1 = "Buy-" + URLencode(document.getElementById(qty).value) + "-" + URLencode(item) + "-cellular-accessory.aspx";
    link = "ShoppingCart.aspx?Itemno=" + URLencode(item) + "&Qty=" + URLencode(document.getElementById(qty).value);
    window.open(link,"_self","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes")
}
function BuyOne(item)
{
    link1 = "Buy-1-" + URLencode(item) + "-cellular-accessory.aspx";
    link = "ShoppingCart.aspx?Itemno=" + URLencode(item) + "&Qty=1";
    window.open(link,"_self","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes")
}
function URLencode(sStr)
{
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
}

//FLV Videos

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}




