function el ( elementName ){

        try {
                return document.getElementById(elementName);
        } catch(e){
                return false;
        }
}


function checkInviteForm(){

//      try {
                var error = '';

                your_name       = el('your_name');
                your_email      = el('your_email');
                your_voipaxname = el('your_voipax_name');
                friendemail     = el('friend_email_1');

                if ( your_name.value.length < 1 ) {
                        error = error + '<li>' + JAVA_L_ERROR_INVITE_YOUR_NAME + '\n';
                }
        
                if ( your_email.value.length < 1 ) {
                        error = error + '<li>' + JAVA_L_ERROR_INVITE_YOUR_EMAIL + '\n';
                }
        
                if ( your_voipaxname.value.length < 1 ) {
                        error = error + '<li>' + JAVA_L_ERROR_INVITE_YOUR_VOIPAX_NAME + '\n';     
                }
        
                if ( friendemail.value.length < 1 ) {
                        error = error + '<li>' + JAVA_L_ERROR_INVITE_YOUR_FRIEND_MAIL + '\n';
                }

                if ( error.length > 0 ) {
                        el('invite_error_message').innerHTML = '<ul>' + error + '</ul>';
                        el('invite_error_message_tr').className = 'visible';

                        return false;
                } else {

                        el('invite_form').submit();
                        return true;
                }
/*
        } catch(e) {
                return false;
        }
*/
}

/*********************************************************************
*
*	Öffnet ein Fenster
*
*********************************************************************/

function openWindow(theURL,winName, toWidth, toHeight, scrollbars, featuresGiven) { //v2.0

	var features = "";
	
	myScreenWidth = screen.width;
	myScreenHeight = screen.height;

	leftPosition 	= (myScreenWidth - toWidth) / 2 ;
	topPosition 	= (myScreenHeight - toHeight) / 2 ;

	if ( !featuresGiven ) {
		features = 'addressbar=no,toolbar=no,statusbar=no,resizable=no';
	} else {
		features = featuresGiven;
	}

	if ( scrollbars ) {
		features= features+',scrollbars='+scrollbars+',';
	}

	features = features + ", height="+toHeight+", width="+toWidth+", left="+leftPosition+", top="+topPosition;
	try {
		myWindow = window.open(theURL,winName,features);
		myWindow.focus();
	} catch (e) {
		alert("Das PopUp wurde aufgrund eines PopUp Blockers geblockt!");
		return false;
	}

}

function openCloseKlappbox( elId , color) {
	var id;
	var klappbox_number;
		for (var i = 0;i<document.getElementsByTagName('td').length;i++) {
			if (document.getElementsByTagName('td')[i].id.search('^klappbox_arrow_')> -1) {
				id = document.getElementsByTagName('td')[i].id;
				klappbox_number = id.split('_')[2];					
				if (id != 'klappbox_arrow_'+elId) {
					try {   el('klappbox_text_' + klappbox_number).className = 'klappbox_close'; }
					catch(e){}
					try {   el('klappbox_arrow_' + klappbox_number).className='klappbox_arrow_close_'+color; }
					catch(e){}
				}			
			}
		}		
	if ( el('klappbox_text_' + elId).className == 'klappbox_close' ) {
	      try {  el('klappbox_text_' + elId).className = 'klappbox_open'; }
	      catch(e){}
	      try {   el('klappbox_arrow_' + elId ).className='klappbox_arrow_open_'+color; }
	      catch(e){}
	} else {
	      try {   el('klappbox_text_' + elId).className = 'klappbox_close'; }
	      catch(e){}
	      try {   el('klappbox_arrow_' + elId ).className='klappbox_arrow_close_'+color; }
	      catch(e){}
	}
}

function ancor( url ){

	document.location = ''+url+'';

}

function highlightRow(id) {
	try{
		el('crow['+id+']').className = 'currentrow crhighlight';
	}catch(e) {
	}
}

function dehighlightRow(id) {
	try{
		el('crow['+id+']').className = 'currentrow crnone';
	}catch(e) {
	}
}

function getCountryCode(param) {
	var tmp = param.split('|');
	return tmp[0];
}

