// JavaScript Document
var site_url="http://www.indiaabasan.com/";
function getScrollTop() {
  if ( document.documentElement.scrollTop )
    return document.documentElement.scrollTop;

  return document.body.scrollTop;
}

function scrollHandler() {
   var e = document.getElementById('rc_notify');
   e.style.top = getScrollTop();
   
   
}

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

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

  elem.innerHTML = str;
}

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

function get_state(country_id,cont_id)
{
 showNotify("Loading...");
	if(country_id=="")
	{
	    //$("#state").html("<option value=''>--select--</option>");
		$("state").update("<option value=''>--select--</option>");
	    //$("#city").html("<option value=''>--select--</option>");
		$("city").update("<option value=''>--select--</option>");
	    //$("#area").html("<option value=''>--select--</option>");
		$("area").update("<option value=''>--select--</option>");
	
	
	}
   
  // $('#'+cont_id+'').load('index.php?/misc/get_state/'+country_id,function(str){});
  new Ajax.Updater(cont_id,'index.php?/misc/get_state/'+country_id);
   hideNotify();
   
}

function get_city(state_id,cont_id)
{
  showNotify("Loading...");
	if(state_id=="")
	{
	   //$("#city").html("<option value=''>--select--</option>");
	   //$("#area").html("<option value=''>--select--</option>");
	   $("city").update("<option value=''>--select--</option>");
	   $("area").update("<option value=''>--select--</option>");
	
	}
 
   //$('#'+cont_id+'').load('index.php?/misc/get_city/'+state_id,function(str){});
   new Ajax.Updater(cont_id,'index.php?/misc/get_city/'+state_id);
   hideNotify();
   
}


function get_area(city_id,cont_id)
{
	 showNotify("Loading...");
	 if(city_id=="")
	{
	  
	   //$("#area").html("<option value=''>--select--</option>");
	    $("area").update("<option value=''>--select--</option>");
	}
   
     //$('#'+cont_id+'').load('index.php?/misc/get_area/'+city_id,function(str){});
    new Ajax.Updater(cont_id,'index.php?/misc/get_area/'+city_id);
   hideNotify();
   
}

function get_location(city_id,obj)
{
	 $(obj).hide();

	 if(city_id=="")
	 {
	    $(obj).update("<option value=''>All</option>");
	 }
   
     //$('#'+cont_id+'').load('index.php?/misc/get_area/'+city_id,function(str){});
    new Ajax.Updater(obj,site_url+'misc/get_location/'+city_id);
  $(obj).show();
   
}

function multiple_location(city_id,formname,divobj,cr_objname)
{
	$(cr_objname+"_id").value="";	
	 //showNotify("Loading...");
//
	$(divobj).update("Loading...");
	 if(city_id=="")
	 {
	    $(divobj).update("No Record Found");
		return;
	 }
   
     //$('#'+cont_id+'').load('index.php?/misc/get_area/'+city_id,function(str){});
    new Ajax.Updater(divobj,site_url+'misc/get_location/'+city_id+'/'+formname+'/multiple/'+cr_objname);
   hideNotify();
   
}

function change_back_office_user_stat(user_id)
{
	
	  if(confirm('Change current status of this user?'))
	  {
	        showNotify("Loading...");
			var cont_id="backlist_"+user_id;
		    //$('#'+cont_id+'').load('index.php?/backoff_user/edit_stat/'+user_id,function(str){});
			new Ajax.Updater(cont_id,'index.php?/backoff_user/edit_stat/'+user_id);
		   hideNotify();
	  }
}
function change_emp_stat(emp_id)
{
	
	  if(confirm('Change current status of this Employee?'))
	  {
	        showNotify("Loading...");
			var cont_id="backlist_"+emp_id;
		    //$('#'+cont_id+'').load('index.php?/backoff_user/edit_stat/'+user_id,function(str){});
			new Ajax.Updater(cont_id,'index.php?/employee_manage/edit_stat/'+emp_id);
		   hideNotify();
	  }
}

function change_frnch_stat(frnch_id)
{
	
	 if(confirm('Change current status of this user?'))
	  {
	     showNotify("Loading...");
	      //alert(user_id);
		 var cont_id="frnch_"+frnch_id;
		 new Ajax.Updater(cont_id,'index.php?/franchise/edit_stat/'+frnch_id);
		 //$('#'+cont_id+'').load('index.php?/franchise/edit_stat/'+frnch_id,function(str){});
		 hideNotify();
	  }

	
}
function change_site_user_stat(user_id)
{
	
	 if(confirm('Change current status of this user?'))
	  {
	     showNotify("Loading...");
	      //alert(user_id);
		 var cont_id="user_"+user_id;
		 new Ajax.Updater(cont_id,'index.php?/site_user_management/edit_stat/'+user_id);
		 //$('#'+cont_id+'').load('index.php?/franchise/edit_stat/'+frnch_id,function(str){});
		 hideNotify();
	  }

	
}

