
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_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_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 Loading(st) {
		if(st == 'start') {
			$('#loading_mask').fadeIn('slow', function(){
				$('#loading_image').fadeIn('slow');		   
			});
		}
		else {
			$('#loading_image').fadeOut('slow', function(){
				$('#loading_mask').fadeOut('slow');		   
			});
		}
	}
	
	$(document).ready(function(){
		
		// Important! no-cache
		$.ajaxSetup({cache: false});
		
		$('textarea[maxlength]').keyup(function(){
			var max = parseInt($(this).attr('maxlength'));
			if($(this).val().length > max){
				$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
			}
			$(this).parent().parent().find('.charsRemaining').html((max - $(this).val().length) + ' characters remaining');
		});
		
		$('input:text[maxlength]').keyup(function(){
			var max = parseInt($(this).attr('maxlength'));
			if($(this).val().length > max){
				$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
			}
			$(this).parent().parent().find('.charsRemaining').html((max - $(this).val().length) + ' characters remaining');
		});
	});
	
	
	function ShowError(header, message) {
		$("div#errMessage").html(message);
		$("div#errMessage").dialog({bgiframe: true, title:header, resizable: false, modal: true, buttons: {Ok: function() {$(this).dialog('close');$(this).dialog('destroy');}}});
		$("div#errMessage").dialog("open");	
	}
	
	function ShowConfirmation(header, message) {
		$("div#errMessage").html(message);
		$("div#errMessage").dialog({bgiframe: true, title:header, resizable: false, modal: true, buttons: { 'Delete': function() { $(this).dialog('close'); $(this).dialog('destroy');}, Cancel: function() { $(this).dialog('close');$(this).dialog('destroy'); }}});
		$("div#errMessage").dialog("open");	
	}
	
	function ShowDetails(header, message, ht, wt) {
		if(!ht) ht=272;
		if(!wt) wt=450;
		$("div#errMessage").html(message);
		$("div#errMessage").dialog({bgiframe: true, title:header, height:ht, width:wt, resizable: false, modal: true, 
						close: function(){$("div#errMessage").dialog('destroy'); }});
		$("div#errMessage").dialog("open");	
	}
	
	function ShowForm(header, message) {
		$("div#pubForm").html(message);
		$("div#pubForm").dialog({
			bgiframe: true,
			autoOpen: false,
			title:header,
			height: 310,
			width:600,
			position: 'center',
			modal: true,
			buttons: {
				'Submit': function() {
					var bValid = true;				
					var Pubname = $('#PubName').val();			
					var Pubemail = $.trim($("#PubEmail").val());
					var Pubcompanyname = $.trim($("#PubCompany").val());
					var Pubphone = $.trim($("#PubPhone").val());
					var strMessage = "";
					var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_"; 
					var iChars_email = "!#$%^&*()+=-[]\\\';,/{}|\":<>?~"; 
					
					if(Pubname == '') {
						bValid = false;
						strMessage += 'Please enter name<br>';
					}					
					else if(!CheckString(Pubname, iChars)) {
						bValid = false;
						strMessage += 'Please enter valid name<br>';
					}
					if(Pubemail == "") {
						strMessage +='Please enter email id<br>';
						bValid = false;
					}
					else if(!(/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i.test(Pubemail))) {
						bValid = false;
						strMessage +='Please enter a valid email id<br>';								
					}			
					
					if(Pubcompanyname == "") {
						bValid = false;
						strMessage +='Please enter company name<br>';
					}
					if(Pubphone == "") {
						bValid = false;
						strMessage +='Please enter phone number<br>';
					}
					else if(isNaN(Pubphone)){
						bValid = false;
						strMessage +='Please enter valid phone number<br>';
					}
					
					
					/*//allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"username",3,16);
					bValid = bValid && checkLength(email,"email",6,80);
					bValid = bValid && checkLength(password,"password",5,16);

					bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
					*/
					
					if (bValid)
					{						
						$.post(ROOT+"/json/publisher.php?action=insert_publisher", $("form#frmPublisher").serializeArray(), function(dt){
							
							if(dt.result == "success") {		
								ShowError("Publisher Alert", 'Publisher created');						
							}
							else if(dt.result == "duplicate_publisher") {
								ShowError("Publisher Alert", 'Email id already exists');
							}							
						});			
							/*
							var val = '<br>Thank you for your interest in MOBL21, someone'+
							  ' from our business development team will contact you within the next 48 hrs.';
							 $("div#errMessage").html(val);
							 $("div#errMessage").dialog({bgiframe: true, width:400, height:300, title:header, resizable: false, modal: true, buttons: {Ok: function() {$(this).dialog('close');$(this).dialog('destroy');}}});
		                     $("div#errMessage").dialog("open");	
							$(this).dialog('close');		
							$(this).dialog('destroy');
							*/
					}
					else
					{		
						ShowError("Publisher Alert", strMessage);
					}
				},
				Cancel: function() {
					$(this).dialog('close');
					$(this).dialog('destroy');
				}
			},
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
		});
		$("div#pubForm").dialog("open");	
	}
	
	
	function ShowPartnerForm(header, message) {
		
		$("div#partnerForm").html(message);
		$("div#partnerForm").dialog({
			bgiframe: true,
			autoOpen: false,
			title:header,
			height: 310,
			width:600,
			position: 'center',
			modal: true,
			buttons: {
				'Submit': function() {
					var bValid = true;				
					var Pubname = $('#PName').val();			
					var Pubemail = $.trim($("#PEmail").val());
					var Pubcompanyname = $.trim($("#PCompany").val());
					var Pubphone = $.trim($("#PPhone").val());
					var strMessage = "";
					var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_"; 
					var iChars_email = "!#$%^&*()+=-[]\\\';,/{}|\":<>?~"; 
					
					if(Pubname == '') {
						bValid = false;
						strMessage += 'Please enter name<br>';
					}					
					else if(!CheckString(Pubname, iChars)) {
						bValid = false;
						strMessage += 'Please enter valid name<br>';
					}
					if(Pubemail == "") {
						strMessage +='Please enter email id<br>';
						bValid = false;
					}
					else if(!(/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i.test(Pubemail))) {
						bValid = false;
						strMessage +='Please enter a valid email id<br>';								
					}			
					
					/*if(Pubcompanyname == "") {
						bValid = false;
						strMessage +='Please enter company name<br>';
					}*/
					if(Pubphone == "") {
						bValid = false;
						strMessage +='Please enter phone number<br>';
					}
					else if(isNaN(Pubphone)){
						bValid = false;
						strMessage +='Please enter valid phone number<br>';
					}
					
					
					if (bValid)
					{						
						$.post(ROOT+"/json/publisher.php?action=insert_partner", $("form#frmPartners").serializeArray(), function(dt){
							//alert(dt.result);
							//if(dt.result =="success") {		
								//ShowError("Partner Alert", 'Partner created');						
							//}												
						});			
			
							var val = '<br>Thank you for your interest in MOBL21, someone'+
							  ' from our business development team will contact you within the next 48 hrs.';
							 $("div#errMessage").html(val);
							 $("div#errMessage").dialog({bgiframe: true, width:400, height:300, title:header, resizable: false, modal: true, buttons: {Ok: function() {$(this).dialog('close');$(this).dialog('destroy');}}});
		                     $("div#errMessage").dialog("open");	
							$(this).dialog('close');		
							$(this).dialog('destroy');
					}
					else
					{		
						ShowError("Partner Alert", strMessage);
					}
				},
				Cancel: function() {
					$(this).dialog('close');
					$(this).dialog('destroy');
				}
			},
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
		});
		$("div#partnerForm").dialog("open");	
	}
	
	
	function simple_tooltip(name){
		$.each(function(i){
			
			$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
			var my_tooltip = $("#"+name+i);
		
			$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
					my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			}).mouseout(function(){
					my_tooltip.fadeOut(400);
			});
		});
	}

	
	$(document).ready(function(){
		$.ajaxSetup({cache: false});
		$("#txtNewPass").val("");
	});
	
	function ResetForgotPassword() {		
		var email = $.trim($("#hdnAdminEmailId").val());		
		var newpass = $.trim($("#txtNewPass").val());
		var confirmpass = $.trim($("#txtConfirmPass").val());
		var iChars = "!@#$%^&*()+=-[]\\;,./{}|:<>?~_"; 
		var token = $.trim($("#hdnAdminToken").val());
		
		var errFlag = false;
		var strMessage = "";
				
		/*if(currentpass == "") {
			errFlag = true;
			strMessage += " - Please enter current password<br>";
		}*/
		
		if(newpass == "") {
			errFlag = true;
			strMessage += "Please enter a new password<br>";
		} else if(!CheckString(newpass, iChars)) {
			errFlag = true;
			strMessage += "Please enter a valid new password<br>";
		}
		
		if(confirmpass == "") {
			errFlag = true;
			strMessage += "Please confirm your password<br>";
		}
		
		if(newpass!='' && confirmpass!='') {
			if(newpass != confirmpass) {
				errFlag = true;
				strMessage += "Password mismatch<br>";
			}
			else
			{
				$("#txtPassword").val(newpass);
			}
		}
		
		if(errFlag) {
			ShowError("Change Password Alert", strMessage);
		}
		else {
			$.post(ROOT+"/json/admin.php?action=change_forgot_password", $("form#frmChgPasswordForgot").serializeArray(), function(dt){																																	   
				if(dt.result == "success") {
					$("#showChgForgotPassword").hide();
					$("#proceedtologin").show();
					ResetOverPassword();					
					//ShowError("Change Password", "Password changed successfully");
				} else {
					ShowError("Change Password Alert", 'Sorry! Your token is invalid');			
				}
			},"json");
			
		}
	}
	function ResetOverPassword() {
		//$("#txtCurrentPass").val("");
		$("#txtNewPass").val("");
		$("#txtConfirmPass").val("");				
	}
	
	function ToLogin(){	
		$("#frmChgPasswordForgot").submit();
	}
	
	function ShowLightBox(message) {
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#fade').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#fade').fadeIn(1000);	
		$('#fade').fadeTo("slow",0.8);	
		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(message).css('top',  winH/2-$(message).height()/2);
		$(message).css('left', winW/2-$(message).width()/2);
	
		//transition effect
		$(message).fadeIn(2000); 
	}
	
	function PageLoader(status) {
		//var winH = $(window).height();
		//var winW = $(window).width();
		
		//$('#image_pre_loader').css({'top': winH/2-$('#image_pre_loader').height()/2, 'left':winW/2-$('#image_pre_loader').width()/2});
		if($('#image_pre_loader').length > 0 && $('#lightbox-overlay').length > 0) {
			if(status == "load") {
				$('#image_pre_loader').fadeIn('slow', function () {
					$('#lightbox-overlay').fadeIn('slow');
				});
			}
			
			if(status == "unload") {
				$('#image_pre_loader').fadeOut('slow', function () {
					$('#lightbox-overlay').fadeOut('slow');
				});
			}
		}
	}
	
	
	
	function Help(pagename) {		
		PageLoader('load');
		$.get(ROOT+"/json/help.php?action="+pagename, function(dt){
			PageLoader('unload');
			$("div#help").html(dt);
			$("div#help").dialog({bgiframe: true, title:'Help', resizable: false, modal: true, width:960, height: 500, close:function() { $("div#help").html(''); } });
			$("div#help").dialog("open");	
			
			$("div#help").find(".contentFaq").hide();
			$('<img src="'+ROOT+'/images/right_faq.png" class="arrow" />').insertBefore($("div#help").find('a h1')); 				   
			$("div#help").find("a h1").click(function(){
				if($(this).is(".active")) {
					$(this).toggleClass("active");
					$('.arrow.active').attr('src', ROOT+'/images/down_faq.png'); // change the image src of the current ACTIVE image to have an INACTIVE state.
					$(this).parent().next(".contentFaq").slideToggle();
				} else {
					$(".contentFaq:visible").slideUp("fast"); // close all visible divs with the class of .content
					$("h1.active").removeClass("active");  // remove the class active from all h1's with the class of .active
					$(this).toggleClass("active");
					$('.arrow.active').attr('src', ROOT+'/images/right_faq.png'); // change the image src of the current ACTIVE image to have an INACTIVE state.
					$(".arrow").addClass('active');
					$(this).siblings('.arrow.active').attr('src', ROOT+'/images/down_faq.png'); // change the image src of the new active image to have an active state.
					$(this).parent().next(".contentFaq").slideToggle();
				}
				return false;
			});
		}, "html");
	}

