function popup_window(url,config) {
   	  mywindow = window.open (url,"popup_win",config);
	  mywindow.moveTo(0,0);
} 

function checkDateRange(start, end) {
   // Parse the entries
   var startDate = Date.parse(start);
   var endDate = Date.parse(end);
   var difference = (endDate - startDate) / (86400000 * 1);
   return difference;
}

function addDays(myDate,days) {
	return new Date(myDate.getTime() + days*24*60*60*1000);
}

function round_float(original,no_of_decimal_places) {
	if(no_of_decimal_places==1)
		var divider=10;
	else if ( no_of_decimal_places==2)
		var divider=100;
	else if ( no_of_decimal_places==3)
		var divider=1000;
	else if ( no_of_decimal_places==4)
		var divider=10000;
	var result=Math.round(original*no_of_decimal_places)/no_of_decimal_places;
	
	return result;
}


function intToFormat(nstrval)
    {
	 var nStr=nstrval.replace(/,/g,'');
     nStr += '';
     x = nStr.split('.');
     x1 = x[0];
     x2 = x.length > 1 ? '.' + x[1] : '';
     var rgx = /(\d+)(\d{3})/;
     var z = 0;
     var len = String(x1).length;
     var num = parseInt((len/2)-1);
 
      while (rgx.test(x1))
      {
        if(z > 0)
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        else
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
          rgx = /(\d+)(\d{2})/;
        }
        z++;
        num--;
        if(num == 0)
        {
          break;
        }
      }
     return x1 + x2;
    }


Date.prototype.format=function(format){var returnStr='';var replace=Date.replaceChars;for(var i=0;i<format.length;i++){var curChar=format.charAt(i);if(replace[curChar]){returnStr+=replace[curChar].call(this);}else{returnStr+=curChar;}}return returnStr;};Date.replaceChars={shortMonths:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],longMonths:['January','February','March','April','May','June','July','August','September','October','November','December'],shortDays:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],longDays:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],d:function(){return(this.getDate()<10?'0':'')+this.getDate();},D:function(){return Date.replaceChars.shortDays[this.getDay()];},j:function(){return this.getDate();},l:function(){return Date.replaceChars.longDays[this.getDay()];},N:function(){return this.getDay()+1;},S:function(){return(this.getDate()%10==1&&this.getDate()!=11?'st':(this.getDate()%10==2&&this.getDate()!=12?'nd':(this.getDate()%10==3&&this.getDate()!=13?'rd':'th')));},w:function(){return this.getDay();},z:function(){return"Not Yet Supported";},W:function(){return"Not Yet Supported";},F:function(){return Date.replaceChars.longMonths[this.getMonth()];},m:function(){return(this.getMonth()<9?'0':'')+(this.getMonth()+1);},M:function(){return Date.replaceChars.shortMonths[this.getMonth()];},n:function(){return this.getMonth()+1;},t:function(){return"Not Yet Supported";},L:function(){return(((this.getFullYear()%4==0)&&(this.getFullYear()%100!=0))||(this.getFullYear()%400==0))?'1':'0';},o:function(){return"Not Supported";},Y:function(){return this.getFullYear();},y:function(){return(''+this.getFullYear()).substr(2);},a:function(){return this.getHours()<12?'am':'pm';},A:function(){return this.getHours()<12?'AM':'PM';},B:function(){return"Not Yet Supported";},g:function(){return this.getHours()%12||12;},G:function(){return this.getHours();},h:function(){return((this.getHours()%12||12)<10?'0':'')+(this.getHours()%12||12);},H:function(){return(this.getHours()<10?'0':'')+this.getHours();},i:function(){return(this.getMinutes()<10?'0':'')+this.getMinutes();},s:function(){return(this.getSeconds()<10?'0':'')+this.getSeconds();},e:function(){return"Not Yet Supported";},I:function(){return"Not Supported";},O:function(){return(-this.getTimezoneOffset()<0?'-':'+')+(Math.abs(this.getTimezoneOffset()/60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()/60))+'00';},P:function(){return(-this.getTimezoneOffset()<0?'-':'+')+(Math.abs(this.getTimezoneOffset()/60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()/60))+':'+(Math.abs(this.getTimezoneOffset()%60)<10?'0':'')+(Math.abs(this.getTimezoneOffset()%60));},T:function(){var m=this.getMonth();this.setMonth(0);var result=this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,'$1');this.setMonth(m);return result;},Z:function(){return-this.getTimezoneOffset()*60;},c:function(){return this.format("Y-m-d")+"T"+this.format("H:i:sP");},r:function(){return this.toString();},U:function(){return this.getTime()/1000;}};

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    var return_var='';
    if(gy.length > 1 ) {
        for (i=0;i<gy.length;i++) {
                ft = gy[i].split("=");
                if(ft.length > 1 ) {
                    if (ft[0] == ji) {
                            return_var=ft[1];
                    }
                }
        }
    }
    return return_var;

}

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;


