
function formatdiv1(DIVID){
	var e = $(DIVID);
	showdiv('myplaceholder');
	e.innerHTML = "";
	emptyandhidediv("myplaceholder2");
	e.style.border = 'solid 1px #C1CBD8';
	e.style.position = 'relative';
	if(browser.isIE){
		e.style.left = '3px';
		e.style.width = '583px';
		e.style.top = '17px';
	}else{
		e.style.left = '2px';
		e.style.width = '583px';
		e.style.top = '14px';
	}
	e.style.height = '250px';
	e.style.overflow = 'auto';
}

function formatdiv11(DIVID){
	var e = $(DIVID);
	e.style.border = 'solid 1px #C1CBD8';
	e.style.position = 'relative';
	if(browser.isIE){
		e.style.left = '-136px';
		e.style.top = '17px';
	}else{
		e.style.left = '-137px';
		e.style.top = '14px';
	}
	e.style.width = '290px';
	e.style.height = '250px';
	e.style.overflow = 'auto';
	showdiv("myplaceholder2");
}

function emptyandhidediv(DIVID){
	var e = $(DIVID);
	e.innerHTML = "";
	e.style.width = '0px';
	e.style.height = '0px';
	e.style.visibility = 'hidden';
}

function showdiv(DIVID){
	var e = $(DIVID);
	e.style.visibility = 'visible';
}

function formatdiv2(DIVID){
	formatdiv11('myplaceholder');
	var e = $(DIVID);
	e.style.border = 'solid 1px #C1CBD8';
	e.style.position = 'absolute';
	if(browser.isIE){
		e.style.left = '296px';
		e.style.top = '17px';
	}else{
		e.style.left = '296px';
		e.style.top = '14px';
	}
	e.style.width = '290px';
	e.style.height = '250px';
	e.style.overflow = 'auto';
}

function formatcontentdiv(DIVID){
	var e = $(DIVID);
	e.style.position = 'relative';
	e.style.left = '5px';
	if(e.style.top != '-210px'){
		e.style.top = '20px';
	}
	e.style.width = '565px';
}

function formatextradiv(DIVID, top, height){
	var e = $(DIVID);
	e.style.position = 'relative';
	e.style.left = '0px';
	e.style.top = top;
	e.style.width = '579px';
	e.style.height = height;
}

function showextradiv(DIVID){
	var e = $(DIVID);
	e.style.visibility = 'visible';
}

function hideextradiv(DIVID){
	var e = $(DIVID);
	e.innerHTML = "";
	e.style.width = '0px';
	e.style.height = '0px';
	e.style.visibility = 'hidden';
}

function hideSubmenu(DIVID){
	var e = $(DIVID);
	e.style.visibility = 'hidden';
	if (e.iframeEl != null)
      e.iframeEl.style.display = "none";
}

function emptydiv(DIVID){
	var e = $(DIVID);
	e.innerHTML = "";
	e.style.width = '0px';
	e.style.height = '0px';
	e.style.visibility = 'hidden';
}
function resetstyle(DIVID){
	var e = $(DIVID);
	e.innerHTML = "";
	e.style.top = '60px';
}
function positionShowPart(DIVID){
	var e = $(DIVID);
	e.innerHTML = "";
	e.style.position = 'relative';
	if(browser.isIE){
		e.style.top = '-6px';
	}else{
		e.style.top = '14px';
	}
	e.style.left = '5px';
}
function positionMenu(DIVID){
	var e = $(DIVID);
	e.style.position = 'absolute';
	e.style.left = '200px';
}

var fromContShop = 0;
var firsStageVars;
var secondStageVars1;
var secondStage1Called = 0;
var secondStageVars2;
var secondStage2Called = 0;
var thirdStageVars;
var mainCall3Called = 0;
var expandCalled = 0;
var fromLenline = 0;
var new_len_part;
//function onComplete overloaded to accept required parameters
function menuClick(category, subcat, searchString){
    firsStageVars = new Array(category, subcat, searchString);
	new Ajax.Request('main/how_many.php?call=menu&category=' + category + '&subcat=' + subcat + '&search=' + searchString, {onLoading:showLoading, onComplete: function(originalRequest) {
      showResponse(originalRequest, category, subcat, searchString);
   }, asynchronous:true});
}