//trim leading 0 (zero) from text input fields 

function trimNumber(s) {
  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  return s;
}




function ShowVideoBoxs(message, filetype, file) { 
	var htm ="";
	
	if(filetype == "audio") {
		$(message).css('width', '225px');
		$(message).css('height', '80px');
	}
	else if(filetype == "video") {
		$(message).css('width', '410px');
		$(message).css('height', '360px');
	}
	
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	
	//Set height and width to mask to fill up the whole screen
	$('#fade').css({'width':maskWidth,'height':maskHeight});	
	//transition effect		
	$('#fade').fadeIn(1000);	
	$('#fade').fadeTo("slow",0.8);	
	
	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
	
	//Set the popup window to center
	$(message).css('top',  winH/2-$(message).height()/2);
	$(message).css('left', winW/2-$(message).width()/2);
	
	var audio_dim = [200,40];
	var video_dim = [380,320];
	
	if(filetype =="video") 
		htm='<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+video_dim[0]+'" height="'+video_dim[1]+'" PLUGINSPAGE="http://www.apple.com/quicktime/">'+
		'<param name="src" value="http://'+document.domain+file+'" />'+
		'<param name="wmode" value="window" />'+
		'<param name="controller" value="true" />'+
		'<param name="autoplay" value="false" />'+
		'<param name="loop" value="false" />'+
		'<param name="scale" value="tofit" />'+
		'<embed src="http://'+document.domain+file+'" width="'+video_dim[0]+'" height="'+video_dim[1]+'" scale="tofit" controller="true" PLUGINSPAGE="http://www.apple.com/quicktime/" autoplay="false" loop="false" wmode="window"></embed></object>';		
		
	if(filetype=="audio")
		htm='<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+audio_dim[0]+'" height="'+audio_dim[1]+'" PLUGINSPAGE="http://www.apple.com/quicktime/">'+
		'<param name="src" value="http://'+document.domain+file+'" />'+
		'<param name="wmode" value="window" />'+
		'<param name="autoplay" value="false" />'+
		'<param name="loop" value="false" />'+
		'<param name="controller" value="true" />'+
		'<param name="scale" value="tofit" />'+
		'<embed src="http://'+document.domain+file+'" width="'+audio_dim[0]+'" height="'+audio_dim[1]+'" autoplay="false" loop="false" wmode="window" PLUGINSPAGE="http://www.apple.com/quicktime/"></embed></object>';		
	
	
	
	$('#flashContent').html(htm);	
	
	//transition effect
	$(message).show(); 
	
	$("#fade").bind("click", function(){
		$('#fade, #modal_message').hide();
	});	
	
}	