/*
*************************************************************************
*	Sample of Open Window 												*
*************************************************************************
function openADViewWindow(ad_id, width, height){
	if(ad_id!=0){
		var args = 'width='+(String)(parseFloat(width)+20)+',height='+(String)(parseFloat(height)+20)+',status=0,address=0,resize=0';
		var popwindow = window.open('index.php?view=ad_view&ad_id='+ad_id,'ad_stat', args);
		if(!popwindow){
			alert("Your POP UP Blocker blocking a new window\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
		}
	}else{
		alert('Invalid operation !!');
	}
}
*************************************************************************


*************************************************************************
*	Sample of Ajax Usage												*
*************************************************************************
function toggle_user_status(user_id, stat){
	if(user_id!=0 && (stat==0 || stat==1)){
		new ajax ('ajax.php', {postBody: 'method=toggle_user_status&user_id='+user_id+'&stat='+stat, onComplete: toggle_user_status_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}else{
		alert("Invalid operation. Please try later on !!");
	}
}

function toggle_user_status_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			alert("The users status has been changed successfully !!\n\nYou need to refresh this page to see the updated status");
			window.location.reload();
		}else{
			alert("We were not able to process your request\n\nPlease try later on");
		}
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}
*************************************************************************
*/

Number.prototype.formatMoney = function(c, d, t){
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

function checklogin(login_username, login_password, company_id, frm){
	new ajax ('ajax.php', {postBody: 'method=registrant_login&login_username='+login_username+'&login_password='+login_password+'&company_id='+company_id, onComplete: checklogin_callback, userVariable: frm});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function checklogin_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			uservar.submit();
		}else{
			alert("Login failed !!\n\nDid you enter your username and password properly?");
		}
	}else{
		alert("Could not connect to server!! Plase try later on");
	}
}

function check_duplicate_registration(frm){
	new ajax ('ajax.php', {postBody: 'method=check_duplicate_registration&email='+frm.email.value+'&login_username='+frm.login_username.value, onComplete: check_duplicate_registration_callback, userVariable: frm});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function check_duplicate_registration_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			uservar.submit();
		}else if(request.responseText=="DUPLICATE_EMAIL"){
			alert("This email address is already registered with us. Please try with different email address");			
		}else if(request.responseText=="DUPLICATE_USERNAME"){
			alert("This Username is already taken. Plase try with different Username");			
		}else{
			alert("We were not able to validate your email address right now. Please try later on");
		}
	}else{
		alert("Could not connect to server!! Plase try later on");
	}
}

function check_activation_status(registrant_id, frm){
	new ajax ('ajax.php', {postBody: 'method=check_activation_status&registrant_id='+registrant_id, onComplete: check_activation_status_callback, userVariable: frm});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function check_activation_status_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			uservar.submit();
		}else{
			alert("It seems that you have not varified your email address. Please check your mail and do the same to proceed");
		}
	}else{
		alert("Could not connect to server!! Plase try later on");
	}
}

function update_registration_price(cntrl){
	switch(cntrl.type){
		case "checkbox":
			/*======== Toggle the options (if any) =========*/
			form_elements = cntrl.form.getElements();
			for(i=0; i<form_elements.length; i++){
				if(form_elements[i].name.indexOf("event_extra_"+cntrl.value+"_option_id")>=0){
					if(cntrl.checked){
						form_elements[i].enable();
					}else{
						form_elements[i].disable();
						form_elements[i].checked = false;
					}
				}
			}
			/*==============================================*/
		break;
	}
	form_elements = cntrl.form.getElements();
	new_total = parseFloat($('base_price').value);
	for(i=0; i<form_elements.length; i++){
		if(form_elements[i].name.indexOf("_option_id")>=0){
			if(form_elements[i].checked){
				new_total += parseFloat($('event_extra_option_price_'+form_elements[i].value).getValue());
			}
		}else if(form_elements[i].name.indexOf("event_extra_ids")>=0){
			if(form_elements[i].checked){
				if($('event_extra_price_'+form_elements[i].value).getValue()!=''){
					new_total += parseFloat($('event_extra_price_'+form_elements[i].value).getValue());
				}
			}
		}
	}
	if($('currency_symbol_position').getValue()=='before'){
		$('grand_total').update($('currency_symbol').getValue() + ' ' +new_total.formatMoney($('currency_decimal_place').getValue(), $('currency_decimal_symbol').getValue(), $('currency_thousand_separator').getValue()));
	}else{
		$('grand_total').update(new_total.formatMoney($('currency_decimal_place').getValue(), $('currency_decimal_symbol').getValue(), $('currency_thousand_separator').getValue()) + ' ' + $('currency_symbol').getValue());
	}
	$('total_price').value = new_total;
}

function set_height(){
	document.getElementsByClassName('base_color_div')[0].style.height = Screen.getDocumentHeight()+'px';
}