function searchClick(category, subcat, searchString){
	var ledarray = new Array("led strips","strips led","led strip","indoor led strips","outdoor led strips","indoor led strip","outdoor led strip","55-7130B-0","55-7130B","55-7130G-0","55-7130G","55-7130R-0","55-7130R","55-7130Y-0","55-7130Y","55-7130W-0","55-7130W","55-7130WW-0","55-7130WW","55-7160B-0","55-7160B","55-7160G-0","55-7160G","55-7160R-0","55-7160R","55-7160Y-0","55-7160Y","55-7160W-0","55-7160W","55-7160WW-0","55-7160WW","55-71300B-0","55-71300B","55-71300G-0","55-71300G","55-71300R-0","55-71300R","55-71300Y-0","55-71300Y","55-71300W-0","55-71300W","55-71300WW-0","55-71300WW","55-7230B-0","55-7230B","55-7230G-0","55-7230G","55-7230R-0","55-7230R","55-7230Y-0","55-7230Y","55-7230W-0","55-7230W","55-7230WW-0","55-7230WW","55-7260B-0","55-7260B","55-7260G-0","55-7260G","55-7260R-0","55-7260R","55-7260Y-0","55-7260Y","55-7260W-0","55-7260W","55-7260WW-0","55-7260WW","55-72300B-0","55-72300B","55-72300G-0","55-72300G","55-72300R-0","55-72300R","55-72300Y-0","55-72300Y","55-72300W-0","55-72300W","55-72300WW-0","55-72300WW","55-71","55-713","55-7130","55-716","55-7160","55-72","55-723","55-7230","55-726","55-7260");
	var sString = searchString.toUpperCase();
	if (contains(ledarray,sString)){
		window.open('http://www.mode-elec.com/pdf/new/LED_Strips.pdf');
	}else{
	switch (sString) {
		case '12-253-50': searchString = '12-253-0'; break;
		case '12-254-50': searchString = '12-254-0'; break;
		case '12-256-50': searchString = '12-256-0'; break;
		case '12-258-50': searchString = '12-258-0'; break;
		case '12-254R-50': searchString = '12-254R-0'; break;
		case '12-254S-50': searchString = '12-254S-0'; break;
		case '12-256R-50': searchString = '12-256R-0'; break;
		case '12-256S-50': searchString = '12-256S-0'; break;
		case '12-258R-50': searchString = '12-258R-0'; break;
		case '12-258S-50': searchString = '12-258S-0'; break;
		case '13-101-50': searchString = '13-101-0'; break;
		case '13-102-50': searchString = '13-102-0'; break;
		case 'SH83-S': searchString = 'SH83-100'; break;
		case '34-652BK-50': searchString = '34-652BK-10'; break;
		case '34-652CL-50': searchString = '34-652CL-10'; break;
		case '34-652RD-50': searchString = '34-652RD-10'; break;
		case '34-652WH-50': searchString = '34-652WH-10'; break;
		case '34-652YL-50': searchString = '34-652YL-10'; break;
		case '34-653BK-50': searchString = '34-653BK-10'; break;
		case '34-653CL-50': searchString = '34-653CL-10'; break;
		case '34-653RD-50': searchString = '34-653RD-10'; break;
		case '34-653WH-50': searchString = '34-653WH-10'; break;
		case '34-653YL-50': searchString = '34-653YL-10'; break;
		case '34-654BK-50': searchString = '34-654BK-10'; break;
		case '34-654CL-50': searchString = '34-654CL-10'; break;
		case '34-654RD-50': searchString = '34-654RD-10'; break;
		case '34-654WH-50': searchString = '34-654WH-10'; break;
		case '34-654YL-50': searchString = '34-654YL-10'; break;
		case '34-655BK-50': searchString = '34-655BK-10'; break;
		case '34-655CL-50': searchString = '34-655CL-10'; break;
		case '34-655RD-50': searchString = '34-655RD-10'; break;
		case '34-655WH-50': searchString = '34-655WH-10'; break;
		case '34-655YL-50': searchString = '34-655YL-10'; break;
		case '34-656BK-50': searchString = '34-656BK-10'; break;
		case '34-656CL-50': searchString = '34-656CL-10'; break;
		case '34-656RD-50': searchString = '34-656RD-10'; break;
		case '34-656WH-50': searchString = '34-656WH-10'; break;
		case '34-656YL-50': searchString = '34-656YL-10'; break;
		case '34-657BK-50': searchString = '34-657BK-10'; break;
		case '34-657CL-50': searchString = '34-657CL-10'; break;
		case '34-657RD-50': searchString = '34-657RD-10'; break;
		case '34-657WH-50': searchString = '34-657WH-10'; break;
		case '34-657YL-50': searchString = '34-657YL-10'; break;
	}
	if(validateSearch(searchString)){
	firsStageVars = new Array(category, subcat, searchString);
	new Ajax.Request('main/how_many.php?call=menu&search=' + searchString, {onLoading:showLoading, onComplete: function(originalRequest) {
      showResponse(originalRequest, category, subcat, searchString);
   }, asynchronous:true});
	}else{
    return false;
    }
	}
}

function lenResponse(lenRequest,searchString){
	if(lenRequest.responseText != 0){
		new_len_part = lenRequest.responseText;
		alert(trim(new_len_part) + " is the Lenline item transferred to Mode. You can try searching for this part in Lenline Website (use 'lenline products' link). Stock check for " + trim(new_len_part) + " is available from this Website.");
	}else{
		fromLenline = 0;
	}
}

function is_Lenline(searchString){
	new Ajax.Request('ajax_calls.php?call=from_len&search=' + searchString, {onComplete: function(lenRequest) {
      lenResponse(lenRequest,searchString);
   }, asynchronous:true});
}

function contains(ledarray, ledstrip) {
  var i = ledarray.length;
  while (i--) {
    if (ledarray[i].toUpperCase() === ledstrip) {
      return true;
    }
  }
  return false;
}

function showResponse(originalRequest,category, subcat, searchString){
	// get the response as text
	var count = originalRequest.responseText;
    //is_Lenline(searchString);
	if(count == 0){
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		hideextradiv('extra');
		new Ajax.Updater('show_part', 'mode_html/no_results.html', {method:'get', asynchronous:true, onComplete:hideLoading});return false;
	}else if(count == 1){
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		hideextradiv('extra');
		new Ajax.Updater('show_part', 'ajax_calls.php?call=c_parts&category=' + category + '&subcat=' + subcat + '&search=' + searchString, {asynchronous:true, onComplete:hideLoading});return false;
	}else{
		formatdiv1('myplaceholder');
		new Ajax.Updater('myplaceholder', 'ajax_calls.php?call=menu&category=' + category + '&subcat=' + subcat + '&search=' + searchString, {asynchronous:true, onComplete:hideLoading});
		if(fromContShop == 0){
		formatcontentdiv('show_part');
		hideextradiv('extra');
		new Ajax.Updater('show_part', 'ajax_calls.php?call=empty', {asynchronous:true});return false;
		}
	}
    // get the response as xml
    //var resultxml = originalRequest.responseXML;
	fromContShop = 0;
}

//Called from hardware submenu...
function spec_menuClick(category, subcat, searchString){
    formatdiv1('myplaceholder');
    new Ajax.Updater('myplaceholder', 'ajax_calls.php?call=special&category=' + category + '&subcat=' + subcat + '&search=' + searchString, {asynchronous:true, onComplete:hideLoading});
    formatcontentdiv('show_part');
    new Ajax.Updater('show_part', 'mode_html/click_partno.html', {method:'get', asynchronous:true, onComplete:hideLoading});return false;
}

function continueShop(){
    if(firsStageVars == null){
        homeCall();
        return;
    }
	fromContShop = 1;
    menuClick(firsStageVars[0], firsStageVars[1], firsStageVars[2]);
    if(secondStage1Called == 1){
        mainCall1(secondStageVars1[0], secondStageVars1[1]);
    }else if(secondStage2Called == 1){
        mainCall2(secondStageVars2[0], secondStageVars2[1], secondStageVars2[2]);
    }
    if(expandCalled == 1){
        mainCall3(thirdStageVars);
    }else if(mainCall3Called == 1){
        expandCall(thirdStageVars);
    }
}

