﻿// JScript File

function HelloWorldSucceed(CallBackResult, eventArgs)
{

}

function GetSectionName(pageName)
{ 
 WebService.GetSectionName(pageName,SucceededCallback);
}

function SucceededCallback(CallBackResult, eventArgs)
{
        GetSucceedPageName(CallBackResult);
}



// Utility Js Functions Starts

 function getQuerystring(key, default_)
 {
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  
  if(qs == null)
    return default_;
  else
    return qs[1];
 }
 
 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function Empty(){alert('hi');}


function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

 function HasValueOrNot(txt,value)
 {    
    if(txt.value == "" )
    {
     txt.value = value;
    } 
 }   
 
 
function checkingNumberic(txt)
{
  if (IsNumeric(txt.value) == false) 
  {
      alert("Enter Only Numeric Values!");
      txt.value="0";
  }
}


function browserType()
{
    var type = 1;
    var browserName=navigator.appName;
   
    if (browserName != "Microsoft Internet Explorer")
    {
      type = 2;
    }
    return type;   
}


function checkdate(input){
var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
returnval=false;//alert("Invalid Date Format. Please correct and submit again.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
returnval=false;//alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}

function SetDate(input)
{
  if(checkdate(input) == false || input.value.length == 0)
  {
   var currentTime = new Date();
   var month = currentTime.getMonth() + 1;
   var day = currentTime.getDate();
   var year = currentTime.getFullYear();
   input.value = month + "/" + day + "/" + year;
  }
}


function checkTextAreaMaxLength(textBox,e, length)
{
    
        var mLen = textBox["MaxLength"];
        
        if(null==mLen)
            mLen=length;
        
        var maxLength = parseInt(mLen);
        if(!checkSpecialKeys(e))
        {
         if(textBox.value.length > maxLength-1)
         {
            if(window.event)//IE
              e.returnValue = false;
            else//Firefox
                e.preventDefault();
         }
    }   
}
function checkSpecialKeys(e)
{
    if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
        return false;
    else
        return true;
}    

function GetNumber(value)
{
    var num = new NumberFormat();
    num.setInputDecimal('.');
    num.setNumber(value);
    num.setPlaces('2', true);
    num.setCurrencyValue('');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_INSIDE);
    num.setNegativeFormat(num.PARENTHESIS);
    num.setNegativeRed(false);
    num.setSeparators(false, ',', ',');
    return num.toFormatted();
}



function imposeMaxLength(Event, Object, MaxLen){    
    return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40))
}


function IsUserExist(userName)
{ 
 WebService.IsUserExist(userName,UserExistSucceededCallback);
 
}

function UserExistSucceededCallback(CallBackResult, eventArgs)
{

        GetUserExistSuccess(CallBackResult);
}

function CheckDomainExists(DomainName)
{  
 WebService.IsDomainExist(DomainName,DomainExistSucceededCallback);
}

function DomainExistSucceededCallback(CallBackResult, eventArgs)
{
 GetDomainExistSuccess(CallBackResult);
}


function BrowseAllDomains(EmailId)
{ 
 WebService.FindAllDomainNames(EmailId,DomainNamesSucceededCallback);
}

function DomainNamesSucceededCallback(CallBackResult, eventArgs)
{
 GetDomainNamesSuccess(CallBackResult);
}




// Utility Js Functions End


function IsUserNameExist(TxtBoxDomainName)
{ 
 WebService.IsUserNameExist(TxtBoxDomainName,GetDomainExistSuccess);
}

function ShowAdsWebService(userId,status)
{
    WebService.ChangeShowAdsStatus(userId,status,OnSuccessShowAds);
}
function OnSuccessShowAds(CallBackResult,eventArgs)
{
    ShowAdsResult(CallBackResult);
}
