
function popup(URL,head,w,h) {
day = new Date();
id = day.getTime();
a = eval("page" + id + " = window.open('"+URL+"', '" + head + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width="+w+",height="+h+",left = 20,top = 20');");
if (a.opener == null) a.opener = self;
}

 function tobreak(wer,were,sdf)
 {
 }
 
function checkDate(date)
{
   // Regular expression used to check if date is in correct format
   var pattern = new RegExp('19|20[0-9]{2}-0|1[0-9]-[0-3][0-9]');
   if(date.match(pattern))
   {
      var date_array = date.split('-');
      var day = date_array[2];

      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[1];
      var year = date_array[0];

      if(month > 12)
      {
         return 'Month is not valid!';
      }
	  
	  if ((month == 2 || month == 4 || month == 6 || month == 9 || month == 11) && day > 30)
	  {
		  return 'There is not 31 days in that month';
	  }

      if(day > 31)
      {
         return 'Day is not valid!';
      }
	  return true;
   }
   else
   {
      return 'Date format is not valid!';
   }
}

function getPage(pag,con)
{
	ajaxpage(pag,con);
}

function doNotes(notid)
{
getPage("rn.php?id="+notid, "not"+notid); var x = document.getElementById("notCount"); x.value = x.value - 1; if (x.value == 0) document.getElementById("AllNotes").style.display="none";
}

function isNumber(sText)
{

   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;

}

function isNumberWithAstr(sText)
{

   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;

}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i;
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function saveval(col, val, id, str)
{
	ajaxpagenoload('saveval.php?col='+col+"&val="+val+"&id="+id+"&str="+str,'saveval');
}

function savevala(col, val, id, str)
{
	ajaxpagela('saveval.php?col='+col+"&val="+val+"&id="+id+"&str="+str, 'saveval');
}

   function doGetCaretPosition (oField) {

     // Initialize
     var iCaretPos = 0;

     // IE Support
     if (document.selection) { 

       // Set focus on the element
       oField.focus ();
  
       // To get cursor position, get empty selection range
       var oSel = document.selection.createRange ();
  
       // Move selection start to 0 position
       oSel.moveStart ('character', -oField.value.length);
  
       // The caret position is selection length
       iCaretPos = oSel.text.length;
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0')
       iCaretPos = oField.selectionStart;

     // Return results
     return (iCaretPos);
   }


   /*
   **  Sets the caret (cursor) position of the specified text field.
   **  Valid positions are 0-oField.length.
   */
   function doSetCaretPosition (oField, iCaretPos) {

     // IE Support
     if (document.selection) { 

       // Set focus on the element
       oField.focus ();
  
       // Create empty selection range
       var oSel = document.selection.createRange ();
  
       // Move selection start and end to 0 position
       oSel.moveStart ('character', -oField.value.length);
  
       // Move selection start and end to desired position
       oSel.moveStart ('character', iCaretPos);
       oSel.moveEnd ('character', 0);
       oSel.select ();
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0') {
       oField.selectionStart = iCaretPos;
       oField.selectionEnd = iCaretPos;
       oField.focus ();
     }
   }

function remcs(vall){
	va = vall.value;
	va = va.replace(',','');
	
	var vpos = null;
	for(i=0; i<va.length; i++){
	 if (va.charAt(i) == ".")
		vpos = i;
	};
	
	   var ValidChars = "0123456789.";
	var gva = "";
	if (vpos != null)
	{
		for(i=0; i<va.length; i++){
			 if (va.charAt(i) == "." && vpos != i)
			 {
			 }
			 else
			 {
 		         if (ValidChars.indexOf(va.charAt(i)) != -1) 
				 {
					 gva += va.charAt(i);
				 }
			 }
		}
	}
	else
	{
		gva = va;
	}
	
	if (vall.value != gva) {
		vall.value = gva;
	}	
}


function disable_submit (btn_id)
{
	var btn = document.getElementById(btn_id);

	btn.className = 'button_disabled';

}

function disable_submit2 (btn_id)
{
	var btn = document.getElementById(btn_id);

	btn.className = 'button_dis';
}

function mc(sd)
{
sd.className = 'mc';
}

function mch(sd)
{
sd.className = 'mch';
}

function mc2(sd)
{
sd.className = 'mc2';
}

function mch2(sd)
{
sd.className = 'mch2';
}

function ecer()
{
		if (document.getElementById('adivster').style.display == "none")
		{
			document.getElementById('adivster').style.display = "block";
		}
   		else
		{
			document.getElementById('adivster').style.display = "none";
		}
}

function php_urlencodeee (str) {
str = escape(str);
return str.replace(/[*+\/@]|%20/g,
function (s) {
switch (s) {
case "*": s = "%2A"; break;
case "+": s = "%2B"; break;
case "/": s = "%2F"; break;
case "@": s = "%40"; break;
case "%20": s = "+"; break;
}
return s;
}
);
}

function bbarsave(x,typee)
{
	var pg = document.getElementById('rdda').value;
	var ud = document.getElementById('diu').value;
	var mess = document.getElementById(x).value;
	mess = mess.replace("&","|");
	ajaxpage("http://www.mytrade.co.za/repsug.php?type="+typee.toString()+"&uid="+ud.toString()+"&mess="+mess.toString()+"&pg="+php_urlencodeee(pg.toString()),"retit");
	document.getElementById('adivster').style.display="none";
	setTimeout("hidemess()",10000);
	document.getElementById(x).value = "";
}

function hidemess()
{
		document.getElementById('retit').innerHTML="";
}

function hidebox()
{
		document.getElementById('adivster').style.display="none";
}

function doGrey($what)
{
	$what.className = 'gc2'; 
}

function doGrey2($what)
{
	$what.className = 'gc'; 
}

function doOrange($what)
{
	$what.className = 'gcd'; 
}

function imexist2 (img)
{
	ajaxpage('imexist2.php?im='+img,'ledit');
}
function chkc()
{
	var eeed = document.getElementById('itexist');
	if (document.getElementById('imurl').value == "")
	{
			document.getElementById('ntplistImage').value = "";
			document.getElementById('ntplistImage').onchange();
			document.getElementById('imloadself').className = "";
			document.getElementById('imurl').value = "";
	}
	else if (eeed == null)
		setTimeout("chkc()",1000);
	else {
		if (eeed.value != 0) {
			document.getElementById('ntplistImage').value = eeed.value;
			document.getElementById('ntplistImage').onchange();
			document.getElementById('imloadself').className = "";
			document.getElementById('imurl').value = "";
			
		}
		else if (eeed.value == 0)
		{
			document.getElementById('imurl').focus();
			document.getElementById('imloadself').className = "";
			alert('The image you specified was invalid. Only jpg, gif and png formats supported');
		}
	}
}