function mainCall1(searchString, u){
    secondStageVars1 = new Array(searchString, u);
    secondStage1Called = 1;
    secondStage2Called = 0;
    formatdiv2('myplaceholder2');
    new Ajax.Updater('myplaceholder2','ajax_calls.php?call=expand&search=' + searchString + '&u=' + u, {asynchronous:true, onLoading: showLoading, onComplete:hideLoading});return false;
}
function mainCall2(tbl, subcat, u){
    secondStageVars2 = new Array(tbl, subcat, u);
    secondStage1Called = 0;
    secondStage2Called = 1;
    formatdiv2('myplaceholder2');
    new Ajax.Updater('myplaceholder2','ajax_calls.php?call=expand&category=' + tbl + '&subcat=' + subcat + '&u=' + u, {asynchronous:true, onLoading: showLoading, onComplete:hideLoading});return false;
}
function mainCall3(numbers){
    thirdStageVars = numbers;
    mainCall3Called = 1;
    expandCalled = 0;
    formatcontentdiv('show_part');
    new Ajax.Updater('show_part','ajax_calls.php?call=c_parts&pnum=pnum&search=' + numbers, {asynchronous:true, onLoading: showLoading, onComplete:hideLoading});return false;
}
function expandCall(numbers){
    mainCall3Called = 0;
    expandCalled = 1;
    thirdStageVars = numbers;
formatcontentdiv('show_part');
new Ajax.Updater('show_part','ajax_calls.php?call=c_parts&search=' + numbers, {asynchronous:true, onLoading: showLoading, onComplete:hideLoading});
if(numbers.substr(0, 5) == '32-02'){
formatextradiv('extra','45px','0px');
new Ajax.Updater('extra', 'ajax_calls.php?call=function1');
showextradiv('extra');	
}else{
hideextradiv('extra');
}
return false;
}

function posLoading(){
    $('loading_pr').style.left = (screen.width - 80)/2;
    //loading_pr.style.top = (screen.height - 18)/2;
	if (screen.width>=1280){
 		$("alberta").style.left=665;
		$("bc").style.left=665;
		$("mb").style.left=665;
		$("nb").style.left=665;
		$("ns").style.left=665;
		$("sn").style.left=665;
		$("on").style.left=665;
		$("qb").style.left=665;
		$("al").style.left=665;
		$("cal").style.left=665;
		$("co").style.left=665;
		$("fl").style.left=665;
		$("ga").style.left=665;
		$("in").style.left=665;
		$("io").style.left=665;
		$("lo").style.left=665;
		$("ma").style.left=665;
		$("mi").style.left=665;
		$("mn").style.left=665;
		$("ne").style.left=665;
		$("nj").style.left=665;
		$("ny").style.left=665;
		$("sd").style.left=665;
		$("te").style.left=665;
		$("tx").style.left=665;
		$("ut").style.left=665;
		$("vi").style.left=665;
		$("wa").style.left=665;
		$("ww").style.left=665;
		$("wy").style.left=665;
	}
	if (screen.width<=800){
 		$("alberta").style.left=422;
		$("bc").style.left=422;
		$("mb").style.left=422;
		$("nb").style.left=422;
		$("ns").style.left=422;
		$("sn").style.left=422;
		$("on").style.left=422;
		$("qb").style.left=422;
		$("al").style.left=422;
		$("cal").style.left=422;
		$("co").style.left=422;
		$("fl").style.left=422;
		$("ga").style.left=422;
		$("in").style.left=422;
		$("io").style.left=422;
		$("lo").style.left=422;
		$("ma").style.left=422;
		$("mi").style.left=422;
		$("mn").style.left=422;
		$("ne").style.left=422;
		$("nj").style.left=422;
		$("ny").style.left=422;
		$("sd").style.left=422;
		$("te").style.left=422;
		$("tx").style.left=422;
		$("ut").style.left=422;
		$("vi").style.left=422;
		$("wa").style.left=422;
		$("ww").style.left=422;
		$("wy").style.left=422;
	}
}

function hideLoading(){
    $('loading_pr').style.visibility='hidden';
}
function showLoading(){
    $('loading_pr').style.visibility='visible';
}

function validateSearch(value){
   value = trim(value);
   if(value == "") 
   { 
      alert('Please enter valid Mode Electronics part number or name of the part you are looking for.');
      return false; 
   }else{	
      return true;
   }
}

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function addToCartClick(part_no, name, qty, id_pic){
    if(!isPosInteger(qty)){
        alert("Invalid input! Only Positive Intergers are accepted.");
        return;
    }else if(qty ==0){
        alert("Number enterd has to be bigger than 0!");
        return;
    }
	new Ajax.Request('ajax_calls.php?call=add_to_cart&part_no=' + part_no + '&name=' + name + '&cart_quantity=' + qty + '&id_pic=' + id_pic, {onComplete: function(originalRequest) {
      showResponse2(originalRequest);
   }, asynchronous:true});
}

function showSideCart(){
	new Ajax.Updater('cart_items', 'ajax_calls.php?call=cart_sum', {asynchronous:true});return false;
}


function showResponse2(originalRequest){
	var str = originalRequest.responseText;
	var arr = new Array();
	arr = str.split(',');
	if(arr[0] == 999){
		var total = arr[1]*1 + arr[2]*1;
		var on_stock = arr[3]*1;
		if(on_stock > 0){
		alert("You requested " + total + " pieces so far, but our database shows that we only have " + on_stock + " pieces in stock. You can order " + on_stock + " pieces that are available right now, or contact us to get more items and completely fulfill your requirements.");
		return;
		}else{
		alert("Sorry, right now requested item is out of stock. Please check again later, or contact us to get this item for you.");
		return;
		}
	}else{
	new Ajax.Updater('cart_items', 'ajax_calls.php?call=cart_sum', {asynchronous:true});return false;
	}
}

