<!--

// ********** GENERAL FUNCTIONS ********* \\

function addBookMark(){
	if(!window.external){
		alert('Your browser does not support automatically adding bookmarks.\nPlease press Ctrl+D or go to Bookmarks -> Bookmark This Page');
	}
	else{
		window.external.AddFavorite('http://www.awsinternet.com', 'AWS Internet')
	}
}

function windowWidth(){
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	}
	else if(document.documentElement && document.documentElement.clientWidth){
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	else if(document.body && document.body.clientWidth){
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

function openWindow(pageLoc,pageName,winWidth,winHeight) {
	window.open(pageLoc,pageName,'top=0,left=0,width=' + winWidth + ',height=' + winHeight + ',scrollbars=yes,menubar=yes,resizable=yes');
}

// ****** IMAGE-RELATED FUNCTIONS ****** \\

function swapImage(newImage){
	document.getElementById('mainImage').src = newImage;
}

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];}
}

// ****** END IMAGE-RELATED FUNCTIONS ****** \\

// ********** DIV-RELATED FUNCTIONS ******** \\

function showSummaryDiv(divID){

	var currentDiv = divID;
	document.getElementById(divID).style.display = '';
	document.getElementById(divID).style.position = 'absolute';
}

function hideSummaryDiv(divID){
	document.getElementById(divID).style.display = 'none';
}


function ShowHideDiv(divId){
	if(document.getElementById(divId).style.display=='none'){
		document.getElementById(divId).style.display = '';
	}
	else{
		document.getElementById(divId).style.display = 'none';
	}
}

function HideDiv(divId){
	document.getElementById(divId).style.display = 'none';
	return true;
}

function ShowDiv(divId){
	document.getElementById(divId).style.display = '';
	return true;
}

function ShowHideParentDiv(divId){
	if(parent.document.getElementById(divId).style.display=='none'){
		parent.document.getElementById(divId).style.display = '';
	}
	else{
		parent.document.getElementById(divId).style.display = 'none';
	}
}

var scrollIncrement = 20;
var divTop = 0;

function scrollDivUp(divID){
	if(divTop!=0){
		divTop = divTop + scrollIncrement;
		document.getElementById(divID).style.top = divTop;
	}
}

function scrollDivDown(divID){
	divTop = divTop - scrollIncrement;
	document.getElementById(divID).style.top = divTop;
}

function ShowHideDiv(divId){

	lastDiv = divId;
	if(document.getElementById(divId).style.display=='none'){
		document.getElementById(divId).style.display = '';
	}
	else{
		document.getElementById(divId).style.display = 'none';
	}
}

// ********** END DIV-RELATED FUNCTIONS ********** \\

// ***** GENERAL FORM VALIDATION FUNCTIONS ***** \\

