//ajax function
function ajaxSiteFunction(){
	var ajaxSiteRequest =false;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxSiteRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxSiteRequest= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxSiteRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
		
	}
	return ajaxSiteRequest;
}


function validateForm(form) {
    if (isNotEmpty(form.name1)) {
        if (isNotEmpty(form.name2)) {
            if (isNotEmpty(form.eMail)) {
                if (isEMailAddr(form.eMail)) {
                    if (isChosen(form.continent)) {
                        if (isValidRadio(form.accept)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}



// validate that the user made a selection other than default
function isChosen(select) {
    if (select.selectedIndex == 0) {
        alert("Please make a choice from the list.");
        return false;
    } else {
        return true;
    }
}
   
// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return true;
        }
    }
  //  alert("Make a choice from the radio buttons.");
    return false;
}


//only letter
function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 65 || charCode > 90) && 
        (charCode < 97 || charCode > 122)) {
        alert("Enter letters only.");
        return false;
    }
    return true;
}


//only number
//onkeypress="return numeralsOnly(event)"

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Enter numerals only in this field.");
        return false;
    }
    return true;
}

//focus for next
//<input type="text" name="name1" id="name1" 
//    onkeypress="return focusNext(this.form, 'name2', event)">

function focusNext(form, elemName, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        form.elements[elemName].focus( );
        return false;
    }
    return true;
}

/*
Make sure that textBox only contain number
 */
function checkNumber(textBox)
{
   while (textBox.value.length > 0 && isNaN(textBox.value))
   {
      textBox.value = textBox.value.substring(0, textBox.value.length - 1)
   }

   textBox.value = trim(textBox.value);
   /* 	if (textBox.value.length == 0) {
   textBox.value = 0;
   } else {
   textBox.value = parseInt(textBox.value);
   } */
}

/*
Check if a form element is empty.
If it is display an alert box and focus
on the element
 */
function isEmpty(formElement, message)
{
   formElement.value = trim(formElement.value);

   _isEmpty = false;
   if (formElement.value == '')
   {
      _isEmpty = true;
      // 		alert(message);
      eMsg(message, "red", 3);
      // ambi ganti dengan alert
      formElement.focus();

   }

   return _isEmpty;
}

function eMsg(msg, sColor, idMsgBox)
{
   if (idMsgBox == 1)
   {
      var div = document.getElementById("icon-yellow");
   }

   if (idMsgBox == 2)
   {
      var div = document.getElementById("icon-ok");
   }

   if (idMsgBox == 3)
   {
      var div = document.getElementById("icon-error");
   }
   div.style.visibility = "visible";
   div.style.display = "block";
   div.style.color = sColor;
   div.style.fontSize = "0.9em";
   // remove old messages
   if(div.hasChildNodes())
   {
      div.removeChild(div.firstChild);
   }
   div.appendChild(document.createTextNode(msg));

}




/*
Set one value in combo box as the selected value
 */
function setSelect(listElement, listValue)
{
   for (i = 0; i < listElement.options.length; i ++ )
   {
      if (listElement.options[i].value == listValue)
      {
         listElement.selectedIndex = i;
      }
   }
}

/* *
 * DHTML date validation script for dd / mm / yyyy. Courtesy of SmartWebby.com (http : // www.smartwebby.com / dhtml / )
 */
// Declaring valid date character, minimum year and maximum year
var dtCh = "-";
var minYear = 1900;
var maxYear = 2900;

function isInteger(s)
{
   var i;
   for (i = 0; i < s.length; i ++ )
   {
      // Check that current character is number.
      var c = s.charAt(i);
      if (((c < "0") || (c > "9"))) return false;
   }
   // All characters are numbers.
   return true;
}

function stripCharsInBag(s, bag)
{
   var i;
   var returnString = "";
   // Search through string's characters one by one.
   // If character is not in bag, append to returnString.
   for (i = 0; i < s.length; i ++ )
   {
      var c = s.charAt(i);
      if (bag.indexOf(c) == - 1) returnString += c;
   }
   return returnString;
}

