//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;

// 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;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			alert("Error Saving!!! Please Contact System Administrator");
		}
	}
	
	xmlhttp.open("GET", "skypestatus.aspx?skypeid=" + skypeid, false);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==404) alert("URL doesn't exist!");
			else if (xmlhttp.status!=200) alert("HTML Error! ("+ xmlhttp.status +")")
			else{ 
				statusnum = xmlhttp.responseText;
				//document.getElementById('skypeManager').innerHTML = "<a href='callto://$$session_managerSkypeID/'>Your SM is " + statusnum + "</a>";

				switch (manageropmode)
				{
				    case '0':
				        break;
				    case '1':
				        document.getElementById('skypeManager').style.display = 'block';
				        break;
				    case '2':
				        if (statusnum != 'Online' && statusnum != 'Skype Me')
				        {
					        document.getElementById('skypeManager').style.display = 'none';
				        }
				        else
				        {
				            document.getElementById('skypeManager').style.display = 'block';
				        }
				        break;
				    default:
				        break;
				}
			}
		}
	}
	xmlhttp.send('');
}

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;
}

//ehud
function showGradingReport(cert,weight,Lab){
    //alert("Lab#=" + Lab);
    var url, weight,Lab1;

    Lab = Lab.split(' ').join('');

    weight = new Number(weight);

    if (weight && weight < 1) {
        weight = weight.toPrecision(2);
    }
    else {
        weight = weight.toFixed(2);
    }
    if (Lab=="HRD"){
        
        url ="http://www.hrdantwerplink.be/?record_number="
        url = url + cert + "&weight=" + weight + "&L"
        //alert(url);
        window.open (url,"mywindow");
    }
    if (Lab=="GIA"){
        url ="http://www.gia.edu/reportcheck/index.cfm?fuseaction=home.showReportVerification&reportno=" 
        url = url + cert + "&weight=" + weight
        //alert(url);
        window.open (url,"mywindow");
    }
    if (Lab=="IGI"){
        url ="http://www.igiworldwide.com/IGI_ONLINE/Client/ShowReport.aspx?PrintNo=" 
        url = url + cert + "&Wght=" + weight
        //alert(url);
        window.open (url,"mywindow");
    }
    if (Lab=="AGS"){
        url ="http://www.agslab.com/trade_report_verification.php?StoneID=" 
        url = url + cert + "&Weight=" + weight
        //alert(url);
        window.open (url,"mywindow");
    }
    
    
}
//ehud end