function validateString(stringToTest,stringType,canBeEmpty,imgIdToChange){
      
	re = /^$/;
	if(canBeEmpty==true && stringToTest==''){
		if(imgIdToChange!=''){
			document.getElementById(imgIdToChange).src = 'images/form_valid.gif';
		}
		return true;
	} //RESERVE stringType=='def' for DEFAULT
      if(stringType=='pas'){ //password
		re = /^\w{6,16}$/;
	}
      else if(stringType=='usr'){ //username
		re = /^[\ a-zA-z]{6,64}$/;
	}
      else if(stringType=='eml'){ //email
	 	re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      }
      else if(stringType=='mem'){ //multiple email address like the TO: Field on send email forms
	 	re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/;
      }
      else if(stringType=='phn'){ //phone
		re = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	}
      else if(stringType=='zip'){ // zip code (includes "-" and space, for postal codes like Canada ("XJ4 5E5")
		re = /^[A-Za-z0-9\ \-]+$/;
	}
      else if(stringType=='url'){ //url
		re = /^(?:(?:ftp|https?):\/\/){1}(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|mobi|tv|us|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
	}
      else if(stringType=='hmt'){ //homeType
		re = /^[A-Za-z0-9\ \.\-_\(\)\,&]+$/;
	}
      else if(stringType=='num'){ //regular integer
		re = /^[0-9]+$/;
	}
	  else if(stringType=='flt'){ //floats (like "2.5")
		re = /^[0-9]+(\.[0-9]+)?$/;
	}
      else if(stringType=='ltx'){ //Link text (text inside <a href>link text</a>)
		re = /^[A-Za-z0-9\ \.\-_\(\)\,&!\?]+$/;
	}
      else if(stringType=='gen'){ //general check
		re = /^[A-Za-z0-9\ \.\-_\(\)\,&!\?;\']+$/;
	}
	  else if(stringType=='alp'){ //alphabetical (with spaces)
		re = /^[A-Za-z\ ]+$/;
	}
      else if(stringType=='aln'){ //alphanumeric (no spaces)
		re = /^[A-Za-z0-9]+$/;
	}
      else if(stringType=='als'){ //alphanumeric (with spaces)
		re = /^[A-Za-z0-9\ ]+$/;
	}
      else {
      	re = /^[A-Za-z0-9\ \.\-_\(\)\,]+$/;
      }
	
	goodString = false;

	goodString = re.test(stringToTest);
	if(goodString){
		if(imgIdToChange!=''){
			document.getElementById(imgIdToChange).src = 'images/form_valid.gif';
		}
		return true;
	}
	else{
		if(imgIdToChange!=''){
			document.getElementById(imgIdToChange).src = 'images/form_not_valid.gif';
		}
		return false;
	}
}

function validateForm(formName){
      
      var obj = document.forms[formName]
      deleting = false;
      delre = /delete/;  //re for delete check box
      
      for (i=0; obj.elements[i]; i++) {
            
            currentElement = obj.elements[i].name;
            currentValue = obj.elements[i].value;
            isValid = true;
            
            if(delre.test(currentElement)){
                  if(obj.elements[i].checked==true){
                        deleting = true;
                  }
            }
            
            if(currentElement.substr(3,2)=='t_' || currentElement.substr(3,2)=='f_'){
                  stringType = currentElement.substr(0,3);
                  canBeEmpty = currentElement.substr(3,1);
                  
                  if(canBeEmpty=='t'){
                        canBeEmpty = true;
                  }
                  else if(canBeEmpty=='f'){
                        canBeEmpty = false;
                  }
                  isValid = validateString(currentValue,stringType,canBeEmpty,'');
            }
            
            if(!isValid){
                  alert('"' + currentValue + '" is not a vaid entry for this field.\nYou will need to fix this before continuing. ');
                  obj.elements[i].focus();
                  obj.elements[i].className='formElementError';
                  return false;
                  break;
            }
            else{
                  obj.elements[i].className='';
            }
      }
      
      if(deleting==true){
            return confirm('You have objects selected for deletion.\n This cannot be undone!\n Are you sure you wish to continue?');
      }
      return true;
}

// *** START Payment calculator functions **** \\

function checkForm(form)
{
    if (form.price.value == 0 || form.price.value.length == 0) {
        alert ("The Price field can't be 0!");
        form.price.focus(); 
		return false;
	}
	else if (form.price.value.indexOf(",") != -1) {
		alert("Price field should not contain commas for computing");
		form.price.focus(); 
		return false;
	}
	else if (form.dp.value.indexOf(",") != -1) {
		alert("Down Payment field should not contain commas for computing");
		form.dp.focus(); 
		return false;
	}

    else if (form.ir.value == 0 || form.ir.value.length == 0) {
        alert ("The Interest Rate field can't be 0!");
        form.ir.focus(); 
		return false;
	}
    else if (form.term.value == 0 || form.term.value.length == 0) {
        alert ("The Term field can't be 0!");
        form.term.focus(); 
		return false;
	}
    else {
        calculatePayment(form);
		return true;
	}
}

function calculatePayment(form)
{
	princ = form.price.value - form.dp.value;
    intRate = (form.ir.value/100) / 12;
    months = form.term.value * 12;
    form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
    form.principle.value = princ;
    form.payments.value = months;
}
// *** END Payment calculator functions **** \\

//-->

