// JavaScript Document
popUpWin = 0;
function popUpWindow(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindowMenubar(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindow_scroll(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowAll(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollBars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function PopupPic(sPicURL) { 
	window.open("http://www.mountviewestate.com.au/popup.html?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
	}
	
	
function cNum(e) {
	var strCheck = '0123456789\b\t	 ';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function cNumPhone(e) {
	var strCheck = '0123456789\b\t	 +()[]-';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}


/*
{NY notes}

Guys I m  using this for cross browser usablity and to make http calls more reliable. --ny
Please follow the comments..
*/
function yconnect(url,frm,cnt)
{
   
//show the result in this content
    var responseSuccess = function(o){ 
        document.getElementById(cnt).innerHTML=o.responseText;
		
    }

//if any failure show msg 
    var responseFailure = function(o){ 
        alert("XMLHTTPRequest Failure");
    }

//used to handle call back events     
    var callback =
    {
        success:responseSuccess,
        failure:responseFailure
    }



// Create object and intiate connection. 	

	if(frm != ''){
		// set the from where you need to get the data 
		YAHOO.util.Connect.setForm(frm);
		var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callback,null);
	}else{
		var cObj = YAHOO.util.Connect.asyncRequest('GET', url, callback,null);
	}




//This is to check the connection status 
	var callStatus = YAHOO.util.Connect.isCallInProgress(cObj);

// check for the status and show loading information 
	if(callStatus){
		document.getElementById(cnt).innerHTML="<span style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;'><img src='../images/crm/loading.gif' align='absmiddle' border='0'>&nbsp; Loading...</span>";
	}
	
}	


/* ajax functions */

function getipaddress(mode,url,cnt,frm)
{
	var ktxt,klist;
	ktxt = eval("document."+frm+".ipaddress");
	klist = eval("document."+frm+".ipaddress_list");	
	
	switch (mode){
		
		case 'add':
			url+= "&ip_address="+ ktxt.value; 	
			yconnect(url,'',cnt);
		break;
		
		case 'delete':
			url+= "&ip_address="+ ktxt.value; 	
			yconnect(url,frm,cnt);
		break;		
	}
}



function showdiv(tag)
{
		
	document.getElementById(tag).style.display="block"; 
}

function hidediv(tag)
{

	document.getElementById(tag).style.display="none"; 
}

function show_n_hide_div(tag)
{
	if(document.getElementById(tag).style.display == "block") 
	{
		hidediv(tag);
	}else
	{
		showdiv(tag);
	}
}

// SP - Only numbers will be allowed
<!--
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;

      }
//-->

function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}

function RTrim(str)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...

    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;


    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}

function trim(str)
{
  return RTrim(LTrim(str));
}