// 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("popup.html?"+sPicURL, "", "resizable=1,HEIGHT=400,WIDTH=400");
	}
	
	
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/Progress.gif' align='absmiddle' border='0'>&nbsp; Loading...</span>";
//		document.getElementById(cnt).innerHTML="<span style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;'>&nbsp; Loading...</span>";
	}
	
}	

/* Multiple Refreshes */
function menu_yconnect(url,frm,cnt,nav_img,curr_img)
{
//show the result in this content
    var responseSuccess = function(o){ 
        document.getElementById(cnt).innerHTML=o.responseText;

	//			Customised section
	//yconnect('includes/left_nav.php?jsmenu=true','','left_nav_menu');
	var img_name = document.getElementById(curr_img+"_img").value;
	var img_title = document.getElementById(curr_img+"_title").value;
	document.getElementById(nav_img).src=img_name;
	document.getElementById(nav_img).alt=img_title;
	document.getElementById(nav_img).title=img_title;
//	document.getElementById("CSF").src="images/tick.jpg";
    }

//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/Progress.gif' align='absmiddle' border='0'>&nbsp; Loading...</span>";
//		document.getElementById(cnt).innerHTML="<span style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;'>&nbsp; Loading...</span>";
	}
	
}	


/* Multiple Refreshes ENDS */


/* 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 getfreeip(fld)
{
	var url;
	url = 'ajaxtpl/freeip.php?server_id='+fld.value;
	yconnect(url,'','ipcnt');
}



function showdiv(tag)
{
	document.getElementById(tag).style.display="block"; 
}

function showdiv1(tag)
{
	alert(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);
	}
}


function change_mode(formname,mode)
{
	var k;
	k = eval("document."+formname)
	k.mode.value = mode;
}


	// ==========================================================================
// Fuctions to mimic LTrim, RTrim, and Trim...

// Author          Aurélien Tisné	(CS)
// Date            03 avr. 2003 23:11:39
// Last Update     $Date$
// Version         $Revision$
// ==========================================================================

// --------------------------------------------------------------------------
// Remove leading blanks from our string.

// I               str - the string we want to LTrim
// Return          the input string without any leading whitespace

// Date            03 avr. 2003 23:12:13
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
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;
}

// --------------------------------------------------------------------------
// Remove trailing blanks from our string.

// I               str - the string we want to RTrim
// Return          the input string without any trailing whitespace

// Date            03 avr. 2003 23:13:50
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
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;
}


// --------------------------------------------------------------------------
// Remove trailing and leading blanks from our string.

// I               str - the string we want to Trim
// Return          the trimmed input string

// Date            03 avr. 2003 23:15:09
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
function trim(str)
{
  return RTrim(LTrim(str));
}



/*ajax image uploader*/
function uploadstats(uploadDir,uploader,url, divname) 
{
  yconnect(url+'?uploadDir='+uploadDir+'&uploader='+uploader,'',divname);

}

function tep()
{
		alert(document.getElementById('thumb_path').value);
    if(document.getElementById('thumb_path').value != "")
	{
		document.getElementById('thumb').src = document.getElementById('thumb_path').value;
	}
}

function uploadfile(frmname,action,obj,divname)
{
	var uploadDir = obj.value;
	uploader = obj.name;
	//alert(frmname);
	if(action=='')
	{
		document.getElementById(frmname).submit(); /* This is used when target is assigned in form */
	}else{

		var currentaction = document.getElementById(frmname).action;

		document.getElementById(frmname).action = action;
		document.getElementById(frmname).target = 'uploadiframe';
		document.getElementById(frmname).submit();
		document.getElementById(frmname).target = '';		
		document.getElementById(frmname).action = currentaction;	
	
	}
	
	uploadstats(uploadDir, obj.name, action, divname);	
	//tep();
}

/* end ajax image upload */

/* start limit text courtesy -- AV  */
function max_length(limit,fld,id)
{
	  var l;
	  limit=limit-1;
	  l=fld.value.length;
	if(l>limit)
	{
		 fld.value = fld.value.substring(0,limit);
	}
	else

	{
		if(id!="")
		{
		 document.getElementById(id).innerHTML="<font color='#9a0032'><b>"+eval(limit-l)+"</b></font> Chars Remaining";

		} 
	}
}


/* end limit text*/


/* WHM select plans */

<!--HIDE IT---

   function dologinname(frm) 
   {
      var domain = replaceString(".","",frm.domain.value);
      var username = domain.substring(0,8);
      var username = username.toLowerCase();
      frm.username.value = replaceString(".","",username);
   }

   function replaceString(oldS,newS,fullS) 
   {
      // Replaces oldS with newS in the string fullS
      for (var i=0; i<fullS.length; i++) {
         if (fullS.substring(i,i+oldS.length) == oldS) {
            fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
         }
      }
      return fullS
   }

   function fixaddress() {
      document.whmform.domain.value = document.whmform.domain.value.toLowerCase();
   }



   function miniupdateform(nfo) 
   {
      cpsets = nfo.split("|");
      // ip,cgi,quota,frontpage,cp,maxftp,maxsql,maxpop,maxlst,maxsub,plan,maxpark,maxaddon
	   document.whmform.plan.value = cpsets[15];
   }


   function updateform(nfo) {
      cpsets = nfo.split("|");
      // ip,cgi,quota,frontpage,cp,maxftp,maxsql,maxpop,maxlst,maxsub,plan,maxpark,maxaddon
      if (cpsets[0] == "n") {
         document.whmform.ip.value  = "";
      } else {
         document.whmform.ip.value  = 1;
      }
      if (cpsets[1] == "n") {
         document.whmform.cgi.value = "";
      } else {
         document.whmform.cgi.value = 1;
      }
      if (cpsets[3] == "n") {
         document.whmform.frontpage.value = "";
      } else {
         document.whmform.frontpage.value = 1;
      }
      document.whmform.quota.value   = cpsets[2];
      document.whmform.maxftp.value  = cpsets[5];
      document.whmform.maxsql.value  = cpsets[6];
      document.whmform.maxpop.value  = cpsets[7];
      document.whmform.maxlst.value  = cpsets[8];
      document.whmform.maxsub.value  = cpsets[9];
      document.whmform.bwlimit.value = cpsets[10];
      if (cpsets[11] == "n") {
         document.whmform.hasshell.value = "";
      } else {
         document.whmform.hasshell.value = 1;
      }
/*   for (var i = 0; i < document.whmform.cpmod.options.length; i++) {
      if (document.whmform.cpmod.options[i].value == cpsets[4])
      document.whmform.cpmod.selectedIndex=i;
   }*/


   document.whmform.plan.value = cpsets[15];


   if (cpsets[12]) {
      document.whmform.maxpark.value  = cpsets[12];
   } else {
      document.whmform.maxpark.value  = 0;
   }
   if (cpsets[13]) {
      document.whmform.maxaddon.value = cpsets[13];
   } else {
      document.whmform.maxaddon.value = 0;
   }
}

//--->

/* end whm plan function */




/*
{NY notes}

Guys I m  using this for cross browser usablity and to make http calls more reliable. --ny
Please follow the comments..
*/
var zi;

function yconnectresponse(url,frm)
{
	  
//show the result in this content
    var responseSuccess = function(o){ 
   //     document.getElementById(cnt).innerHTML=o.responseText;
		zi =  o.responseText;		 
		alert(zi);

    }

//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){
		alert("loading...");
//		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>";
	}
	
	

	
}

// SP - Only numbers will be allowed
 function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
            return false;

         return true;

      }

