//error handeling - kobi
function defaultHandler() {return false}
function silentHandler()  {return true}
function customHandler(desc,page,line,chr)  {
 alert(
 '\nError description: \t'+desc
 +'\nPage address:      \t'+page
 +'\nLine number:       \t'+line
 )
 return true
}
window.onerror=defaultHandler;

function getXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
    }
    else {
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch (ex) {
            return null;
        }
    }
}
// Validations
function ValNotEmpty(o, s) {
	if (o.length==0) { alert(s); return true; } else { return false; }
}
function ValEqual(o1, o2, s) {
	if (!(o1==o2)) { alert(s); return true; } else { return false; }
}
function ValNum(o, s) {
	if (isNaN(o)) { alert(s); return true; } else { return false; }
}
function ValEmail(o, s) {
	if (!ValidateEmail(o)) { alert(s); return true; } else { return false; }
}
function ValidateEmail(str) {
	var filter=/^.+@.+\..{2,3}$/
	return filter.test(str);
}
//validation username - minimum 4 letter
function isUserNamevalidLength(o, s){
    if ((o.length < 4) || (o.length > 10)) 
        {
            alert(s);
            return false;
        } 
        
    else { return true; }
}
//validation username2 - no spaces
function isUserNamevalidChars(o,s){
    var str = o.indexOf(" ") 
    if (str == -1)
	    {
	    return true;
	    }
    else 
	    {
		    alert(s)
		    return false;
	    }
}


function setselect(a, str) {
	if (a)
	{
		for (i=0; i<a.length; i++) 
			if (a[i].value == str) 
				a.selectedIndex = i
	}
}

function setmselect(a, str) {
	if (a)
	{
		for (i=0; i<a.length; i++) 
			if (a[i].value == str) 
				a[i].selected = true;
	}
}

function changeV(tr)
{
	if(document.getElementById(tr).style.display == "none")
		document.getElementById(tr).style.display = "block";
	else
		document.getElementById(tr).style.display = "none";
}

function iFrameHeight(ifrname){
	var minHeight = 200;
	h = document.getElementById(ifrname).document.body.scrollHeight;
	if (h > minHeight) {
		document.getElementById(ifrname).height = h;
	} else {
		document.getElementById(ifrname).height = minHeight;
	}
}

function OpenHelp(nHelp) {
	var winid;
	var winw = 640;
	var winh = 480;
	var x = (screen.width - winw) / 2;
	var y = (screen.height - winh) / 2;
	winid = window.open (app_root_dir + '/help_item.asp?hid='+nHelp, 'helptopic', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height='+winh+',width='+winw+',left='+x+',top='+y);
	winid.focus();
}

function myround(n, d) {
	var x = Math.round(n * Math.pow(10, d)) / Math.pow(10, d);
	var sign = (x < 0);
	if (sign) { x *= -1; }
	var s = x + '';
	if (s.indexOf('.') == -1) s += '.';
	var l = s.length;
	var p = s.indexOf('.');
	for (var i=0;i<=d-l+p;i++) { s += '0'; }
	//p = s.indexOf('.');
	//while (p > 3) { p -= 3; s = s.substr(0, p) + ',' + s.substr(p, 1000); }
	if (d == 0) { s = s.replace('.',''); }
	if (sign) { s = '-' + s; }
	return parseFloat(s);
} 

function myformat(n, d) {
	var x = Math.round(n * Math.pow(10, d)) / Math.pow(10, d);
	var sign = (x < 0);
	if (sign) { x *= -1; }
	var s = x + '';
	if (s.indexOf('.') == -1) s += '.';
	var l = s.length;
	var p = s.indexOf('.');
	for (var i=0;i<=d-l+p;i++) { s += '0'; }
	p = s.indexOf('.');
	while (p > 3) { p -= 3; s = s.substr(0, p) + ',' + s.substr(p, 1000); }
	if (d == 0) { s = s.replace('.',''); }
	if (sign) { s = '-' + s; }
	return s;
} 

function popLogin(){
	var winid;
	var winw = 500;
	var winh = 400;
	var x = (screen.width - winw) / 2;
	var y = (screen.height - winh) / 2;
	winid = window.open (app_root_dir + '/popLogin.asp', 'PopLogin', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height='+winh+',width='+winw+',left='+x+',top='+y);
	winid.focus();
}

function PutInDiv(strDivId,str) {
	document.getElementById(strDivId).innerHTML = str;
}

function changeLang(newLang, LCID) {
	var url = window.location.href;
	var idx = url.indexOf("?");
	var idx2 = url.indexOf("newLang=");
	var hStr 
	if (idx > -1) {
		if (idx2 > -1) {
			hStr = window.location.href.substring(0, idx2);
		} else {
			hStr = window.location.href + '&';
		}
		window.location.href = hStr + 'newLang=' + newLang + '&LCID=' + LCID;
	} else {
		window.location.href  = window.location.href + '?newLang=' + newLang + '&LCID=' + LCID;
	}
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function getmanagerskypestatus(skypeid,manageropmode) {
	var xmlhttp;
	var statusret;
	var oReq = getXMLHttpRequest();

	oReq.open("GET", "skypestatus.aspx?skypeid=" + skypeid, false);
	oReq.send('');
	if (oReq.readyState == 4) {
	    if (oReq.status == 404) alert("URL doesn't exist!");
	    else if (oReq.status != 200) alert("HTML Error! (" + oReq.status + ")")
	    else {
	        statusnum = oReq.responseText;
	        //document.getElementById('skypeManager').innerHTML = "<a href='callto://$$session_managerSkypeID/'>Your SM is " + statusnum + "</a>";

	        switch (manageropmode) {
	            case '0':
	                break;
	            case '1':
	                if (document.getElementById('skypeManager')) {
	                    document.getElementById('skypeManager').style.display = 'block';
	                    break;
	                }
	            case '2':
	                if (statusnum != 'Online' && statusnum != 'Skype Me') {
	                    if (document.getElementById('skypeManager')) { document.getElementById('skypeManager').style.display = 'none'; }
	                }
	                else {
	                    if (document.getElementById('skypeManager')) { document.getElementById('skypeManager').style.display = 'block'; }
	                }
	                break;
	            default:
	                break;
	        }
	    }
	}
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
  return blnResult;
}


function ChangeView(state) {
    document.getElementById("ifr2").src = "ChangeMobileTemplate.asp?state=" + state
}


