﻿// JScript File

<!--// Hide from old browsers

// Removes leading whitespaces
function LTrim( value ) {
var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {    return LTrim(RTrim(value)); }

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func){	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

//
// getPageScroll()
// Returns page scroll values array (x,y) .
// Revised code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


//
// getPageSize()
// Returns page width, height array
// Revised code from - quirksmode.org
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function CheckNameValidate(oSrc, args){
    
    //get text boxes for first and last name
    var txtfname = document.getElementById("ctl00_cphMainContent_txtFirstName");
    var txtLname = document.getElementById("ctl00_cphMainContent_txtLastName");
    
    if (txtfname && txtLname){        
        //validate input
        args.IsValid = (txtfname.value.length == 0 && txtLname.value.length == 0 )?false:true;
    }
}  

function isNumeric(){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e){ keycode = e.which; }
    else return true;

    //var key = String.fromCharCode(keycode);
    return ((keycode >= 48 && keycode <= 57) || keycode == 8 || keycode == 9 || keycode == 17   || keycode == 46 || (keycode >= 96 && keycode <= 105) || keycode == 13 )?true:false; 

}


function getaBanner()
{
   var whichBanner=get_random();

    var Banner=new Array(5)
     Banner[0]="http://images.myregistry.com/addgift/Images/AddGiftEcards.jpg";
     Banner[1]="http://images.myregistry.com/addgift/Images/AddGiftAmex.jpg";
     Banner[2]="http://images.myregistry.com/addgift/Images/AddGiftStores.jpg";   
     Banner[3]="http://images.myregistry.com/addgift/Images/AddGiftCashGifts.jpg";
     Banner[4]="http://images.myregistry.com/addgift/Images/AddGiftStores.jpg";

    return Banner[whichBanner];
  }


function get_random()
{
    var ranNum= Math.floor(Math.random()*5);
    return ranNum;
}

function ShowPanel(id){
    var panel = document.getElementById(id);
    panel.style.visibility = "visible";
}

function HidePanel(id){
    var panel = eval(document.getElementById(id));
    panel.style.visibility = "hidden";
}

//
//  Disable unwanted key characters
//
document.onkeypress = NotesKeyPress;
function NotesKeyPress(e){
   
    try{    
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e){ keycode = e.which; }
        else return true; 

        return (keycode == 60 || keycode == 62 || keycode == 13 )?false:true; 
    }
    catch(err){
        
    }

}

// addLoadEvent(getCoords);	// register getCoords with stratup fuctions
function showNotification(message){

    var objBody = document.getElementsByTagName("body").item(0);
    
    var objSearchBox = document.createElement("div");
    objSearchBox.setAttribute('id','notification');  
    objSearchBox.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-left:none; border-top:none; border-bottom:solid 2px #666666; border-right:solid 2px #666666;\">" + 
    "<tr><td align=\"left\" valign=\"top\">" + 
    "<table cellpadding=\"4\" cellspacing=\"0\" width=\"100%\" style=\"border:solid 2px #cccccc;\" class=\"warningtxt\">" +
    "<tr><td align=\"left\">" + message + "</td></tr><tr><td align=\"left\">" +
    "<a href=\"javascript:hideNotificationError();\" title=\"OK\"><img border=\"0\" alt=\"OK\" src=\"Images/MyRegistry/Members/Buttons/bok.jpg\"" + 
    "onmouseover=\"this.src = this.src.replace(/.jpg/,'Over.jpg');\" onmouseout=\"this.src = this.src.replace(/Over.jpg/,'.jpg');\" />" + 
    "</a></td></tr></table></td></tr></table>";
    
    objBody.insertBefore(objSearchBox, objBody.firstChild);      
}

function hideNotificationError(){
    var objBody = document.getElementsByTagName("body").item(0);
    var objSearchBox = document.getElementById("notification");
    objBody.removeChild(objSearchBox);
}

function showToolTip(message){

    var objBody = document.getElementsByTagName("body").item(0);
    
    var objSearchBox = document.createElement("div");
    objSearchBox.setAttribute('id','notification');  
    objSearchBox.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-left:none; border-top:none; border-bottom:solid 2px #666666; border-right:solid 2px #666666;\">" + 
    "<tr><td align=\"left\" valign=\"top\">" + 
    "<table cellpadding=\"8\" cellspacing=\"0\" width=\"100%\" style=\"border:solid 2px #cccccc;\">" +
    "<tr><td align=\"left\">" + message + "</td></tr></table>";
    
    objBody.insertBefore(objSearchBox, objBody.firstChild);      
}

function hideToolTip(){
    var objBody = document.getElementsByTagName("body").item(0);
    var objSearchBox = document.getElementById("notification");
    objBody.removeChild(objSearchBox);
}


function DisplayPan(){
 
    var objPnlNotify = document.getElementById('ctl00_cphMainContent_checkoutNotify');
    objPnlNotify.style.visibility = "visible"
   // alert("objPnlNotify")
   return false;
   
}

function checkmultiEmails(emails) {
var email = emails.split(',');
for (var i = 0; i < email.length; i++) {
if (!checkEmail(email[i])) {
return false;
break;
}
}
return true;
} 


function checkEmail(email) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) {
return false;
}
else
{
return true;
}
}


//-->