function showCart(){
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		new Ajax.Updater('show_part', 'cart/show_cart.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});
		showSideCart();
		return false;
}

function updateCartClick(pars){
	new Ajax.Request('ajax_calls.php?call=update_cart' + pars, {onComplete: function(originalRequest) {
      showResponse3(originalRequest);
   }, asynchronous:true});
}

function showResponse3(originalRequest){
	var str = originalRequest.responseText;
	var arr = new Array();
	arr = str.split(',');
	if(arr[2] == 998){
		var req = arr[3];
		var on_stock = arr[4];
		var part_no = arr[1];
		alert("Your request for " + part_no + " is " + req + " pices, but our database shows that we only have " + on_stock + " pieces in stock. You can order " + on_stock + " pieces that are available right now, or contact us to get more items and completely fulfill your requirements.");
	}else{
	new Ajax.Updater('cart_items', 'ajax_calls.php?call=cart_sum', {asynchronous:true});
	}
	showCart();
}

function getParsString(){
	var inputs = document.getElementsByName("parts");
	var pars = "";
	var i = 0;
	while(i < inputs.length)
	{
		pars += "&" + inputs[i].getAttribute("id") + "=" + inputs[i].value;
		if(!isPosInteger(inputs[i].value)){
		  alert("Invalid quantity input for Part #" +  inputs[i].getAttribute("id") + "! Only Positive Integers are accepted.");
		  return;
        }
		i++;
	}
	return pars;
}

function getParsString0(){
	var inputs = document.getElementsByName("parts");
	var pars = "";
	var i = 0;
	while(i < inputs.length)
	{
		pars += "&" + inputs[i].getAttribute("id") + "=0";
		i++;
	}
	return pars;
}

function getParsString10(del_part){
	var inputs = document.getElementsByName("parts");
	var pars = "";
	var i = 0;
	while(i < inputs.length)
	{
		if(del_part == inputs[i].getAttribute("id")){
			pars += "&" + inputs[i].getAttribute("id") + "=0";
		}else{
			pars += "&" + inputs[i].getAttribute("id") + "=" + inputs[i].value;
		}
		i++;
	}
	return pars;
}

function showCheckout(){
		pars = "total=get_total";
		new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      		checkTotal(originalRequest);
   		}, asynchronous:true});
}

function checkTotal(originalRequest){
	var total = originalRequest.responseText;
	if(total >= 29){
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		fromMenu = 0;
		new Ajax.Updater('show_part', 'cart/checkout.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
	}else{
		alert("Total amount for any order can not be less than CDN$ 30.00!\nYour current order is CDN$ " + total);
		return;
	}
}

// if login call is from shopping cart, fromCart is 1
var fromCart = 0;
function showLoginForm(orig){
		fromCart = orig;
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		new Ajax.Updater('show_part', 'main/login.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
}

function loginClick(pararay){
	if(ValidateLogin(pararay[0], pararay[1])){
		var pars = 'mail=' + pararay[0].value + '&mail2=' + pararay[1].value + '&call=login';
		new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      		showResponse4(originalRequest);
   		}, asynchronous:true});
	}
}

function showResponse4(originalRequest){
	var resp = originalRequest.responseText;
	if(resp == 1){
		var el = $("menuList");
		el.innerHTML = '<LI><A onclick="return homeCall()" title="Home" id="about" style="cursor:pointer" accesskey="h">Home</A></LI>' +
    '<LI>&nbsp;|&nbsp;</LI><LI class="submenu"><A onclick="return buttonClick(event, \'distributors\')" title="Locate our Distributor in you area" id="dist" style="cursor:pointer">Distributors</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +
    '<LI><A onclick="return aboutCall()" title="About Mode" id="about" style="cursor:pointer">About Us</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +
    '<LI><A onclick="return contactCall()" title="Contact Info" id="contact" style="cursor:pointer">Contact</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI><A onclick="return productsCall()" title="Products (Adobe PDF Version)" id="products" style="cursor:pointer">Products</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI class="submenu"><A onclick="return buttonClick(event, \'new_products\')" title="New Products List" id="new" style="cursor:pointer">New Prod.</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI class="submenu"><A onclick="return buttonClick(event, \'technical\')" title="Get some technical info" id="tech" style="cursor:pointer">Technical</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI><A onclick="return stockClick()" title="Check Current Mode Electronics Stock Availability and Prices" id="stock" style="cursor:pointer">Stock Check</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI class="submenu"><A onclick="return buttonClick(event, \'account\')" title="Change your Password or Update User Information" id="acc" style="cursor:pointer">My Account</A>' +
    '</LI><LI>&nbsp;|&nbsp;</LI>' +	
    '<LI><A onclick="return logoutClick()" title="Logout" id="login" style="cursor:pointer">Logout</A>' +
    '</LI</UL>';
			showLogin_s();
	}else{
		alert("Email address and/or password are incorrect!");
	}

}

function logoutClick(orig){
	fromCart = 0;
	new Ajax.Request('ajax_calls.php?call=logout', {onComplete: function(originalRequest) {
      showResponse5(originalRequest, orig);
   }, asynchronous:true});
   return false;
}
function showResponse5(originalRequest, orig){
	var el = $("menuList");
	el.innerHTML =  '<LI><A onclick="return homeCall()" title="Home" id="about" style="cursor:pointer" accesskey="h">Home&nbsp;</A></LI>' +
    '<LI>|</LI><LI class="submenu"><A onclick="return buttonClick(event, \'distributors\')" title="Locate our Distributor in you area" id="dist" style="cursor:pointer">&nbsp;<font color="fcaf82" id="dist1">Find a Distributor</font>&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +
    '<LI><A onclick="return aboutCall()" title="About Mode" id="about" style="cursor:pointer">&nbsp;&nbsp;About Us&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +
    '<LI><A onclick="return contactCall()" title="Contact Info" id="contact" style="cursor:pointer">&nbsp;&nbsp;Contact&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +	
    '<LI><A onclick="return productsCall()" title="Products (Adobe PDF Version)" id="products" style="cursor:pointer">&nbsp;&nbsp;Products&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +	
    '<LI class="submenu"><A onclick="return buttonClick(event, \'new_products\')" title="New Products List" id="new" style="cursor:pointer">&nbsp;&nbsp;New Products&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +	
    '<LI class="submenu"><A onclick="return buttonClick(event, \'technical\')" title="Get some technical info" id="tech" style="cursor:pointer">&nbsp;&nbsp;Technical&nbsp;&nbsp;</A>' +
    '</LI><LI>|</LI>' +	
    '<LI><A onclick="return loginCall()" title="Login" id="login" style="cursor:pointer">&nbsp;&nbsp;Distributors Login</A>' +
    '</LI</UL>';
	homeCall();
}

function homeCall(login){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
	if(login == 1){
       new Ajax.Updater('show_part', 'mode_html/home1.html', {method:'get', asynchronous:true});return false;
	}else if(login == 3){
	   new Ajax.Updater('show_part', 'mode_html/home3.html', {method:'get', asynchronous:true});return false;
    }else{
	   new Ajax.Updater('show_part', 'mode_html/home.html', {method:'get', asynchronous:true});return false;
	}
}

function contactCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
    new Ajax.Updater('show_part', 'mode_html/contact.html', {method:'get', asynchronous:true});return false;
}

function aboutCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
    new Ajax.Updater('show_part', 'mode_html/about_mode.html', {method:'get', asynchronous:true});return false;
}

function productsCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
    new Ajax.Updater('show_part', 'mode_html/products.html', {method:'get', asynchronous:true});return false;
}

function loginCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
    new Ajax.Updater('show_part', 'mode_html/login.html', {method:'get', asynchronous:true, evalScripts:true});return false;
}

function showLogin_s(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'main/login_s.php', {method:'get', asynchronous:true});return false;
}

function regClick(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'main/register.php', {method:'get', asynchronous:true});return false;
}

function registerClick(el){
	if(!ValidateForm3(el)){
	    return;
	}
	var pars = 'f_name=' + el[0].value + '&l_name=' + el[1].value + '&company=' + el[2].value + '&email=' + el[3].value +'&accepts=' + el[5].checked + '&call=register';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showRegMessage(originalRequest);
   }, asynchronous:true});
}
function showRegMessage(originalRequest){
	var msg = originalRequest.responseText;
	if(msg == 1){
           		alert("Thank you to registering with Mode Electronics!\nLogin information has been emailed to you. Use this information to login and take advantage of the additional information from this web site.");
	}else if(msg == 2){
		alert("Sorry, email entered was already used for registration!");
	}else if(msg == 3){
		alert("Sorry, email address entered is not in our database.");
	}else if(msg == 4){
		alert("Sorry, there was database problem. We can not register you at the moment.");
	}else if(msg == 5){
		alert("Sorry, we could not email login information to you!");
	}else{
		alert("Error! Please try again later");
	}	
}

function updateClick(el){
	var pars = 'f_name=' + el[0].value + '&l_name=' + el[1].value + '&company=' + el[2].value + '&email=' + el[3].value +'&accepts=' + el[4].checked + '&old_email=' + el[5].value + '&call=update';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showUpMessage(originalRequest);
   }, asynchronous:true});
}
function showUpMessage(originalRequest){
	var msg = originalRequest.responseText;
	if(msg == 1){
           		alert("Your information successfully updated! If you changed your email address, when you login next time please use the new one.");
           	homeCall();
	}else if(msg == 2){
		alert("Sorry, email entered was already used for registration!");
	}else if(msg == 3){
		alert("Sorry, email address entered is not in our database.");
	}else if(msg == 4){
		alert("Sorry, there was database problem. We can not register you at the moment.");
	}else if(msg == 5){
		alert("Sorry, we could not email login information to you!");
	}else{
		alert(msg);
	}	
}

function techCall(page){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
  if(page == "basic"){
    new Ajax.Updater('show_part', 'mode_html/basic_electronics.html', {method:'get', asynchronous:true});return false;
  }else if(page == "ohms"){
    new Ajax.Updater('show_part', 'mode_html/ohms_law.html', {method:'get', asynchronous:true});return false;
  }else if(page == "led"){
    new Ajax.Updater('show_part', 'mode_html/led_tech_info.html', {method:'get', asynchronous:true});return false;
  }else if(page == "lead_free"){
    new Ajax.Updater('show_part', 'mode_html/led_free_sold.html', {method:'get', asynchronous:true});return false;
  }else if(page == "brushes"){
    new Ajax.Updater('show_part', 'mode_html/brushes1.html', {method:'get', asynchronous:true});return false;
  }else if(page == "soldering1"){
    new Ajax.Updater('show_part', 'mode_html/soldering1.html', {method:'get', asynchronous:true});return false;
  }else if(page == "sold_tech"){
    new Ajax.Updater('show_part', 'mode_html/soldering2.html', {method:'get', asynchronous:true});return false;
  }else if(page == "led_free_sold"){
    new Ajax.Updater('show_part', 'mode_html/led_free_sold.html', {method:'get', asynchronous:true});return false;
  }else
    return;  
}

function rohsinfoCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'mode_html/rohs_info.html', {method:'get', asynchronous:true});return false;
    return;  
}

function connCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'mode_html/connectors.html', {method:'get', asynchronous:true});return false;
    return;  
}

function toolsCall(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'mode_html/tools.html', {method:'get', asynchronous:true});return false;
    return;  
}

function distCall(where){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
  if(where == "ca"){
    new Ajax.Updater('show_part', 'mode_html/distributors_ca.html', {method:'get', asynchronous:true});return false;
  }else if(where == "us"){
    new Ajax.Updater('show_part', 'mode_html/distributors_us.html', {method:'get', asynchronous:true});return false;	
  }else
    return;
}

function stockClick(){
	var left = 160;
	if (screen.width>=1280){
 		left = 400;
	}
	else if (screen.width == 1024){
		left = 270;
	}
	else{
  		left = 160;
	}
	window.open('main/stock.php', null, 'width=610, height=210, status=1, scrollbars=1, resizable=0, top=170, left=' + left); return false
}

function numberClick(){
	var left = 160;
	if (screen.width>=1280){
 		left = 400;
	}
	else if (screen.width == 1024){
		left = 270;
	}
	else{
  		left = 160;
	}
	window.open('main/number.php?start=yes', null, 'width=570, height=145, status=1, scrollbars=0, resizable=0, top=170, left=' + left); return false
}

function indexClick(){
	indexWindow = window.open("mode_html/mode_index.html", "index", "width=209,height=545,status=no,scrollbars=yes,resizable=yes,toolbar=no,top=0,left=0");
	indexWindow.focus();
}

function catalogClick(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'mode_html/catalog.html', {method:'get', asynchronous:true});return false;
    return; 
}

function listClick(){
	var left = 160;
	if (screen.width>=1280){
 		left = 400;
	}
	else if (screen.width == 1024){
		left = 270;
	}
	else{
  		left = 160;
	}
	window.open('main/mnmsilt.php', null, 'width=610, height=210, status=1, scrollbars=1, resizable=0, top=170, left=' + left); return false
}

function userAdmin(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
    new Ajax.Updater('show_part', 'main/user_data.php', {method:'get', asynchronous:true, evalScripts:true});return false;
}

function listOrders(){
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'check/mylist.php', {method:'get', asynchronous:true, evalScripts:true});return false;
}