function daysInFebruary (year)
{
   // February has 29 days in any year evenly divisible by four,
   // EXCEPT for centurial years which are not also divisible by 400.
   return (((year % 4 == 0) && ( ( ! (year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n)
{
   for (var i = 1; i <= n; i ++ )
   {
      this[i] = 31
      if (i == 4 || i == 6 || i == 9 || i == 11)
      {
         this[i] = 30
      }
      if (i == 2)
      {
         this[i] = 29
      }
   }
   return this
}

function isDate(dtStr)
{
   var daysInMonth = DaysArray(12)
   var pos1 = dtStr.indexOf(dtCh)
   var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
   var strDay = dtStr.substring(0, pos1)
   var strMonth = dtStr.substring(pos1 + 1, pos2)
   var strYear = dtStr.substring(pos2 + 1)
   strYr = strYear
   if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
   if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
   for (var i = 1; i <= 3; i ++ )
   {
      if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
   }
   month = parseInt(strMonth)
   day = parseInt(strDay)
   year = parseInt(strYr)
   if (pos1 == - 1 || pos2 == - 1)
   {
      alert("Format tanggal adalah : dd-mm-yyyy")
      return false
   }
   if (strMonth.length < 1 || month < 1 || month > 12)
   {
      alert("Mohon masukkan bulan yang benar")
      return false
   }
   if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
   {
      alert("Mohon masukkan tanggal yang benar")
      return false
   }
   if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
   {
      alert("Mohon masukkan 4 digit tahun antara " + minYear + " and " + maxYear)
      return false
   }
   if (dtStr.indexOf(dtCh, pos2 + 1) != - 1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false)
   {
      alert("Mohon masukkan tanggal yang benar")
      return false
   }
   return true
}

function CheckIsDate(dtStr)
{
 //   var ErrorMessage = '';
//	var elem = document.getElementById(divElementId);
//	    elem.innerHTML = "";
//		elem.style.display = 'block';
//    	elem.style.visibility = 'visible';
		
   var daysInMonth = DaysArray(12)
   var pos1 = dtStr.indexOf(dtCh)
   var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
   var strDay = dtStr.substring(0, pos1)
   var strMonth = dtStr.substring(pos1 + 1, pos2)
   var strYear = dtStr.substring(pos2 + 1)
   strYr = strYear
   if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
   if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
   for (var i = 1; i <= 3; i ++ )
   {
      if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
   }
   month = parseInt(strMonth)
   day = parseInt(strDay)
   year = parseInt(strYr)
   if (pos1 == - 1 || pos2 == - 1)
   {
      //alert("Format tanggal adalah : dd-mm-yyyy")
	 // ErrorMessage = 'Format tanggal adalah : dd-mm-yyyy';
	 // elem.innerHTML = ErrorMessage;
      return false
   }
   if (strMonth.length < 1 || month < 1 || month > 12)
   {
      //alert("Mohon masukkan bulan yang benar")
	  // ErrorMessage = 'Mohon masukkan bulan yang benar';
	//   elem.innerHTML = ErrorMessage;
      return false
   }
   if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
   {
      //alert("Mohon masukkan tanggal yang benar");
	 // ErrorMessage = 'Mohon masukkan tanggal yang benar';
	//  elem.innerHTML = ErrorMessage;
      return false;
   }
   if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
   {
      //alert("Mohon masukkan 4 digit tahun antara " + minYear + " and " + maxYear);
	 // ErrorMessage = 'Mohon masukkan 4 digit tahun antara ' + minYear + ' and ' + maxYear;
	 // elem.innerHTML = ErrorMessage;
      return false
   }
   if (dtStr.indexOf(dtCh, pos2 + 1) != - 1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false)
   {
      //alert("Mohon masukkan tanggal yang benar")
	//  ErrorMessage = 'Mohon masukkan tanggal yang benar';
	//  elem.innerHTML = ErrorMessage;
      return false
   }
   return true
}



function ValidateForm()
{
   var dt = document.frmListAllOrderByDate.txtDate
   if (isDate(dt.value) == false)
   {
      dt.focus()
      return false
   }
   return true
}

// Function cari
function viewHasilCari(q)
{
   var q = window.document.frmIndex.q.value;

   if (q != '')
   {
      window.location.href = 'index.php?q=' + q;
   }
   else
   {
      // 	alert("Masukkan nama produk yang ingin dicari")
      window.document.frmIndex.q.focus();
      return;
   }
}


function subcribe(e)
{
   var e = window.document.frmIndex.txtEmail.value;

   if (e != '')
   {
      window.location.href = 'index.php?email=' + e;
   }
   else
   {
      alert("Masukkan email anda untuk subscribe")
      window.document.frmIndex.txtEmail.focus();
      return;
   }
}


function checkAddMsgForm()
{
   with (window.document.frmMsg)
   {
      if (isEmpty(txtNama, 'Masukkan Nama anda'))
      {
         alert('Pilih kategori artikel');
         txtNama.focus();
         return;
      }
      else if (isEmpty(txtEmail, 'Masukkan email valid anda'))
      {
         txtEmail.focus();
         return;
      }
      else if (isEmpty(txtSubject, 'Masukkan subject yang anda maksud'))
      {
         txtSubject.focus();
         return;
      }
      else if (isEmpty(txtMessage, 'Tulis pesan anda'))
      {
         txtMessage.focus();
         return;
      }
      else if (isEmpty(txtNumber, 'Masukkan kode yang terlihat pada gambar'))
      {
         txtNumber.focus();
         return;
      }
      else
      {
         submit();
      }
   }
}


// upload image
// onclick = "UploadImage(this.form, this.form.imageUpload.value)"
//
function UploadImage(form, file)
{
   allowSubmit = false;
   extArray = new Array(".gif", ".jpeg", ".jpg", ".png");
   if ( ! file) return;
   while (file.indexOf("\\") != - 1)
   file = file.slice(file.indexOf("\\") + 1);
   ext = file.slice(file.indexOf(".")).toLowerCase();
   for (var i = 0; i < extArray.length; i ++ )
   {
      if (extArray[i] == ext)
      {
         allowSubmit = true;
         break;

      }
   }
   if (allowSubmit == false)
   // form.submit();
   // alert('oke');
   // else
  alert("Mohon upload file dengan types: " + (extArray.join(" ")) + "\nMohon pilih file yang lain.");
	    
}
// -->


/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
 */
function trim(str)
{
   return str.replace(/^\s+|\s+$/g, '');
}

/*
Check if a string is in valid email format.
Input  : the string to check
Output : true if the string is a valid email address, false otherwise.
 */
function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   return regex.test(str);
}

function getScrollTopRight()
{
   if ( document.documentElement.scrollTop )
   		return document.documentElement.scrollTop;
   return document.body.scrollTop;
}

function scrollHandlerTopRight()
{
   var e = document.getElementById('LoadingTopRight');
	   e.style.top = getScrollTopRight();
}

function showNotifyTopRight( str )
{
   var elem = document.getElementById('LoadingTopRight');
	   elem.style.display = 'block';
	   elem.style.visibility = 'visible';

   if ( elem.currentStyle &&
	   elem.currentStyle.position == 'absolute' )
   {
      elem.style.top = getScrollTopRight();
      window.onscroll = scrollHandlerTopRight;
   }
	  elem.innerHTML = str;
}


function hideNotifyTopRight()
{
   var elem = document.getElementById('LoadingTopRight');
	   elem.style.display = 'none';
	   elem.style.visibility = 'hidden';
	   window.onscroll = null;
}


function checkReadyStateShowLeftTopRight(obj)
{
   switch(obj.readyState)
   {
      case 0 :
    		 showNotifyTopRight("Sending request...");
      break;
      case 1 :
		     showNotifyTopRight( "Loading response...");
      break;
      case 2 :
		     showNotifyTopRight("Response loaded...");
      break;
      case 3 :
		     showNotifyTopRight("Response ready...");
      break;
      case 4 :
	      // hideNotify() ;
	      showNotifyTopRight('Loading completed...');
    	//  setTimeout("Effect.Fade('LoadingTopRight',{duration: 0.9, queue: 'end'})", 500);
      break;
      default :
   		   showNotifyTopRight("An unexpected error has occurred."+"status : " + obj.status);
   }

   if(obj.readyState == 4 || obj.readyState == "complete")
   {
       hideNotifyTopRight() ;
      // 	setTimeout("showNotify('Complete...')", 200);
      // 					hideNotify();
      // 	Effect.Fade(showNotify('Complete...'), {duration : 0.25, queue : 'end'});
   }
}

//// notify 2

function getScrollTopLeft()
{
   if ( document.documentElement.scrollTop )
   return document.documentElement.scrollTop;
   return document.body.scrollTop;
}

function scrollHandlerNotifyLeft()
{
   var e = document.getElementById('LoadingTopLeft');
	   e.style.top = getScrollTopLeft();
}

function showNotifyLeft( str )
{
   var elem = document.getElementById('LoadingTopLeft');
	   elem.style.display = 'block';
	   elem.style.visibility = 'visible';

   if ( elem.currentStyle &&
	   elem.currentStyle.position == 'absolute' )
   {
    	elem.style.top = getScrollTopLeft();
	      window.onscroll = scrollHandlerNotifyLeft;
   }
		elem.innerHTML = str;
}

function hideNotifyLeft()
{
   var elem = document.getElementById('LoadingTopLeft');
	   elem.style.display = 'none';
	   elem.style.visibility = 'hidden';
   window.onscroll = null;
}


function checkReadyStateShowLeft(obj)
{
   switch(obj.readyState)
   {
      case 0 :
		showNotifyLeft("Sending request...");
      break;
      case 1 :
	  	showNotifyLeft( "Loading response...");
      break;
      case 2 :
     	showNotifyLeft("Response loaded...");
      break;
      case 3 :
	    showNotifyLeft("Response ready...");
      break;
      case 4 :
    	showNotifyLeft('Loading completed...');
     // setTimeout("Effect.Fade('LoadingTopLeft',{duration: 0.25, queue: 'end'})", 500);
      break;
      default :
    	  showNotifyLeft("An unexpected error has occurred."+ "status : " + obj.status);
   }
   if(obj.readyState == 4 || obj.readyState == "complete")
   {
       hideNotifyLeft();
      // 	setTimeout("showNotify('Complete...')", 200);
      // 					hideNotify();
      // 	Effect.Fade(showNotify('Complete...'), {duration : 0.25, queue : 'end'});
   }
}
/////


//// notify 3 center

function getScrollTopCenter()
{
   if ( document.documentElement.scrollTop )
   return document.documentElement.scrollTop;
   return document.body.scrollTop;
}

function scrollHandlerNotifyCenter()
{
	var e = document.getElementById('LoadingTopCenter');
		e.style.top = getScrollTopLeft();
}

function showNotifyCenter( str )
{
   var elem = document.getElementById('LoadingTopCenter');
	   elem.style.display = 'block';
	   elem.style.visibility = 'visible';

   if ( elem.currentStyle &&
	   elem.currentStyle.position == 'absolute' )
   {
       elem.style.top = getScrollTopCenter();
       window.onscroll = scrollHandlerNotifyCenter;
   }
	   elem.innerHTML = str;
}

function hideNotifyCenter()
{
   var elem = document.getElementById('LoadingTopCenter');
	   elem.style.display = 'none';
	   elem.style.visibility = 'hidden';
   window.onscroll = null;
}


function checkReadyStateShowImageLoading(obj)
{
   switch(obj.readyState)
   {
      case 0 :
      	showNotifyCenter("Sending request...");
      break;
      case 1 :
      	showNotifyCenter("Loading response...");
      break;
      case 2 :
      	showNotifyCenter("Response loaded...");
      break;
      case 3 :
      	showNotifyCenter("Response ready...");
      break;
      case 4 :
		showNotifyCenter('Loading completed...');
//      setTimeout("Effect.Fade('LoadingTopCenter',{duration: 0.25, queue: 'end'})", 500);
		hideNotifyCenter();
      break;
      default :
      	showNotifyCenter("An unexpected error has occurred.");
   }
   
   if(obj.readyState == 4 || obj.readyState == "complete")
   {
      hideNotifyCenter();
      // 	setTimeout("showNotify('Complete...')", 200);
      // 					hideNotify();
      // 	Effect.Fade(showNotify('Complete...'), {duration : 0.25, queue : 'end'});
   }
}


///for loading gif
function getScrollLoading()
{
   if ( document.documentElement.scrollTop )
   return document.documentElement.scrollTop;

   return document.body.scrollTop;
}

function scrollHandlerLoading()
{
   var e = document.getElementById('loading');
	   e.style.top = getScrollTopLoading();
}

function showNotifyLoading(str)
{
   var elem = document.getElementById('loading');
	   elem.style.display = 'block';
	   elem.style.visibility = 'visible';

   if ( elem.currentStyle &&
	   elem.currentStyle.position == 'absolute' )
   {
      elem.style.top = getScrollTopLoading();
      window.onscroll = scrollHandlerLoading;
   }

   elem.innerHTML = str;
}

function hideNotifyLoading()
{
   var elem = document.getElementById('Loading');
   elem.style.display = 'none';
   elem.style.visibility = 'hidden';
   window.onscroll = null;
}

function imageLoading(elementId){
			elementId.style.visibility = 'visible';
			elementId.style.display = 'block';
//		 new Effect.Fade(elementId, {duration:5.5, from:2.5, to:0});
		  $(elementId).show("slow");
//          $(elementId).fadeTo("slow", 0.33);
          $(elementId).fadeTo("slow", 0);
}

function checkReadyStateShowLoadingChecking(obj,elementId)
{
	//var ElementText = document.getElementById('textLoading');
	    
   switch(obj.readyState)
   {
      case 0 :
		 imageLoading(document.getElementById(elementId));
       break;
      case 1 :
		imageLoading(document.getElementById(elementId));
      break;
      case 2 :
		 imageLoading(document.getElementById(elementId));
      break;
      case 3 :
			 imageLoading(document.getElementById(elementId));
      break;
      case 4 :
	   		imageLoading(document.getElementById(elementId));
      break;
      default :
		   alert ( "An unexpected error has occurred." +" status : " + obj.status );
   }

}


function checkReadyStateShowLeftLoading(obj)
{
	var ElementText = document.getElementById('textLoading');
	    
   switch(obj.readyState)
   {
      case 0 :
		 imageLoading(document.getElementById('loadingSignup'));
 	 	 ElementText.innerHTML ="Sending request...";
      break;
      case 1 :
		imageLoading(document.getElementById('loadingSignup'));
		 ElementText.innerHTML= "Loading response...";
      break;
      case 2 :
		 imageLoading(document.getElementById('loadingSignup'));
	 	  ElementText.innerHTML = "Response loaded...";		 
      break;
      case 3 :
			 imageLoading(document.getElementById('loadingSignup'));
		 	 ElementText.innerHTM = "Response ready...";			 
      break;
      case 4 :
	   		imageLoading(document.getElementById('loadingSignup'));
			 ElementText.innerHTML ='Loading completed...';			
		
      break;
      default :
	    ElementText.innerHTML = "An unexpected error has occurred." +" status : " + obj.status;
   }

//   if(obj.readyState == 4 || obj.readyState == "complete")
 //  {
//     hideNotifyLoading() ;
//		imageLoading(document.getElementById('loadingSignup'));
 //  }
}
////end



function init() {

var ld=(document.all);
var ns4=document.layers;
var ns6=document.getElementById && !document.all;
var ie4=document.all;
	
if (ns4) ld=document.loading;
else if (ns6)
	ld = document.getElementById("loading").style;
else if (ie4)
	ld = document.all.loading.style;
else 
	ld = document.all.loading.style;
if(ns4){
	ld.visibility="hidden";
	}
	else if (ns6||ie4) ld.display="none"; 
}

//window.onload=init();


function Message(txt, timeout)
{
   var box = document.getElementById("messagebox");
   var txtNode = document.createTextNode(txt);
   if (box == null)
   {
       box = document.createElement("div");
      box.id = "messagebox";
      box.classname = "messagebox";
      box.style.display = 'block';
      box.appendChild(txtNode);
   }
   else
   {
      var oldTxtNode = box.firstChild;
      box.replaceChild(txtNode, oldTxtNode);
   }
  
   setTimeout("removeBox('messagebox')", timeout);
}

function removeBox(id)
{
   var box = document.getElementById(id);
   if (box && box.parentNode)
   {
      box.parentNode.removeChild(box);
   }
}

function MyObject(id)
{
   this.id = id;
   this.front = document.createElement("div");
   this.front.backingObj = this;
}


///

  function CountLeft(field, count, max)
  	{ // if the length of the string in the input field is greater than the max value, trim it  
   		if (field.value.length > max) field.value = field.value.substring(0, max); else 
		   // calculate the remaining characters   
   			count.value = max - field.value.length;
    } 


function textCounter(field,maxlimit) {
		if (field.value.length > maxlimit){
    		alert ('A maximum of 2000 characters is allowed.');
				field.value = field.value.substring(0, maxlimit);
			}
		}



///

// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}
   
// utility function called by getCookie( )
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
   
// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}
   
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
   
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function showMessage(elementId, Message){
			elementId.style.visibility = 'visible';
			elementId.style.display = 'block';
			elementId.innerHTML = "";
		 	elementId.innerHTML = Message;
	//	 new Effect.Fade(elementId, {duration:10.5, from:10.5, to:0});
			// $(elementId).fadeTo("slow", 0.33);
			 $(elementId).fadeTo("slow", 1);
	
}

function displayLess(elementId){
		 new Effect.Fade(elementId, {duration:1.5, from:1.5, to:0});
}


function showCaptchaImage(elementId){
		 new Effect.Appear(elementId, {duration:2.5, from:0, to:2.5});
}


function hideBox(elementId){
		elementId.style.visibility = 'hidden';
		elementId.style.display = 'none';
}

function showBox(elementId){
		elementId.style.visibility = 'visible';
		elementId.style.display = 'block';
}

function backSignup(elementHide,elementShow){
		hideBox(elementHide);
		showBox(elementShow)

}


function passwordStrength(password)
{
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	 document.getElementById("passwordDescription").innerHTML = desc[score];
	 document.getElementById("passwordStrength").className = "strength" + score;
}


// Password strength meter v1.0
// Matthew R. Miller - 2007
// www.codeandcoffee.com
// Based off of code from  http://www.intelligent-web.co.uk

// Settings
// -- Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;

// Check password
function checkPassword(strPassword)
{
	// Reset combination count
	nCombinations = 0;
	
	// Check numbers
	if (bCheckNumbers)
	{
		strCheck = "0123456789";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check upper case
	if (bCheckUpperCase)
	{
		strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check lower case
	if (bCheckLowerCase)
	{
		strCheck = "abcdefghijklmnopqrstuvwxyz";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check punctuation
	if (bCheckPunctuation)
	{
		strCheck = ";:-_=+\|//?^&!.@$£#*()%~<>{}[]";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Calculate
	// -- 500 tries per second => minutes 
    	var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;
 
	// Number of days out of password lifetime setting
	var nPerc = nDays / nPasswordLifetime;
	
	return nPerc;
}
 
// Runs password through check and then updates GUI 
function runPassword(strPassword, strFieldID) 
{
	// Check password
	nPerc = checkPassword(strPassword);
	
	 // Get controls
    	var ctlBar = document.getElementById(strFieldID + "_bar"); 
    	var ctlText = document.getElementById(strFieldID + "_text");
    	if (!ctlBar || !ctlText)
    		return;
    	
    	// Set new width
    	var nRound = Math.round(nPerc * 100);
	if (nRound < (strPassword.length * 5)) 
	{ 
		nRound += strPassword.length * 5; 
	}
	if (nRound > 100)
		nRound = 100;
    	ctlBar.style.width = nRound + "%";
 
 	// Color and text
 	if (nRound > 95)
 	{
 		strText = "Very Secure";
 		strColor = "#3bce08";
 	}
 	else if (nRound > 75)
 	{
 		strText = "Secure";
 		strColor = "orange";
	}
 	else if (nRound > 50)
 	{
 		strText = "Mediocre";
 		strColor = "#ffd801";
 	}
 	else
 	{
 		strColor = "red";
 		strText = "Insecure";
 	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
 
// Checks a string for a list of characters
function doesContain(strPassword, strCheck)
 {
    	nCount = 0; 
 
	for (i = 0; i < strPassword.length; i++) 
	{
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) 
		{ 
	        	nCount++; 
		} 
	} 
 
	return nCount; 
} 
 
//check verication password
// Runs password through check and then updates GUI 
function runVerificationPassword(strRePassword, strFieldID) 
{
	
	 // Get controls
     	var password = document.getElementById('txtPassword').value;
    	var verificationPassword = document.getElementById('txtRePassword').value;
    	var ctlText = document.getElementById('verificationPassword');
    	if (!ctlText)
    		return;

 	// Color and text
 	if (verificationPassword  != password)
 	{
 		strColor = "red";
 		strText = "Verification password does not macth";
 	}else{
 		strColor = "green";
 		strText = "Verification password is macth";
	}
	
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}


function framePrint(whichFrame){
	parent[whichFrame].focus();
	parent[whichFrame].print();
}

function validate() {
   var filename = document.getElementById("file_source").value;
   var ext = getExt(filename);
   if(ext == "csv")
      return true;
   alert("Mohon upload file csv saja.");
   document.getElementById("file_source").value='';
   return false;
}



function getExt(filename) {
   var dot_pos = filename.lastIndexOf(".");
   if(dot_pos == -1)
      return "";
   return filename.substr(dot_pos+1).toLowerCase();
}

function validateImage(file) {
   var filename = file;
   var result= true;
   var ext = getExt(filename);
   if ((ext == "gif") || (ext == "jpg") || (ext == "jpeg") || (ext == "png") || (ext == "bmp")){
	   result = true;
      return true;
   }else{
   alert("Mohon upload file berextention .gif, .jpeg, .jpg atau .png");
   filename ='';
   result =false;
   return false;
   }
   return result;
}
