//+++-----------------------------------------------------------------+++\\

var sBrowser='';
 sBrowser = (navigator.appName.indexOf("Netscape") >= 0) ?  "NS" : 
  (navigator.appName.indexOf("Microsoft") >= 0) ?    "IE" : "OTHER";   
//+++-----------------------------------------------------------------+++\\


function addlink(action)
{

  var y=document.selection.createRange().text;
  if(y!="")
  {
   if(action=="link")
   {
   var x=prompt("Please enter extract URL with http://","http://");
   var value='<a href='+x+'>'+y+'</a>';
   }
   else if(action=="bold")
   {
     var value='<b>'+y+'</b>';
   }
    else if(action=="color")
   {
	   alert(color);
     var value='<font class>'+y+'</font>';
   }
  document.selection.createRange().text=value;
  }
  else
  {
    alert("Please first select some text");
  }
// insertAtCursor(document.frm.pagetxt, value);
document.selection.empty();
}

function addfont(action,sel)
{
 
  var y=document.selection.createRange().text;
  if(y!="")
  {

   if(action=="color")
   {
	var cname;
	cname=sel.options[sel.selectedIndex].value;
	
   var value='<font class=';
   value+=cname+'>'+y+'</font>';
   }
      else if(action=="size")
   {
	var cname;
	cname=sel.options[sel.selectedIndex].value;
	
   var value='<font size=';
   value+=cname+'>'+y+'</font>';
   }
  document.selection.createRange().text=value;
  sel.selectedIndex=0;
  }
  else
  {
    alert("Please first select some text");
  }
  document.selection.empty();
// insertAtCursor(document.frm.pagetxt, value);
}
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}

function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	alert('Found in: ' + foundIn + '\n' + txt);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function addlist(action,field)
{

  
 
   if(action=="list")
   {
   var x=prompt("Please enter number of bullets","2");
    var y=prompt("Please enter color of bullet, Option Blue, Cyan , Grey","grey");
	y=y.toLowerCase();
	if(y=='blue')
	  y="bluestxt";
	else if(y=='grey')
	  y="txtgrey";
    else if(y=='cyan')
	  y="txtcyan";
   myValue="<ul>";
   for(i=0;i<x;i++)
     {
		 myValue+="<li class="+y+"> <Insert text here> </li>\r\n"
		 }
      myValue+="</ul>";
   insertAtCursor(field, myValue)
   }
   
// insertAtCursor(document.frm.pagetxt, value);
document.selection.empty();
}
//--------------- to remove whitespaces from both side of string, use following function ---\\
function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
	sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
	sString = sString.substring(0,sString.length-1);
}
	return sString;
}
//------------------------------------------------------------------------------------------\\
//--------------- show haide divs Email -----------------------------------------------------------\\
// use following prefixes :'div' for <div> 'td' for column and 'sp' for span with same second element for all
//  e.g : div1,td1,sp1 
// function will be called wlike shDiv(1);
function shDiv(ID) //show hide div
{
	var divID='div'+ID;
	var spanID='sp'+ID;
	var tdID='td'+ID;
	if(document.getElementById(divID)) //if div exists
	if(document.getElementById(divID).style.display=='none') 
		{ 
			document.getElementById(divID).style.display='inline'; 
			if(document.getElementById(tdID)) // if column exists
				document.getElementById(tdID).title='Click to collapse'; 
			if(document.getElementById(spanID)) // if span exists
				document.getElementById(spanID).innerHTML='(Collapse)';
		} 
		else 
		{ 
			document.getElementById(divID).style.display='none'; 
			if(document.getElementById(tdID))
				document.getElementById(tdID).title='Click to expand'; 
			if(document.getElementById(spanID))
				document.getElementById(spanID).innerHTML='(Expand)';
		}
};

function shDiv2(divID) // show hide div
{

	if(document.getElementById(divID).style.display=='none')
	{
		document.getElementById(divID).style.display='inline';
	}
	else
	{
		document.getElementById(divID).style.display='none';	
	}	
}



//------------------------------------------------------------------------------------------\\
// call follwing function on keypress event of a field and that field will
// accept only numeric values and '.' IE only: now it works in mozilla too
//function validatePrice()
//{
	//if ( ( (event.keyCode < 48) && (event.keyCode != 46) ) || (event.keyCode > 57)) 
		//event.returnValue = false;
//}
function validatePrice(e)
{
 if(sBrowser=='IE')	
	{
		if ( ( (e.keyCode < 48) && (e.keyCode != 46) ) || (e.keyCode > 57)) 
			return false;	
   }
   else
   {
		if ( ( (e.charCode < 48) && (e.charCode != 46) && (e.charCode != 0)) || (e.charCode > 57) ) 
			return false;	   						
   }
}
function compareDates (value1, value2) {
   var date1, date2;
   var month1, month2;
   var year1, year2;

   month1 = value1.substring (0, value1.indexOf ("-"));
   date1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
   year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

   month2 = value2.substring (0, value2.indexOf ("-"));
   date2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
   year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);

   if (year1 > year2) return 1;
   else if (year1 < year2) return -1;
   else if (month1 > month2) return 1;
   else if (month1 < month2) return -1;
   else if (date1 > date2) return 1;
   else if (date1 < date2) return -1;
   else return 0;
}
  
  
  var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
  
  }
  
  
function confirmdel(message,url)
{
  if(confirm(message))
  {
    document.location.href=url;
  }
}