function showOrder(number){
	var pars = 'order_no=' + number;
	emptydiv('myplaceholder');
	emptydiv('myplaceholder2');
	positionShowPart('show_part');
    new Ajax.Updater('show_part', 'check/mydetails.php', {method:'get',parameters:pars, asynchronous:true, evalScripts:true});return false;
}	

function showPurchase(msg){

    if(msg.value.length > 300){
        alert("Comments can not be longer than 300 characters!");
        return;
    }
    var pars = 'comment=' + msg.value;
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'cart/purchase.php', {asynchronous:true, parameters:pars, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
}
function posProcess(){
    $('process').style.left = (screen.width - 100)/2;
    $('process').style.top = (screen.height - 18)/2 - 200;
}
function hideProcess(){
    $('process').style.visibility='hidden';
}
function showProcess(){
    $('process').style.visibility='visible';
}

function showReceipt(pararay){
    var tmpyear;
    year = pararay[4].value;
    if (year > 96)
        tmpyear = "19" + year;
    else if (year < 21)
        tmpyear = "20" + year;
    else {
        alert("The Expiration Year is not valid.");
    return;
    }
if(checkCreditCard(pararay[2].value, pararay[0].value)){
if(isExpiryDate(tmpyear, pararay[3].value)){
    var pars = 'ct=' + pararay[0].value + '&cnm=' + pararay[1].value + '&cn=' + pararay[2].value +  '&cm=' + pararay[3].value + '&cy=' + pararay[4].value;
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'cart/process.php', {onLoading:showProcess, asynchronous:true, parameters:pars, evalScripts:true, onComplete:hideProcess});return false;
	}
	}
}

function showReceipt2(jsarray){   // for Hosted Paypage

    var pars = 'order_id=' + jsarray[0] + '&date_stamp=' + jsarray[1] + '&time_stamp=' + jsarray[2] +  '&sequence_no=' + jsarray[3] + '&appr_code=' + jsarray[4] + '&iso_code=' + jsarray[5] + '&message=' + jsarray[6] + '&trtype=' + jsarray[7] + '&total_amount=' + jsarray[8] + '&txn_num=' + jsarray[9] + '&card=' + jsarray[10] + '&resp_code=' + jsarray[11] + '&cardholder=' + jsarray[12];

	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'cart/process2.php', {onLoading:showProcess, asynchronous:true, parameters:pars, evalScripts:true, onComplete:hideProcess});return false;

}
	

var changed;
var img_changed;
function markRow(el, u){
    var img_el = $(u);
	if(changed){
		changed.style.color = '#000000';
		img_changed.src = 'images/fw_bold.gif';
	}
	el.style.color = '#A32D23';
	img_el.src = 'images/fw_bold2.gif';
	changed = el;
	img_changed = img_el;
}
var changed2;
function markRow2(el){
	if(changed2){
		changed2.style.color = '#000000';
	}
	el.style.color = '#B43227';
	changed2 = el;
}
function unmarkRow2(){
	if(changed2){
		changed2.style.color = '#000000';
	}
	changed2 = null;
}

function firstStepClick(par){
	if(IsEmpty(par)){
		alert("Please enter your email address!");
	}else if(invalidEmail(par)){
		alert("The emal address you entered is not valid!");
	}else{
	var pars = 'mail=' + par.value + '&call=step1';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      checkEmail(originalRequest);
   }, asynchronous:true});
	}
}

function checkEmail(originalRequest){
	var msg = originalRequest.responseText;
	if(msg == 1){
		showPassForm();
	}else if(msg == 0){
		alert("Email address entered already used for registration. Use 'Forgot you password?' link to recover your password.");
	}else if(msg == 2){
		alert("There was database connection error. Please try again later.");

	}else{
		alert("Network error. Please try again.");
	}
}

function showPassForm(){
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/step1.php', {asynchronous:true, evalScripts:true});return false;
}

function showAddressForm(p_id){	
	if(verifyNewPass(p_id)){
		var par = 'ps=' + p_id[0].value;
		emptyandhidediv('myplaceholder');
		emptyandhidediv('myplaceholder2');
		positionShowPart('show_part');
		new Ajax.Updater('show_part', 'main/step2.php', {asynchronous:true, parameters:par, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
	}
}
function showAddressForm2(){	
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/step2.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
}

var fromMenu = 0;
function showChangeAddressForm(origin){
    if(origin == 1){
        fromMenu = 1;
    }else{
        fromMenu = 0;
    }	
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/change_address.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
}
function checkOrigin(){
    if(fromMenu == 1){
        userAdmin();
    }else{
        showCheckout();
    }
}

function verifyNewPass(p_id)
{
   if(IsEmpty(p_id[0])) 
   { 
      alert('Password not entered!'); 
      p_id[0].focus(); 
      return false; 
   }
   if (p_id[0].value.length < 6){
    alert("Password should be at least 6 character long!");
    p_id[0].focus();

    return false;
   }
   if (p_id[0].value.length > 12){
    alert("Password should not be longer than 12 characters!");
    p_id[0].focus();
    return false;
   }
   var okChar  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
   var entered = p_id[0].value;
   var valid = true;
   for (i = 0;  i < entered.length;  i++){
    c = entered.charAt(i);
    for (j = 0;  j < okChar.length;  j++)
      if (c == okChar.charAt(j))
        break;
    if (j == okChar.length)
    {
      valid = false;
      break;
    }
  }
  if (!valid)
  {
    alert("Only letters and digits are alowed in password!");
    p_id[0].focus();
    return false;
  }
   
   if(IsEmpty(p_id[1])) 
   { 
      alert('Please re-enter your password!'); 
      p_id[1].focus(); 
      return false; 
   }
   if(p_id[0].value != p_id[1].value){
   	  alert('Entered passwords do not match');
   	  return false;
   }
	
   return true; 
}

function register(el){	
	if(validAdInput(el)){
		if(el[14].checked){
			doRegistration(el);
		}else{
			showShipAddressForm(el);
		}
	}		
}

function checkpstnum(pstnum){
var re6digit=/^\d{6}$/ //regular expression defining a 6 digit number
if (pstnum.search(re6digit)== -1){ //if match failed	
	return false;
}else{
	return true;
}
}

function register2(el){
	if(validAdInput2(el)){	
		doRegistration2(el);
	}	
}

function showShipAddressForm(el){
	var pars = 'title=' + el[0].value + '&f_name=' + el[1].value + '&l_name=' + el[2].value + '&company=' + el[3].value + '&address=' + el[4].value + '&city=' + el[5].value + '&province=' + el[6].value + '&p_code=' + el[7].value + '&phone=' + el[8].value + '&ext=' + el[9].value + '&fax=' + el[10].value + '&po_no=' + el[11].value + '&pst_no=' + el[12].value + '&subscribed=' + el[13].checked + '&shipping_same=' + el[14].checked;
	//alert(pars);
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/step21.php', {asynchronous:true, parameters: pars, evalScripts:true});return false;
}

function backToAddressForm(){	
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/step2.php', {asynchronous:true, evalScripts:true});return false;
}

function updateAddress(el){
	if(validAdInput(el)){
	var pars = 'title=' + el[0].value + '&f_name=' + el[1].value + '&l_name=' + el[2].value + '&company=' + el[3].value + '&address=' + el[4].value + '&city=' + el[5].value + '&province=' + el[6].value + '&p_code=' + el[7].value + '&phone=' + el[8].value + '&ext=' + el[9].value + '&fax=' + el[10].value + '&po_no=' + el[11].value + '&pst_no=' + el[12].value + '&subscribed=' + el[13].checked + '&shipping_same=' + el[14].checked + '&call=updateAd';
	//alert(pars);
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onLoading: showLoading, onComplete: function(originalRequest) {
	  hideLoading();
      showUpdateMessage(originalRequest,el);
   }, asynchronous:true});
	}
}