function getCountryID(param) {
	var tmp = param.split('|');
	return tmp[1];
}

function getSMSPrice(param) {
	var tmp = param.split('|');
	return tmp[2];
}

function getSMSFree(param) {
	var tmp = param.split('|');
	return tmp[3];
}

function limitTextCountdown(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function processSMSElements(smsText, charCounter, smsCounter) {
	charCounter.value = smsText.value.length;
	remainder = mod (charCounter.value,160);
	if (remainder == 0) {
		subtrk = 1;
	} else  {
		subtrk = 0;
	}
	sms_count        = (Math.floor(charCounter.value/160) + 1) - subtrk;
	smsCounter.value = sms_count;
}

function getSMSTemplateContent(smsText, smsTemplateContent) {
	smsText.value = smsTemplateContent;
}

function custRound(x,places) {
	return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

function mod (divisee,base) {
	return Math.round(divisee - (Math.floor(divisee/base)*base));
}

function resetAll(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11)  {
	field1.value  = "0";
	field2.value  = "0";
	field3.value  = "0";
	field4.value  = "";
	field5.value  = "";
	field6.value  = "";
	field7.value  = "";
	field8.value  = "";
	field9.value  = "";
	field10.value = "";
	field11.value = "";
}

function resetSMSAnswer(field1, field2, field3, field4, field5)  {
	field1.value  = "0";
	field2.value  = "0";
	field3.value  = "0";
	field4.value  = "";
	field5.value  = "";
}

function resetSendTime(dayVar, monthVar, yearVar, timeVar, schedVar)  {
	var datum = new Date();
	
	var jDay   = datum.getDate();
	var jMonth = datum.getMonth() + 1; //In Javascript 0 = Jan, 1 = Feb, ..., 11 = Dec. So always increment the value
	var jYear  = datum.getFullYear();
	var jTime  = datum.getHours() + ":" + datum.getMinutes();
	
	dayVar.value   = jDay; 
	dayVar.disabled = 1;
	monthVar.value = jMonth;
	monthVar.disabled = 1;
	yearVar.value  = jYear;
	yearVar.disabled = 1;
	timeVar.value  = jTime;
	timeVar.disabled = 1;
	schedVar.value = "0";	
	schedVar.checked = 1;	
}

function disableSendTimeElems(dayVar, monthVar, yearVar, timeVar)  {
	dayVar.disabled   = 1;
	monthVar.disabled = 1;
	yearVar.disabled  = 1;
	timeVar.disabled  = 1;	
	document.send_sms.theTime.disabled  = 0;
}

function enableSendTimeElems(dayVar, monthVar, yearVar, timeVar)  {
	dayVar.disabled   = 0;
	monthVar.disabled = 0;
	yearVar.disabled  = 0;
	timeVar.disabled  = 0;	
	document.send_sms.theTime.disabled  = 1;	
}

var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();

   document.send_sms.theTime.value = "" 
                                   + tDate.getHours() + ":" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

function HideAllSMSDivWindows (numOfWin) {
	for (var i = 1; i<=numOfWin; i++) {
		document.getElementById("SMSMessageID" + i).style.visibility = "hidden";
		document.getElementById("SMSOKCancelID" + i).style.visibility = "hidden";
	}
}

function loadThickBox(anumber,bnumber)
{
	tb_show('Voipax Instant Call', 'index.customer.php?mod=pc&a_number='+anumber+'&b_number='+bnumber+'&height=400&width=350&modal=true', null);
}

function loadThickBoxFreeBuzzer(anumber,bnumber)
{
	tb_show('FREEBUZZER Instant Call', '/freebuzzer/instant-call.php?&a_number='+anumber+'&b_number='+bnumber+'&height=500&width=800&modal=true', null);
}

function loadThickBoxRinglocal(anumber,bnumber)
{
	tb_show('Ringlocal Instant Call', '/ringlocal/instant-call.php?&a_number='+anumber+'&b_number='+bnumber+'&height=500&width=800&modal=true', null);
}

function closeThickBox()
{
	tb_remove();
}