var newwin;

function submitForm(form, base){
form.action=base + form.elements['referurl'].value;
form.submit();

}
function formatDate(str) {
	
    if (str.indexOf('-01-01')>-1) {
        document.write(str.substring(0, 4));
    }
	else
	{
		document.write(str.substring(0, 10));
	}
}


function spawn(page) {

document.location=page;

}

function spawnold(page) {
        
    var w = screen.availWidth-100;
	var h = screen.availHeight-100;
	var l = 100;
	var t = 100;
	var pos ="width=" + w + ",height=" + h + ",left=" + l + ",top=" + t;
	
	
    if (newwin!=null && !newwin.closed)
    {
	   
	    newwin.close();
	    newwin=window.open(page, "View", "scrollbars=yes, resizable=no, addressbar=no, menubar=no, toolbar=no, status=no," + pos);
	    newwin.focus();
    
    }
    else
    {
	newwin=window.open(page, "View", "scrollbars=yes, resizable=no, addressbar=no, menubar=no, toolbar=no, status=no," + pos);
	newwin.focus();
	
    }
}
function refreshParent() {
  document.forms[0].submit();
  
}


function submitThis(formname) {
	document.forms[formname].submit();
  
}
function addToList(fieldName, newText, newValue) {
	var listField=document.forms[0].elements[fieldName];
   if ( ( newValue == "" ) || ( newText == "" ) ) {
      alert("You cannot add blank values!");
   } else {
      var len = listField.length++; // Increase the size of list and return the size
      listField.options[len].value = newValue;
      listField.options[len].text = newText;
      listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered)
   } // Ends the check to see if the value entered on the form is empty
}
function removeFromList(fieldName) {
	var listField=document.forms[0].elements[fieldName];
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be removed!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be removed!");
      } else {  // Build arrays with the text and values to remain
         var replaceTextArray = new Array(listField.length-1);
         var replaceValueArray = new Array(listField.length-1);
         for (var i = 0; i < listField.length; i++) {
            // Put everything except the selected one into the array
            if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }
            if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }
            if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }
            if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }
         }
         listField.length = replaceTextArray.length;  // Shorten the input list
         for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
            listField.options[i].value = replaceValueArray[i];
            listField.options[i].text = replaceTextArray[i];
         }
      } // Ends the check to make sure something was selected
   } // Ends the check for there being none in the list
}

function selectAllItems(fieldName) {
	var listField=document.forms[0].elements[fieldName];
   
         for (var i = 0; i < listField.length; i++) {
            listField.options[i].selected=true;
         }
}
function createName() {
	var str;
	
	var str=document.forms[0].elements['firstname'].value;
	
	if (document.forms[0].elements['male'].checked==true) {
		str += " bin ";
		}
		else
		{
		str += " bint ";
	}
	str +=document.forms[0].elements['fathname'].value + " bin " +
	    document.forms[0].elements['granname'].value + " " + document.forms[0].elements['branch'].value;
	    
	
	document.forms[0].elements['fullname'].value=str;

}

function createName(form) {
	var str=form.elements['firstname'].value;
	if (form.elements['male'].checked==true) {
		str += " bin ";
		}
		else
		{
		str += " bint ";
	}
	str +=form.elements['fathname'].value + " bin " +
	   form.elements['granname'].value + " " + form.elements['branch'].value;
	    
	
	form.elements['fullname'].value=str;
	
	}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function escapeVal(text,replaceWith){

for(i=0; i<text.length; i++){

if(text.indexOf("%0D%0A") > -1){
text=text.replace("%0D%0A",replaceWith)
}
else if(text.indexOf("%0A") > -1){
text=text.replace("%0A",replaceWith)
}
else if(text.indexOf("%0D") > -1){
text=text.replace("%0D",replaceWith)
}

}
document.write(text);
}

function moveDualList( srcList, destList, moveAll ) 

{

  // Do nothing if nothing is selected

  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )

  {

    return;

  }



  newDestList = new Array( destList.options.length );



  var len = 0;



  for( len = 0; len < destList.options.length; len++ ) 

  {

    if ( destList.options[ len ] != null )

    {

      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );

    }

  }



  for( var i = 0; i < srcList.options.length; i++ ) 

  { 

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Statements to perform if option is selected



       // Incorporate into new list

       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );

       len++;

    }

  }



  // Sort out the new destination list

  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT



  // Populate the destination with the items from the new array

  for ( var j = 0; j < newDestList.length; j++ ) 

  {

    if ( newDestList[ j ] != null )

    {

      destList.options[ j ] = newDestList[ j ];

    }

  }



  // Erase source list selected elements

  for( var i = srcList.options.length - 1; i >= 0; i-- ) 

  { 

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Erase Source

       //srcList.options[i].value = "";

       //srcList.options[i].text  = "";

       srcList.options[i]       = null;

    }

  }



} // End of moveDualList()

function compareOptionValues(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.value, 36 );  

  var sB = parseInt( b.value, 36 );  

  return sA - sB;

}



// Compare two options within a list by TEXT

function compareOptionText(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.text, 36 );  

  var sB = parseInt( b.text, 36 );  

  return sA - sB;

}

function reveal(a) {
var myItem = document.getElementById(a);
myItem.style.display = 'block';

}

function showHide(id) {

elm = document.getElementById(id);
var icon = document.getElementById('icon');
if (elm.className=="hidden") {
elm.className="unhidden";
if (icon!=null) {
icon.innerHTML="less";
}
}
else 
{
elm.className="hidden";
if (icon!=null) {
icon.innerHTML="more...";
}
}
}