function doRegistration2(el){
	var pars = 'title=' + el[0].value + '&f_name=' + el[1].value + '&l_name=' + el[2].value + '&company=' + el[3].value + '&address=' + el[4].value + '&city=' + el[5].value + '&province=' + el[6].value + '&p_code=' + el[7].value + '&phone=' + el[8].value + '&ext=' + el[9].value + '&call=step21';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showRegMessage(originalRequest);
   }, asynchronous:true});
}



function showUpdateMessage(originalRequest, el){
	if(el[14].checked){
		var msg = originalRequest.responseText;
		if(msg == 1){
			emptyandhidediv('myplaceholder');
			emptyandhidediv('myplaceholder2');
			positionShowPart('show_part');
			new Ajax.Updater('show_part', 'cart/checkout.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
		}
	}else if(!el[14].checked & el[15].value == 1 ){
		if(!confirm("Update Shipping Address too?")){
			var msg = originalRequest.responseText;
			if(msg == 1){
                if(fromMenu == 1){
                    userAdmin();
                }else{
				    emptyandhidediv('myplaceholder');
				    emptyandhidediv('myplaceholder2');
				    positionShowPart('show_part');
				    new Ajax.Updater('show_part', 'cart/checkout.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
				}
			}
		}else{
			var msg = originalRequest.responseText;
			if(msg == 1){
				emptyandhidediv('myplaceholder');
				emptyandhidediv('myplaceholder2');
				positionShowPart('show_part');
				new Ajax.Updater('show_part', 'main/change_existing_shipping.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
			}
		}
	}else{
			var msg = originalRequest.responseText;
			if(msg == 1){
				emptyandhidediv('myplaceholder');
				emptyandhidediv('myplaceholder2');
				positionShowPart('show_part');
				new Ajax.Updater('show_part', 'main/add_shipping.php', {asynchronous:true, evalScripts:true, onLoading: showLoading, onComplete:hideLoading});return false;
			}
	}		
		
}

function showShipAddressForm2(){
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	new Ajax.Updater('show_part', 'main/change_existing_shipping.php', {asynchronous:true, evalScripts:true});return false;
}

function updateExistingShipping(el){
	if(validAdInput2(el)){
	var pars = 'title=' + el[0].value + '&f_name=' + el[1].value + '&l_name=' + el[2].value + '&company=' + el[3].value + '&address=' + el[4].value + '&city=' + el[5].value + '&province=' + el[6].value + '&p_code=' + el[7].value + '&phone=' + el[8].value + '&ext=' + el[9].value + '&call=updateShipAd';
	//alert(pars);
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showShipUpdateMessage(originalRequest);
   }, asynchronous:true});
	}
}

function showShipUpdateMessage(originalRequest){
	var msg = originalRequest.responseText;
	if(msg == 1){
		alert("Shipping address updated succesfully!");
		if(fromMenu == 1){
		  userAdmin();
        }else{
		  emptyandhidediv('myplaceholder');
		  emptyandhidediv('myplaceholder2');
		  positionShowPart('show_part');
		  new Ajax.Updater('show_part', 'cart/checkout.php', {asynchronous:true, evalScripts:true});return false;
		}
	}
}

function insertNewShipping(el){
	if(validAdInput2(el)){
	var pars = 'title=' + el[0].value + '&f_name=' + el[1].value + '&l_name=' + el[2].value + '&company=' + el[3].value + '&address=' + el[4].value + '&city=' + el[5].value + '&province=' + el[6].value + '&p_code=' + el[7].value + '&phone=' + el[8].value + '&ext=' + el[9].value + '&call=insertShipAd';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showShipInsertMessage(originalRequest);
   }, asynchronous:true});
	}
}

function showShipInsertMessage(originalRequest){
	var msg = originalRequest.responseText;
	if(msg == 1){
	   if(fromMenu == 1){
          userAdmin();
       }else{
	      emptyandhidediv('myplaceholder');
		  emptyandhidediv('myplaceholder2');
		  positionShowPart('show_part');
		  new Ajax.Updater('show_part', 'cart/checkout.php', {asynchronous:true, evalScripts:true});return false;
	   }
	}
}

function validAdInput(el){
	if((Trim(el[1].value)).length == 0 || el[1].value == null){
		alert("Please enter your First Name!");
	}else if((Trim(el[2].value)).length == 0 || el[2].value == null){
		alert("Please enter your Last Name!");
	}else if((Trim(el[4].value)).length == 0 || el[4].value == null){
		alert("Please enter your Address!");
	}else if((Trim(el[4].value)).length > 60){
		alert("Address is too long. Must be 60 characters or less!");
	}else if((Trim(el[5].value)).length == 0 || el[5].value == null){
		alert("Please enter the name of your City!");
	}else if((Trim(el[7].value)).length == 0 || el[7].value == null){
		alert("Please enter your Postal Code!");
	}else if(!((Trim(el[7].value)).length == 0)){
		if(!isPostCode(Trim(el[7].value))){
			alert("Invalid Postal Code!");
		}else{
			return true;
		}
	}else if((Trim(el[8].value)).length == 0 || el[8].value == null){
		alert("Please enter your Phone Number!");
	}else if(!((Trim(el[12].value)).length == 0)){
		if(!checkpstnum(el[12].value)){
		alert("Please enter a valid Exemption Certificate Number.");
		}else{
			return true;
		}
	}else{
		return true;
	}
}

