// Copyright information must stay intact
// FormCheck v1.10
// Copyright NavSurf.com 2002, all rights reserved
// Creative Solutions for JavaScript navigation menus, scrollers and web widgets
// Affordable Services in JavaScript consulting, customization and trouble-shooting
// Visit NavSurf.com at http://navsurf.com

function formCheck(formobj){
	// name of mandatory fields
	var fieldRequired = Array("name", "area", "phone", "address", "city", "state", "email", "part", "serial");
	// field description to appear in the dialog box
	var fieldDescription = Array("Name", "Tel Area Code", "Telephone", "Address", "City", "State", "eMail", "Part Number", "Serial #");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea": 
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function swapImage1(imgFilename){
	var defaultImage = new Object();
	document.images["bigPhoto"].src = "http://www.datoptic.com/images/" + imgFilename;
} 


function swapImage(imgFilename){
	var defaultImage = new Object();
	document.images["bigPhoto"].src = "http://www.datoptic.com/images/" + imgFilename;
} 


function popup(url,features){
	var curPopupWindow;
	curPopupWindow = window.open(url, 'popupWindow', features, false);
	curPopupWindow.focus();
}

function swapImg(imgName)
		{
			if (imgName != null)
			{
				if (document.images)
			{
			var largeImgName = imgName.replace("S0", "L0")
			newImage = new Image()
			newImage.src = largeImgName
			window.document["largeImg"].src = newImage.src
			}
			}
		}


function GoTo(thisPage) {

     if((thisPage.substring(0,4) == "http")||

        (thisPage.substring(0,4) == "HTTP")){

          self.location = thisPage;

     } 

     else { 
          self.location = "%%web_site_url%%/" + thisPage;

     }

}

function goHist(a){

     history.go(a);

}

function OpenWindow(thisURL) {
	var myWin = window.open(thisURL,"pics",
     "toolbar=no,scrollbars=yes,resizable=no,width=500,height=500");
}

function viewCart(command){

var scriptName = "quikstore.cgi";
var linkURL = "http://www.avxstor.com/cgi-bin/web.cgi";
var task = "?view_cart=yes"
if(command == "checkout"){
     task = "?checkout=yes"
}
linkURL += task;

	var myLocation = unescape(document.location);
	myLocation = myLocation.substring(1).split('/');

     if(myLocation[myLocation.length - 1].substring(0,scriptName.length) == scriptName){

          // GET Requests
		var qsQuery = unescape(document.location.search.replace(/\+/g,' '));
        qsQuery = qsQuery.replace('?','&');
        qsQuery = qsQuery.replace("checkout=yes&",'');
        qsQuery = qsQuery.replace("view_cart=yes&",'');

          if(qsQuery.length > 1){
     		linkURL += qsQuery;
          }
          else{
               for(i = 0; i < document.forms[0].elements.length; i++){
                    var inType = document.forms[0].elements[i].type;
                    if(inType == "hidden"){
                         var fieldName = document.forms[0].elements[i].name;
                         var fieldValue = document.forms[0].elements[i].value;
                         if(fieldName == "view_cart"){
                            continue;
                         }
                         if(fieldName == "checkout"){
                            continue;
                         }
                         if(fieldValue != "shipping.html"){
                              qsQuery += "&" + fieldName + "=" + fieldValue;
                         }
                    }
               }
               linkURL += qsQuery;
          }
     }
     else{
          var PAGE = myLocation[myLocation.length - 1];
          linkURL += "&page=" + PAGE + "&store_type=html";
     }

document.location = linkURL;
}


function formReset(){
 for(a = 0; a < document.forms.length -1; a++){
   for(i = 2; i < document.forms[a].elements.length -1; i++){
     var inType = document.forms[a].elements[i].type;

     if(inType == "text"){
        document.forms[a].elements[i].value = "";
     }
     else if(inType == "select-one"){
        document.forms[a].elements[i].options[0].selected = true;
     }
     else if(inType == "radio"){
        document.forms[a].elements[i].checked = false;
     }
     else if(inType == "checkbox"){
        document.forms[a].elements[i].checked = false;
     }
   }
 }
}

function getCookie(name){
          // Simply retreives a cookie
          if((name == "")||(name == null)||(name == "undefined")){
               return null; 
          }
          var cname = name + "=";
          var dc = document.cookie;
          if (dc.length > 0) {
               begin = dc.indexOf(cname);
               if (begin != -1) {
                    begin += cname.length;
                    end = dc.indexOf(";", begin);
                    if (end == -1) end = dc.length;
                    return unescape(dc.substring(begin, end));
               }
          }
     return null;
     }
     function testCookie(){
          if(!getCookie('welcome')){
               alert("It appears that you do not have session cookies turned on " +
                     "in your browser? \n\n" +
                     "This web site uses temporary cookies to track your purchases " +
                     "while you are shopping with us. You must have session cookies " +
                     "enabled to be able to shop on our web site.\n\n" +
                     "These temporary cookies are NOT stored on your computer and will " +
                     "be deleted when you close your browser.");
          }
     }


