function showAlert(msg)
{
	alert(msg);
}


function opo(ab)
{
	window.open(ab,"newwin","top=0,left=0,scrollbars=yes,toolbar=no,status=no,resizable=yes,width=650,height=500");
}

function opo1(ab)
{
	window.open(ab,"newwin","top=0,left=0,scrollbars=yes,toolbar=no,status=no,resizable=yes,width=450,height=600");
}

function showConfirm(the_url)
{
	if(confirm("Are You Sure, you want to delete this record")) location.href=the_url;
}

function doOpen(filename,height,width)
{
	var tt=Math.random();
	var yy=tt+"";
	yy=yy.substring(2,yy.length);
	window.open(filename,yy,"scrollbars=yes,toolbar=no,status=no,resizable=yes,width="+width+",height="+height+",top=0,left=0");
}

function jsRedirect(the_url)
{
	location.href=the_url;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function doIntimate(theid)
{
	window.opener.location.href='./free_code_intimate.php?id='+theid;
	window.close();
}

function getSelectedItem(theid,title,ccombos) {

	if(title=="") 
	{
		document.form1.title1.focus();
		alert("Please enter a title for the combo group");
		return false; 
	}
	len = theid.length ; 
	i = 0 ; 

	var setSelection = "n"; 
	var chosenc = ""; 
	var chosenv = ""; 

	for (i = 0; i < len; i++) {
		if (theid[i].selected) {
			chosenc = chosenc + theid[i].value ; 
			chosenc = chosenc + ","; 
			chosenv = chosenv + theid[i].text ; 
			chosenv = chosenv + ", "; 
			setSelection = "y"; 
		} 
	}
	if(setSelection == "n") {
		alert("You should select items from the list to add to combo menu. ");
		return false; 
	}
	
	document.form1.tcombo.value = title; 

	chosenc = chosenc.substring(0,chosenc.lastIndexOf(","));
	chosenv = chosenv.substring(0,chosenv.lastIndexOf(","));
	ccombos.value = chosenc; 
	//discombo.value= chosenv;
	var numValue = Number(document.form1.ccomboctr.value) + 1;
	document.form1.ccomboctr.value = numValue;
	
	var listbox = document.form1.cnones ;
	var newOption = document.createElement('option'); 
	newOption.value = title + ":" + chosenc; // The value that this option will have 
	newOption.innerHTML = title + ":" + chosenv; 
	listbox.appendChild(newOption); 
	document.form1.title1.value = "" ;
	theid.selectedIndex=-1;
	
	return true; 
}

function selectAllListBox(theID)
{
	var ref = theID;
	var jointStr = ref.options[0].value; 
	for(i=1; i<ref.options.length; i++) jointStr = jointStr + ";;" + ref.options[i].value;
	document.form1.ccombo.value = jointStr; 
	return true; 
}


function moveUpx(lst)
{

	if(lst.selectedIndex == -1)
	alert('Please select an Item to move up.');
	else 
	{
		if(lst.selectedIndex == 0)
		{
			alert('First element cannot be moved up');
			return false
		}
		else
		{
			var tempValue = lst.options[lst.selectedIndex].value; 
			var tempIndex = lst.selectedIndex-1; 
			lst.options[lst.selectedIndex].value = lst.options[lst.selectedIndex-1].value; 
			lst.options[lst.selectedIndex-1].value = tempValue; 
			var tempText = lst.options[lst.selectedIndex].text; 
			lst.options[lst.selectedIndex].text = lst.options[lst.selectedIndex-1].text; 
			lst.options[lst.selectedIndex-1].text = tempText; 
			lst.selectedIndex = tempIndex;
		}
	} 
	return false;
}

function moveDownx(lst)
{
	if(lst.selectedIndex == -1)
	alert('Please select an Item to move down');
	else
	{
		if(lst.selectedIndex == lst.options.length-1) 
		alert('Last element cannot be moved down'); 
		else
		{ 
			var tempValue = lst.options[lst.selectedIndex].value; 
			var tempIndex = lst.selectedIndex+1; 
			lst.options[lst.selectedIndex].value = lst.options[lst.selectedIndex+1].value; 
			lst.options[lst.selectedIndex+1].value = tempValue; 
			var tempText = lst.options[lst.selectedIndex].text; 
			lst.options[lst.selectedIndex].text = lst.options[lst.selectedIndex+1].text; 
			lst.options[lst.selectedIndex+1].text = tempText; 
			lst.selectedIndex = tempIndex; 
		} 
	} 
	return false; 
}

function removeItem(selectbox)
{
	var i = selectbox.selectedIndex;
	if(i >= 0)
	{
		selectbox.remove(i);
	}
	else alert ("Select something to remove");
}

function modifySelection(theId1, theId2)
{
	// get value of selected item of id1 
	var i = theId1.selectedIndex; 
	var chosenVal = theId1.options[i].value; 
	// split to get actual item codes 
	var splitVal = chosenVal.split(":"); 
	var titleText = splitVal[0]; 
	document.form1.title1.value = titleText ; 
	var pdtArray = splitVal[1].split(","); 
	// select items in id2 as they occur in scan and keep exiting to start new scan 
	for(var pn = 0; pn < pdtArray.length; pn++)
	{
		// scan through the id2 to find the codes
		for(var reScan = 0; reScan < theId2.length; reScan++)
		{
			if(theId2.options[reScan].value == pdtArray[pn])
			{
				theId2.options[reScan].selected = true; 
				break;
			}
		}
	}
	// remove item from id1 
	removeItem(theId1);
}

function submitComboForm(theId)
{
	document.form1.ccomboctr.value = 25; 
	selectAllListBox(theId); 
	document.form1.submit();
}