function validAdInput2(el){
	if((Trim(el[1].value)).length == 0 || el[1].value == null){
		alert("Please enter your First Name!");
	}else if((Trim(el[2].value)).length == 0 || el[2].value == null){
		alert("Please enter your Last Name!");
	}else if((Trim(el[4].value)).length == 0 || el[4].value == null){
		alert("Please enter your Address!");
	}else if((Trim(el[4].value)).length > 60){
		alert("Address is too long. Must be 60 characters or less!");
	}else if((Trim(el[5].value)).length == 0 || el[5].value == null){
		alert("Please enter the name of your City!");
	}else if((Trim(el[7].value)).length == 0 || el[7].value == null){
		alert("Please enter your Postal Code!");
	}else if(!((Trim(el[7].value)).length == 0)){
		if(!isPostCode(Trim(el[7].value))){
			alert("Invalid Postal Code!");
		}else{
			return true;
		}
	}else if((Trim(el[8].value)).length == 0 || el[8].value == null){
		alert("Please enter your Phone Number!");
	}else{
		return true;
	}
}

function emailPass(){
	var email = prompt("Please enter you email address", "");
	if(invalidEmail2(email)){
		alert("Email address entered is not valid!");
		emailPass();
	}
	var pars = 'email=' + email + '&call=sendEmail';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showEmailMessage(originalRequest);
   }, asynchronous:true});
}
function showEmailMessage(originalRequest){
	var msg = originalRequest.responseText;
	alert(msg);
}

function isPosInteger(inputVal) {
   inputStr = inputVal.toString()
   for (var i = 0; i < inputStr.length; i++) {
          var oneChar = inputStr.charAt(i)
         if (oneChar < "0" || oneChar > "9") {
              return false;
        }
   }
return true;
}

function changePass(){
	emptyandhidediv('myplaceholder');
	emptyandhidediv('myplaceholder2');
	positionShowPart('show_part');
	hideextradiv('extra');
	new Ajax.Updater('show_part', 'main/change_p.php', {asynchronous:true, evalScripts:true});return false;
}

function changePass2(pararay){
    if(IsEmpty(pararay[0].value)){ 
      alert('Old Password not entered!'); 
      pararay[0].focus(); 
      return false; 
    }
    if(verifyNewPass2(pararay)){
    var pars = 'p1=' + pararay[0].value + '&p2=' + pararay[1].value + '&p0=' + pararay[2].value + '&call=chp';
	new Ajax.Request('ajax_calls.php', {method: 'post', parameters: pars, onComplete: function(originalRequest) {
      showChpMessage(originalRequest);
   }, asynchronous:true});
   }
}
function showChpMessage(originalRequest){
    var msg = originalRequest.responseText;
    if(msg == 1){
        alert("Password successfully changed!");
        homeCall();
    }else if(msg == 3){
        alert("Old password is not correct!");
    }else if (msg == 4){
        alert("New password must be between 6 and 12 characters. Try again.");
    }else if (msg == 5){
        alert("Passwords enterd in new password fields were not the same!");
    }else{
        alert("Sorry, there is a problem connecting to database. Please try again later.");
        homeCall();
    }
}
function verifyNewPass2(p_id)
{
   if(IsEmpty(p_id[1].value)) 
   { 
      alert('Please enter your new password.'); 
      p_id[1].focus(); 
      return false; 
   }
   if (p_id[1].value.length < 6){
    alert("Your new password should be at least 6 character long!");
    p_id[1].focus();
    return false;
   }
   if (p_id[1].value.length > 12){
    alert("Your new password should not be longer than 12 characters!");
    p_id[1].focus();
    return false;
   }
   var okChar  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
   var entered = p_id[1].value;
   var valid = true;
   for (i = 0;  i < entered.length;  i++){
    c = entered.charAt(i);
    for (j = 0;  j < okChar.length;  j++)
      if (c == okChar.charAt(j))
        break;
    if (j == okChar.length)
    {
      valid = false;
      break;
    }
  }
  if (!valid)
  {
    alert("Only letters and digits are alowed in your new password!");
    p_id[1].focus();
    return false;
  }
   
   if(IsEmpty(p_id[2])) 
   { 
      alert('Please re-enter your new password!'); 
      p_id[2].focus(); 
      return false; 
   }
   if(p_id[1].value != p_id[2].value){
   	  alert('Passwords enterd in the new password fields were not the same');
   	  return false;
   }
	
   return true; 
}

function isPostCode(entry)	// CANADIAN CODES ONLY
{
entry = entry.replace(" ", "");
strlen=entry.length; if(strlen!=6) {return false;}
entry=entry.toUpperCase();    // in case of lowercase characters
// Check for legal characters in string - note index starts at zero
if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false;}
if('0123456789'.indexOf(entry.charAt(1))<0) {return false;}
if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false;}
if('0123456789'.indexOf(entry.charAt(3))<0) {return false;}
if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0) {return false;}
if('0123456789'.indexOf(entry.charAt(5))<0) {return false;}
return true;
}

function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function saveCookies(){
if(document.login_form.remember.checked == true){
    createCookie('me7432cookie', document.login_form.log_email.value, 180);
    createCookie('me7432cookie2', document.login_form.log_pass.value, 180);
}else{
    eraseCookie('me7432cookie');
    eraseCookie('me7432cookie2');	
}
}

function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}
var browser = new Browser();

function nothing(){}

// // Simple follow the mouse script
// copyright Stephen Chapman, 30th September 2005
// you may copy this script provided that you retain the copyright notice

var divName = 'loading_pr'; // div that is to follow the mouse
var offX = 15;         // X offset from mouse position
var offY = 15;         // Y offset from mouse position

// no changes required below this line
function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;} function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;} function follow(evt) {if (document.getElementById) {var obj = document.getElementById(divName).style; obj.visibility = 'hidden'; obj.left = (parseInt(mouseX(evt))+offX) + 'px';  obj.top = (parseInt(mouseY(evt))+offY) + 'px';}} document.onclick = follow;    
