﻿function validNumberSpace(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }
    if ((keyCode < 48 || keyCode > 57) && (keyCode < 96 || keyCode > 105) && TestForSystemKeys(keyCode) == false && keyCode != 32 && keyCode != 8 && keyCode != 127 && keyCode != 188 && keyCode != 190 && keyCode != 9) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function validNumber(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }

    if ((keyCode < 48 || keyCode > 57) && (keyCode < 96 || keyCode > 105) && TestForSystemKeys(keyCode) == false && keyCode != 188 && keyCode != 189 && keyCode != 190) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function validInteger(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }
    if ((keyCode < 48 || keyCode > 57) && (keyCode < 96 || keyCode > 105) && TestForSystemKeys(keyCode) == false && keyCode != 188 && keyCode != 189 && keyCode != 190) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function validAlphaNumber(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }
    if ((keyCode < 9 || keyCode > 200) && TestForSystemKeys(keyCode) == false) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function validAlphaOnly(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }
    if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 122) && TestForSystemKeys(keyCode) == false) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function validDate(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : keyStroke.keyCode;
    if (keyCode == 13) {
        document.returnValue = false;
    }
    if ((keyCode < 48 || keyCode > 57) && keyCode != 191 && TestForSystemKeys(keyCode) == false) {
        document.returnValue = false;
        return false;
    }
    document.returnValue = true;
}
function TestForSystemKeys(keyCode) {
    //checks for all system keys in one place.
    window.status = '';
    switch (keyCode) {
        case 37: // right cusror
            return true;
            break;
        case 38: // left cursor
            return true;
            break;
        case 8: // delete
            return true;
            break;
        case 46: // backspace
            return true;
            break;
        case 9: //  tab
            return true;
            break;
        default:
            window.status = 'input not valid';
            return false;
            break;
    }
}


function isEmail(email){
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(email))
	return true
  else{
	return false
  }
} 

function sendEmail (email) {
	window.location='mailto:'+email;
}

function openWebPage(url) {
	window.open(url);
}

function printPreview()
{ 
	var browser=navigator.appName;
	if (browser == 'Microsoft Internet Explorer' || browser=='MSIE')
	{
		var OLECMDID = 7; 
		var PROMPT = 1; // 2 DONTPROMPTUSER 
		var WebBrowser= '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(OLECMDID, PROMPT);
		WebBrowser1.outerHTML = ""; 
	} else {	 
		 window.print();
	}
}

function isNumeric(strTest)
{
	var NumericRegExp = /^\d+$/;
	var regex = new RegExp(NumericRegExp);
	return (regex.test(strTest));
}

function BlendOpacity(id, opacStart, opacEnd, millisec) {
	// Speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;


	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("SetOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++){
			setTimeout("SetOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function SetOpacity(opacity, id) {
	if (document.getElementById(id) == null)
		return false;
	
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

  var strSoftHyphen = (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1 || document.all) ? "&shy;" : "<wbr/>"; // use soft-hyphen for IE and Opera which are known to implement it correctly
      
  function SoftWrap(str, maxcolumns) {
    // these regular expressions need to incorporate variables (function params), so cant be static properties of the function, to save a few operations in repeated use
    var wordspaceRe = new RegExp('^\\w{1,' + maxcolumns + '}\\s+');
    var punctuationRe = new RegExp('^[!\\._\\-\\\\\,=\\*]{1,' + maxcolumns + '}');

    var wrapstr = "";
    var charCount = 0;
    while(str.length) {
      var endidx = 1;
      // shortcut if there's less remaining characters than the maxcols
      if(str.length < maxcolumns) {
        wrapstr += str; 
        break;
      }
      // look ahead for space characters
      var spaceMatches = str.match(wordspaceRe);
      if(spaceMatches && spaceMatches[0]) {
        endidx = spaceMatches[0].length;
        wrapstr += str.substring(0, endidx); 
        str = str.substring(endidx);
        charCount = 0; // reset 
        continue;
      } else {
        // handle markup
        if(str.charAt(0) == "<" && str.indexOf(">") > -1) {
          endidx = str.indexOf(">");
          charCount++; // count as one character
        } else if( str.charAt(0) == "&" && str.match(/^&\w+;/) ) { // handle entities
          endidx = (str.indexOf(";") > -1) ? str.indexOf(";") +1 : str.length;
          charCount++; // count as one character
        } else { 
          var puncMatches = str.match(punctuationRe);
          if(puncMatches && puncMatches[0]) {
            // handle punctuation
            endidx = puncMatches[0].length;
            charCount += endidx; // count as one character
          } else {
            charCount++; // default case is just one character
          }
        }
      }
      wrapstr += str.substring(0, endidx);
  
      if(charCount >= maxcolumns) {
        wrapstr += strSoftHyphen;
        charCount = 0;
      }
      str = str.substring(endidx);
    }
    return wrapstr;
  }
  
  function SuperSizeMe(strUrl)
  {
	tb_show('Image', strUrl, false);
	}
  
function AddRollovers()
{
	$("img.rollover").mouseover(function () { var strExtension = (this.src.indexOf('jpg')>-1)?'.jpg':'.gif';this.src = 'images/buttons/' + this.id + '_over' + strExtension;})
	$("img.rollover").mouseout(function () { var strExtension = (this.src.indexOf('jpg')>-1)?'.jpg':'.gif';this.src = 'images/buttons/' + this.id + strExtension; })
}

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 {
	    var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function clearFrmItem(item,defaultVal) {
    if (item.value == defaultVal) {
        item.value = '';
    }
}

function setFrmItem(item,defaultVal) {
    if (item.value == '') {
        item.value = defaultVal ;
    }
}
function Toggle(strElem, strImgElem) {
	var oElem = document.getElementById(strElem);
	var oImg = document.getElementById(strImgElem);
	
	if (document.getElementById(strElem).style.display=='none'){
		oElem.style.display='block';
		oImg.src='Images/Icons/Contract.gif';
		createCookie(strElem,'block',30);
	}else{
		oElem.style.display='none';
		oImg.src='Images/Icons/Expand.gif';
		createCookie(strElem,'none',30);
	}
}

function ShowPopupBasket()
{
	var iFrame = document.getElementById('popupBasketIFrame');
	iFrame.height = 550;
	iFrame.src = 'basket.aspx?BasketPreview=true&detail=true';
	
	tb_show('Basket', 'TB_inline?height=600&width=770&inlineId=popupBasket', null);
}
