﻿var urlAddress = window.location.href;
var pageName = document.title;
var printContent = "";
var printTitle = "";

// used often
function confirmDelete()
{
    if (confirm("Are you sure you want to remove this record permanently? Doing so will remove all references to this record from the system. Note that this action cannot be undone.")==true)
        return true;
    else
        return false;
}

// used for triggering certain buttons on 'enter' press
function clickButton(key_1, key_2, btn) {
    if ((key_1 == 13) || (key_2 == 13)) {
        document.getElementById(btn).click();
        return false;
    } 
    else return true;
}


// for creating a cookie 
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 expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

// for reading from a cookie 
function readCookie(name) {
  var nameEQ = name + "=";
  
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//generateRandomString
function randomString(length, numeric) {
	var chars = "abcdefghiklmnopqrstuvwxyz";
	if (numeric)
	    chars = "0123456789";
	    
	var randomstring = '';
	for (var i=0; i<length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	
	return randomstring;
}


// copy to clipboard

function copyToClipboard(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="https://secure.virtualatlantic.com/common/scripts/clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}


var orig_vals = new Array();

$(document).ready(function() {

    // requires jQuery
    /* Contact and Submit Research form scripts */

    jFieldSetup('.j_first_name', "First Name");
    jFieldSetup('.j_last_name', "Last Name");
    jFieldSetup('.j_email_other', "Email Address");
    jFieldSetup('.j_contact', "Contact Number");
    jFieldSetup('.j_address1', "Address");
    jFieldSetup('.j_address2', "Address 2");
    jFieldSetup('.j_city', "City");
    jFieldSetup('.j_zip', "Zip");
    jFieldSetup('.j_message', "Enter Message");
    jFieldSetup('.j_email', "user@domain.com");
    jFieldSetup('.j_search', "Search Phrase");
    jFieldSetup('.j_email_repeat', "Confirm Email");
    jFieldSetup('.j_password', "Password");
    jFieldSetup('.j_login_email', "Email");
    jFieldSetup('.j_login_password', "Password");
    jFieldSetup('.j_email_forgot', "Email");
    jFieldSetup('.j_school_district', "School Name or District");
    jFieldSetup('.j_company', "Company/Organization");
    jFieldSetup('.j_state', "State/Province");
    jFieldSetup('.j_full_name', "Name");
    jFieldSetup('.j_size', "Audience Size");
    jFieldSetup('.j_strengths', "Information about your school or district");
    jFieldSetup('.j_notes', "Additional Notes About Services Desired");
    jFieldSetup('.j_title', "Title/Profession");
    jFieldSetup('.j_message2', "Additional Information");
    jFieldSetup('.j_quantity', "Quantity");
    jFieldSetup('.j_topic', "Topic / Area of Interest");
    jFieldSetup('.j_date', "Requested Date(s)");
    jFieldSetup('.j_speaker', "Requested Speaker(s)");
    jFieldSetup('.j_country', "Country");

    function jFieldSetup(_class, orig_val) {

        fields = $(_class);

        for (var i = 0; i < fields.length; i++) {
            field = fields[i];

            if (field.value == "") {
                field.value = orig_val;

            }
            orig_vals[_class] = orig_val;

            field.onfocus = function() {
                orig_val = orig_vals['.' + this.className];
                if (this.value == orig_val) {
                    this.style.color = "#000000";
                    this.value = "";
                }
            };

            field.onblur = function() {
                orig_val = orig_vals['.' + this.className];
                if (this.value == "") {
                    this.style.color = "#aaaaaa";
                    this.value = orig_val;
                }
            };
        }
    }
});

// check all checkboxes on page
function SetAllCheckBoxes(sender) {

    re = new RegExp(sender.id);

    for (i = 0; i < document.forms[0].elements.length; i++) {

        elm = document.forms[0].elements[i]

        if (elm.type == 'checkbox') {

            if (re.test(elm.name)) {

                elm.checked = sender.checked;

            }
        }
    }
}

// JQUERY Textbox CHAR LIMIT / Counter


    function limitChars(textarea, limit, infodiv) {
        var text = textarea.val();

//      var limit = textarea.attr("maxlength"); 
       
        var textlength = text.length;

        var info = document.getElementById(infodiv);

        if (textlength > limit) {
            $('#' + infodiv).html('You cannot write more then ' + limit + ' characters!');

            textarea.val(text.substr(0, limit));

            return false;
        }
        else {
            $('#' + infodiv).html('You have ' + (limit - textlength) + ' characters left.');

            return true;
        }
    }
    
    
    
// non modal popup    
    function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=100,left = 690,top = 475');");
}

function openPrintable(key) {
    popup = window.open("../products/receipt.aspx?key=" + key, "popup", "width=800,height=600,scrollbars=yes,menubar=yes");
}
    
function openPopup(url, width, height) {
    popup = window.open(url, "popup", "width=" + width + " ,height=" + height + ",scrollbars=yes,menubar=yes");
} 