function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

function process_ajax_msg(msg) {
	msg_arr=msg.split("<<>>");
	//alert(msg_arr);
	if(msg_arr[0]=='1') {
		return msg_arr[1];
	}else {
		return '';	
	}
}


 
function get_today_date() {
	// Array of day names
	var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	// Array of month Names
	var monthNames = new Array(
	"01","02","03","04","05","06","07","08","09","10","11","12");
	var now = new Date();
	return monthNames[now.getMonth()]+"/"+now.getDate()+"/"+now.getFullYear();

}

function makePaginationResults(Increment,Page,Display,ConditionVar,FormName){
		//alert(FormName);
		$('#smartyDisplay').val(Display);
		$('#smartyPage').val(Page);
		$('#smartyIncrement').val(Increment);
		
		$('#'+FormName).submit();	
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
function changeImageCharacters(path)
{
 document.getElementById('imgCaptcha').src=path+"includes/createimage.php?sid="+Math.random();
}

/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 120 //set x offset of bar in pixels
var startY = 3 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("topbar").style.visibility="hidden"
}

function staticbar(){
	barheight=document.getElementById("topbar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}

/**************/

/*var del_address= function(addr_id,row) {
	if(confirm("Are you sure to delete the address?")) {
		del_address_confirm(addr_id,row);
	}
}
var del_reminder= function(reminder_id,row) {
	if(confirm("Are you sure to delete the reminder?")) {
		del_reminder_confirm(reminder_id,row);
	}
}
*/

var del_address_confirm=function(address_id,row) {

		address_id=$('#del_address_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_address_confirm&aid="+address_id,
				   complete: function() { 
				   							$('#'+row+address_id).remove();
											$('#del_action').hide('slow');
				   							//window.location=window.location.href;
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						$('#del_action_addr').hide('slow');	
				   }
				});	
}

var del_reminder_confirm=function(reminder_id,row) {
		reminder_id=$('#del_address_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_reminder_confirm&rid="+reminder_id,
				   complete: function() { 
				   							$('#'+row+reminder_id).remove();
											$('#del_action').hide('slow');
				   							//window.location=window.location.href;
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}


var del_car_confirm=function(car_id,row) {
		car_id=$('#del_address_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_car_confirm&cid="+car_id,
				   complete: function() { 
				   							$('#'+row+car_id).remove();
											$('#del_action').hide('slow');
				   							//window.location=window.location.href;
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}


var del_m_member_confirm=function(mem_id,row) {
		mem_id=$('#del_address_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_member_mem_confirm&mem_id="+mem_id,
				   complete: function() { 
				   							$('#'+row+mem_id).remove();
											$('#del_action').hide('slow');
				   							//window.location=window.location.href;
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}


var del_tw_confirm=function(members_tw_id,row) {
		members_tw_id=$('#del_user_tw_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_member_tw_confirm&members_tw_id="+members_tw_id,
				   complete: function() { 
				   							$('#'+row+members_tw_id).remove();
											$('#del_action').hide('slow');
				   							//window.location=window.location.href;
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}


var del_m_member_doc_confirm=function(member_docs_id,row) {

		member_docs_id=$('#del_mdoc_confirm').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_member_doc_confirm&member_docs_id="+member_docs_id,
				   complete: function() { 
				   							$('#'+row+member_docs_id).remove();
											$('#del_action').hide('slow');
										},
				   success: function(done_msg){
					  // alert(done_msg);
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}


var del_m_mem_pol_confirm=function(other_portfolio_id ,row) {
		other_portfolio_id=$('#m_mem_pol').attr('title');
			$.ajax({
				   type: "POST",
				   cache:false,
				   url: js_Site_Global_Ajax_Path+"member_fns.php",
				   data: "condition=del_member_otherpolicy_confirm&other_portfolio_id="+other_portfolio_id,
				   complete: function() { 
				   							$('#'+row+other_portfolio_id).remove();
											$('#del_action').hide('slow');
										},
				   success: function(done_msg){
						 var done_msg=done_msg.split('<<>>');
						 if(done_msg[0]=='0') {
							  $('.fail_msg').html(done_msg[1]);
							  $('#id_fail_msg').show();
						 } else {
							  $('.succ_msg').html(done_msg[1]);
							  $('#id_succ_msg').show();
						 }
						// $('#add_new_address_').fancybox.resize
				   }
				});	
}

/* outline dotted function - SML */
var anchorEventIsMouse = true;
$(document).ready(function() {

$('a,input,img').mousedown(function() {
  anchorEventIsMouse = true;
  this.hideFocus = true;  /* IE6-7 */
  this.style.outlineStyle = 'none';  /* FF2+, IE8 */
  });

});
