

function CopyCode(link)
{

	var code;

     code = link;
	if (code.length>0)
    {
        //document.property.previewcode.select();
 		if (window.clipboardData)
   		{
    		window.clipboardData.setData("Text", code);
    		alert("Your alert WAP link has been copied to the ClipBoard! Simply PASTE (Ctrl+V) this into your html document.");
		}
        else
        {
            alert("Use Right Mouse Button & Select text and COPY!");

            // This is importent but it's not noted anywhere
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

            // create interface to the clipboard
            var clip = Components.classes['"@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip) return;

            // create a transferable
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans) return;

            // specify the data we wish to handle. Plaintext in this case.
            trans.addDataFlavor('text/unicode');

            // To get the data from the transferable we need two new objects
            var str = new Object();
            var len = new Object();

            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

            var copytext=code;

            str.data=copytext;

            trans.setTransferData("text/unicode",str,copytext.length*2);

            var clipid=Components.interfaces.nsIClipboard;

            if (!clip) return false;

            clip.setData(trans,null,clipid.kGlobalClipboard);
        }
	}
	else
    	alert("You do not have anything to Copy!");
}


function formValidation(form)
{
	if(notEmpty(form.listname))
	{
		if(notEmpty(form.listdescription))
		{
			return true;
		}
	}
	return false;
}

function notEmpty(elem)
{
	var str = elem.value;
	if(str.length == 0)
	{
		alert("You must fill in all required fields (*)");
		return false;
	}
	else
	{
		return true;
	}
}

function isEmpty(mytext)
{
	var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc.
	if ((mytext.value.length==0) || (mytext.value==null) || ((mytext.value.search(re)) > -1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function selectalertcode()
{
	document.alerttext.alara.select();
}

function mappopup(userid)
{
	locamion = window.open ("http://www.cellyspace.com/lbs/scripts/mappopup.php?userid="+userid,"mylocations","status=0,toolbar=0,resizable=0,width=430,height=500");
}

function areacodes ()
{
	window.open ("http://www.cellyspace.com/lbs/scripts/areacode.php","Area Codes","status=0,toolbar=0,resizable=0,width=430,height=500");
}


function popUp(URL,size)
{
	if(!size)
		var size=520;
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=530,height="+size+",left = 425,top = 150');");
}

function aff_buttons (js1,nb)
{
	var i = 0;
	for (i = 0 ; i < nb ; i++)
	{
		var el = 'buttons'+i;
		document.getElementById(el).style.display = 'none';
	}
	if (document.getElementById(js1).style.display == 'none')
	{
		 document.getElementById(js1).style.display = '';
	}
}


function loca_method (id)
{
	if (id == 1)
	{
		document.getElementById ("areacode").style.display = 'none';
		document.getElementById ("gps").style.display = 'none';
	}
	else
	if (id == 2)
	{
		document.getElementById ("areacode").style.display = '';
		document.getElementById ("gps").style.display = 'none';
	}
	else
	if (id == 3)
	{
		document.getElementById ("areacode").style.display = 'none';
		document.getElementById ("gps").style.display = '';
	}

}


function check_selected(dml,id)
{
	var len = dml.elements.length ;
	var checked_one = false;

	for(var i=0;i<len;i++)
	{
		if(dml.elements[i].name == id)
		{
			if(dml.elements[i].checked == true)
			{
				checked_one = true ;
			}
		}
	}

	if(checked_one == true)
	{
		return true;
	}
	else
	{
		alert("Please select atleast one radio button");
		return false;
	}
}


function change_country(id_country,mms)
     {
     if(mms==1)
          window.location='/alerts_mms.php?id_country='+id_country;
     else
          window.location='/alerts.php?id_country='+id_country;
     }

function choose_item (id,id_item,list_name,alert_quantity)
     {
     //alert(alert_quantity);
	for (i = 0 ; i < alert_quantity ; i++)
          {
		if(i%2==0)
			color=color2;
		else
			color=color1;
		var el = 'buttons'+i;
		//document.getElementById(el).style.display = 'none';
		document.getElementById('tr_'+i).className = color;
          //alert(document.getElementById('tr_'+i).className);
          }

	//document.getElementById('buttons'+id).style.display = '';
	document.getElementById('tr_'+id).className = color4;
	document.getElementById('list').value = id_item;
	document.getElementById('list_name').value = list_name;
	document.getElementById('tr_id').value=id;
     }




function popUp1(URL)
     {
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=430,height=500,left = 425,top = 150');");
     }

function check_form(type)
     {
     alert_name=document.getElementById("list_name").value;
     
     if(alert_name=='choose_another_item')
          {
          alert('Please choose some SMS alert to delete');
          return false;
          }

	if(document.getElementById('list').value=='')
          {
		alert('You have not chosen anything');
		return false;
          }
	if(confirm("Do you really want to delete '"+alert_name+"'?")==true)
          {
		delete_go(document.getElementById('list').value,type);
		return false;
          }
     }

function delete_go(id_item,type)
     {
	 // Mozilla, Safari, etc.
	if (window.XMLHttpRequest)
          {
		delete_request = new XMLHttpRequest();
		if (delete_request.overrideMimeType)
               {
			delete_request.overrideMimeType('text/xml');
               }
          }
	else if (window.ActiveXObject)
          { // IE
		try
               {
			delete_request = new ActiveXObject("Msxml2.XMLHTTP");
               }
		catch (e)
               {
			try
                    {
				delete_request = new ActiveXObject("Microsoft.XMLHTTP");
                    }
			catch (e)
			{}
               }
          }

	var url_delete='ajax_delete.php?id_item='+id_item+'&type='+type+'&sd='+Math.random();
	delete_request.onreadystatechange = deletesuccess;
	delete_request.open('GET', url_delete, true);
	delete_request.send(null);
     }
