function ValidateEmail(email) {
	var rx = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
	var matches = rx.exec(email);
	return (matches != null && email == matches[0]);
}
function Trim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
/*
Keep the user's cookie alive
*/
function MakeKeepAliveRequest(){
	if (!KeepAliveUrl)
		return;
	if (KeepAliveTimer != null)
		window.clearTimeout(KeepAliveTimer);
	var x = null;
	if (typeof XMLHttpRequest != "undefined") {
		x = new XMLHttpRequest();
	} 
	else {
		try {
			x = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				x = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {
			}
		}
	}	
	try{
		// don't do this asynchronously
		x.open("GET", KeepAliveUrl, false, "", "");
		x.send(null);
	}
	catch (e){
	}
	KeepAliveTimer = window.setTimeout(MakeKeepAliveRequest, 599999);
}
var KeepAliveUrl = "/KeepAlive.aspx";
var KeepAliveTimer = window.setTimeout(MakeKeepAliveRequest, 599999);
function OpenCertDetails(){
    thewindow =window.open('https://seal.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&dn=WWW.ISRAEL-DIAMONDS.COM&lang=en', 'anew','height=620,width=540,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
	thewindow.focus();
}
function Nothing(){}
var commonIsIE = (document.all) ? 1 : 0;
function ClickButtonWhenEnterKeyPress(e, btnID){
    var chr = (commonIsIE) ? e.keyCode : e.which;
    var ch = String.fromCharCode(chr);
    if (chr == 13){//Enter key was pressed
        //click wanted button
        if(btnID != ''){
            if(commonIsIE){
                document.getElementById(btnID).click();
            }
            else{
                document.getElementById(btnID).onclick();
            }
        }
        //prevent default button click
        if(commonIsIE){
            e.returnValue = false;
        }
        else{
            e.preventDefault();
        }
    }
}
function RaiseControlClick(control){
    document.getElementById(control).click();
}
function IsArrowKeyPress(e){
    var chr = (commonIsIE) ? e.keyCode : e.which;
    var ch = String.fromCharCode(chr);
    return (chr >= 33 && chr <= 40)
}
//See: http://bytes.com/topic/javascript/answers/598383-how-display-textarea-value-span-innerhtml-br-netscape
function GetTextareaLines(s, alternativeLine){
    return s.
    replace(/&/g, "&amp;").
    replace(/</g, "&lt;").
    replace(/>/g, "&gt;").
    replace(/\r\n/g, alternativeLine).
    replace(/\r/g, alternativeLine).
    replace(/\n/g, alternativeLine);
}
function SearchSiteBoxSearch(txtSearchSite){
    if(document.getElementById(txtSearchSite).value != '')
        window.location = '/Search/Site/Default.aspx?q='+document.getElementById(txtSearchSite).value.replace(/ /g, '+');
}
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function GetViewportWidth(){//see: http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
    var viewportwidth;        
    if (typeof window.innerWidth != 'undefined'){// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        viewportwidth = window.innerWidth
    }
    else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth !=
        'undefined' && document.documentElement.clientWidth != 0){// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        viewportwidth = document.documentElement.clientWidth
    }
    else{// older versions of IE
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth
    }//alert('viewportwidth:'+viewportwidth)
    return viewportwidth;
}
function GetViewportHeight(){//see: http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
    var viewportheight;        
    if (typeof window.innerWidth != 'undefined'){// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        viewportheight = window.innerHeight
    }
    else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth !=
        'undefined' && document.documentElement.clientWidth != 0){// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        viewportheight = document.documentElement.clientHeight
    }
    else{// older versions of IE
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }//alert('viewportheight:'+viewportheight)
    return viewportheight;
}
//OpenChat - start
//function IsLPChatAvailable(){}
var lpXmlhttp
function OpenChat(btnNum){
    if(navigator.appVersion.match("MSIE") == null &&
        navigator.appVersion.match("Chrome") == null){//needed for safari+ff+opera
        var hw;
        hw=window.open('/Tracking/chat.aspx?btn=' + btnNum + '&amp;loc='+escape(document.location),
                    'chat10723326',
                    'width=495,height=422');
        hw.focus();
    }
    else{
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            lpXmlhttp=new XMLHttpRequest();
        }
        else{// code for IE6, IE5
            lpXmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        lpXmlhttp.onreadystatechange=function(){
                if (lpXmlhttp.readyState==4 && lpXmlhttp.status==200){
                    _OpenChat(btnNum, lpXmlhttp.responseText);
                }
            }
        lpXmlhttp.open("GET","/XmlHttp/IsLPChatAvailableXmlHttp.aspx",true);
        lpXmlhttp.send();
    }
}
function _OpenChat(btnNum, isLPChatAvailable){
    var hw;
    if(isLPChatAvailable == 'true'){
        hw=window.open('/Tracking/chat.aspx?btn=' + btnNum + '&amp;loc='+escape(document.location),
            'chat10723326',
            'width=472,height=320');
    }
    else{
        hw=window.open('/Tracking/VChat.aspx?btn='+btnNum+'&amp;loc='+escape(document.location),
            'chat',
            'width=495,height=422');
    }
    hw.focus();
}
//OpenChat - end
function AddToDebugSpan(val, seperator){
    document.getElementById('spanDebug').innerHTML += seperator + val;
}
function ClearDebugSpan(){
    document.getElementById('spanDebug').innerHTML = '';
}
//AddToDebugSpan(':'+, '<br/>')<input type="button" onclick="ClearDebugSpan();" value="Clear" /><span id='spanDebug'></span>