function change_project_stat(proj_id)
{
	
	 if(confirm('Change current status of this Project?'))
	  {
	     showNotify("Loading...");
	      //alert(user_id);
		 var cont_id="proj_"+proj_id;
		 new Ajax.Updater(cont_id,'index.php?/property/edit_stat/'+proj_id);
		 //$('#'+cont_id+'').load('index.php?/franchise/edit_stat/'+frnch_id,function(str){});
		 hideNotify();
	  }

	
}
function change_ad_management_stat(ad_id)
{
	
	 if(confirm('Change current status of this user?'))
	  {
	     showNotify("Loading...");
	      //alert(user_id);
		 var cont_id="ad_"+ad_id;
		 new Ajax.Updater(cont_id,'index.php?/ad_management/edit_stat/'+ad_id);
		 //$('#'+cont_id+'').load('index.php?/franchise/edit_stat/'+frnch_id,function(str){});
		 hideNotify();
	  }

	
}
function change_newsletter_management_stat(news_id)
{
	
	 if(confirm('Change current status of this news?'))
	  {
	     showNotify("Loading...");
	      //alert(user_id);
		 var cont_id="news_"+news_id;
		 new Ajax.Updater(cont_id,'index.php?/newsletter_management/edit_stat/'+news_id);
		 //$('#'+cont_id+'').load('index.php?/franchise/edit_stat/'+frnch_id,function(str){});
		 hideNotify();
	  }

	
}

function change_link_exchange_stat(link_id)
{
		if(confirm('Change current status of this link?'))
		{
				showNotify("Loading...");
				var cont_id="link_"+link_id;
				new Ajax.Updater(cont_id,'index.php?/link_exchange/edit_stat/'+link_id);
				hideNotify();
		}
}

 //*********Thanks steven levithan for giving us such a good trim utility in javascript**********************//
function trim11 (str) {
	str = str.replace(/^\s+/, '');
	
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}


function checkNumeric(e) 
		{
		
		var keynum
		var keychar
		var numcheck
		
		if(window.event) // IE
		{
			keynum = e.keyCode
		}
		else if(e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which
		}
		
		//alert(keynum);
		if(keynum==8 ||keynum==9 ||(keynum>=48 && keynum<=59)||(keynum>=96 && keynum<=105) || keynum==110   )
		{
			return true;	
		}
		else
		{
			keychar = String.fromCharCode(keynum)
			numcheck = /\d/
			return numcheck.test(keychar)	
		}
		/*if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
		else
		cntfield.value = maxlimit - field.value.length;*/
		}
		
		
		

function checkNumeric_dot(e)
               {
               
               var keynum
               var keychar
               var numcheck
               
               if(window.event) // IE
               {
                       keynum = e.keyCode
               }
               else if(e.which) // Netscape/Firefox/Opera
               {
                       keynum = e.which
               }
               
               
               if(keynum==8)
               {
                       return true;        
               }
               else
               {
                       keychar = String.fromCharCode(keynum)
                       numcheck = /\d|\./
                       return numcheck.test(keychar)        
               }
               /*if (field.value.length > maxlimit) // if too long...trim it!
               field.value = field.value.substring(0, maxlimit);
               // otherwise, update 'characters left' counter
               else
               cntfield.value = maxlimit - field.value.length;*/
               }
 

/**
 * DHTML date validation script. 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=2100;

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,fieldName){
	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("The date format should be : dd/mm/yyyy in "+fieldName+" field")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month in "+fieldName+" field")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+"in "+fieldName+" field")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date in "+fieldName+" field")
		return false
	}
return true
}

function open_pop_up(url,width,height)
{
 var scr_width=screen.availWidth;
 var scr_height=screen.availHeight;
 leftPos=(scr_width-width)/2;
 topPos=(scr_height-height)/2;
 
  window.open(url,"popup","menubar=0,resizable=0,scroll=0,status=0,width="+width+",height="+height+",left="+leftPos+",top="+topPos);

}
function get_disp_name(val,obj)
{
	new Ajax.Updater(obj,'index.php?/misc/get_disp_name/'+val);
}

function disp_name(val)
{
   	$('display_name').value='';
	 $('display_name').value=val;
}
