PowerCreate = "";
ErrorWindow = "";
NortonNote = "";
Examples = "";
Mercial = "";

function textCounter(field,cntfield) {
	total = 0;
	numberofwords=0;
	var i=0;
	
	total = (field.value.length * 0.062) + 0;
	total = (Math.round(total * 100)) / 100;
	while(i<=field.value.length) {
		if (field.value.substring(i,i+1) == " ") {
			numberofwords++;
		}
		if (field.value.substring(i,i+1) == "\n") {
			numberofwords++;
		}
		i++;
	}
    total = total + (numberofwords * 0.062);
	cntfield.value = total.toFixed(1);
}


function pop_winPowerCreate(psjs_url){
    if(PowerCreate){
        if(PowerCreate.closed){
            PowerCreate = window.open("<%=ROOT_URL%>/Power_Create.asp", "PowerCreate", 
			"top=50,left=50,width=425,height=375,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
        } else { 
            PowerCreate.focus();
        }
    } else {
        PowerCreate = window.open("<%=ROOT_URL%>/Power_Create.asp", "PowerCreate", 
		"top=50,left=50,width=425,height=375,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
    }
}

function pop_winMercial(psjs_url){
    if(Mercial){
	    
        if(Mercial.closed){
            Mercial = window.open(psjs_url, "Mercial", 
			"top=50,left=50,width=800,height=425,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
			Mercial.document.close();
        } else { 
            Mercial.focus();
            Mercial.location.replace(psjs_url);
            Mercial.document.close();
        }
    } else {
        Mercial = window.open(psjs_url, "Mercial", 
		"top=50,left=50,width=800,height=425,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
		Mercial.document.close();
    }
}

function pop_winExample(psjs_url){
    if(Examples){
	    
        if(Examples.closed){
            Examples = window.open(psjs_url, "Examples", 
			"top=50,left=50,width=800,height=434,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
			Examples.document.close();
        } else { 
            Examples.focus();
            Examples.location.replace(psjs_url);
            Examples.document.close();
        }
    } else {
        Examples = window.open(psjs_url, "Examples", 
		"top=50,left=50,width=800,height=434,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
		Examples.document.close();
    }
}


function pop_winNortonNote(psjs_url){
    if(NortonNote){
        if(NortonNote.closed){
            NortonNote = window.open("<%=ROOT_URL%>/Norton_Note.asp", "NortonNote", 
			"top=50,left=50,width=425,height=260,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
        } else { 
            NortonNote.focus();
        }
    } else {
        NortonNote = window.open("<%=ROOT_URL%>/Norton_Note.asp", "NortonNote", 
		"top=50,left=50,width=425,height=360,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
    }
}

function pop_winErrorWindow_ItemID(psjs_url){
    if(ErrorWindow){
        if(ErrorWindow.closed){
            ErrorWindow = window.open("<%=ROOT_URL%>/Error_ItemID.asp", "ErrorWindow", 
			"top=50,left=50,width=425,height=225,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
        } else { 
            ErrorWindow.focus();
        }
    } else {
        ErrorWindow = window.open("<%=ROOT_URL%>/Error_ItemID.asp", "ErrorWindow", 
		"top=50,left=50,width=425,height=225,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
    }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isblank(s) {
	for(var i = 0; i < s.length; i++) {
	  var c = s.charAt(i);
	  if((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function verify(f) {
	var msg;
	var empty_fields = "";
	var errors = "";
	
	// Loop through the elements of the form, looking for all
	// text and textarea elements that don't have an "optional" property.
	// Can also use a "min" and "max" property.
	
	for (var i = 0; i < f.length; i++) {
		var e = f.elements[i];
		var vn = "";
		if(((e.type == "text") || (e.type == "textarea")) && !e.optional) {
			// Check if empty
			if((e.value == null) || (e.value == "") || isblank(e.value)) {
			    vn = e.name;
				if (e.vname != null) { vn = e.vname; }
				empty_fields += "\n	" + vn;
				continue;
			}
			
			// Check for numbers in numeric fields
			if(e.numeric || (e.min != null) || (e.max != null)) {
				var v = parseFloat(e.value);
				if(isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
					errors += "- The field " + vn + " must be a number";
					if(e.min != null) 
						errors += " that is greater than " + e.min;
					if(e.max != null && e.min != null)
						errors += " and less than " + e.max;
					else if (e.max != null)
						errors += " that is less than " + e.max;
					errors += ".\n";
				}
			}
		}
	}
	
	// Now we display the issues.
	
	if(!empty_fields && !errors) return true; // Guess what, Spock?  We all cool.  No doubt yo.
	
	msg =  "________________________________________________________________\n\n";
	msg += "Your data was not submitted due to the following error(s).\n";
	msg += "Please correct the error(s) and re-submit.\n";
	msg += "________________________________________________________________\n\n";
	
	if (empty_fields) {
		msg += "The following required fields are empty:" + empty_fields + "\n";
		if(errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}

function canAddCharacter(textarea, maxChars)
{
	if(typeof(textarea.onkeypress.arguments[0]) != 'undefined')
		var keyCode = textarea.onkeypress.arguments[0].keyCode;
	else
	{
		if(document.selection.createRange().text.length != 0) return true;
		var keyCode = event.keyCode;
	}

	var allowedChars = new Array(8, 37, 38, 39, 40, 46);	//Backspace, delete, arrow keys
	for(var x=0; x<allowedChars.length; x++) {
		if(allowedChars[x] == keyCode) {
			return true;
		}
	}
	
	if(textarea.value.length < maxChars) return true;

	return false;
}

function trimLength(textarea, maxChars)
{
	if(textarea.value.length <= maxChars) return;

	textarea.value = textarea.value.substr(0, maxChars)
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

var nW,nH,oH,oW;

function zoomToggle(iWideSmall,iHighSmall,iWideLarge,iHighLarge,whichImage){

	oW=whichImage.style.width;oH=whichImage.style.height;

	if((oW==iWideLarge)||(oH==iHighLarge)){
		nW=iWideSmall;nH=iHighSmall;
	} else{
		nW=iWideLarge;nH=iHighLarge;
	}

	whichImage.style.width=nW;whichImage.style.height=nH;
}

function confirmDelete()
{
var agree=confirm("Are you sure you wish to delete?");
if (agree)
	return true ;
else
	return false ;
}

function pop_winSample(url){
	var html = "<html><head><title>Play Sample</title></head><body><table><tr><td align=\"center\">";
	html += "<embed src=\""+url+"\" \"autostart=\"true\" volume=\"100\" width=\"144\" height=\"45\" controls=\"console\" align=\"top\">";
	html += "</td></tr><tr><td align=\"center\"><a href=\"javascript:window.close()\">Close</a></td></tr></table></body></html>";
	Sample_Window = window.open("", "Sample_Window", "top=50,left=50,width=175,height=82,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0");
	Sample_Window.document.write(html);
}
