﻿function changeClass(element, className)
{
	element.className = className;
}

//Functon to get X-poisition of element 
function getRealLeft(element)
{
	var position = element.offsetLeft;
	var parent = element.offsetParent;
	while (parent != null)
		{
		position += parent.offsetLeft;
		parent = parent.offsetParent;
		}
	return position;
}
 function formatAsPhoneNumber(str){ 
        while (str.indexOf("-") > -1){
            str = str.replace(/-/i, "");
        }
        if (/^\d{10}$/.test(str) == true){
            return str.substr(0, 3) + "-" + str.substr(3, 3) + "-" + str.substr(6, 4);
        }else if (/^\d{11}$/.test(str) == true){
            return str.substr(0, 1) + "-" + str.substr(1, 3) + "-" + str.substr(4, 3) + "-" + str.substr(7, 4);
        }else{
            return str;
        }
    }

//----------------------------------------
//Use in Sales Report Edit
function errorMessageShow()
{
	eval(getElement('ErrorMessageDiv').onShow);
	getElement('ErrorMessageDiv').style.display = 'block';
	getElement('ErrorMessageClose').focus();
	eval(getElement('ErrorMessageDiv').AfterShow);
}


function errorMessageClose()
{
	eval(getElement('ErrorMessageDiv').onClose);
	eval(getElement('ErrorMessageDiv').BeforeClose);
	getElement('ErrorMessageDiv').style.display = 'none';
}

  function errorMessageGetOnShow()
    {
      return getElement('ErrorMessageDiv').onShow;
    }

  function errorMessageSetOnShow(objHandler)
    {
	getElement('ErrorMessageDiv').onShow = objHandler;	
    }

  function errorMessageGetOnClose()
    {
      return getElement('ErrorMessageDiv').onClose;
    }

  function errorMessageSetOnClose(objHandler)
    {
	getElement('ErrorMessageDiv').onClose = objHandler;	
	}

		
	function errorMessageSetAfterShow(objHandler)
	{
		getElement('ErrorMessageDiv').AfterShow = objHandler;
	}

	function errorMessageSetBeforeClose(objHandler)
	{
		getElement('ErrorMessageDiv').BeforeClose = objHandler;
	}

  function errorMessageGetInstruction()
    {
    return getElement('ErrorMessageInstruction').innerHTML;
    }

  function errorMessageSetInstruction(strInstruction)
    {
    getElement('ErrorMessageInstruction').innerHTML = strInstruction;
    }
    
  function errorMessageGetItems()
    {
    return getElement('ErrorMessageItems').innerHTML;
    }

  function errorMessageSetItems(strItems)
    {
    getElement('ErrorMessageItems').innerHTML = strItems;
    }

  function errorMessageSetPosition(x, y)
    {
    getElement('ErrorMessageDiv').style.left = x + 'px';
    getElement('ErrorMessageDiv').style.top = y + 'px';
	}

  function errorMessageSetSize(w, h)
    {
    getElement('ErrorMessageDiv').style.width = w + 'px';
    getElement('ErrorMessageDiv').style.height = h + 'px';
	}

//Function to get Element by ID
function getElement(id)
{
	if (document.layers)            // Netscape 4
		return eval("document." + id);
	if (document.getElementById)    // Netscape 6
		return eval("document.getElementById('" + id + "')");
	if (document.all)               // IE4+
		return eval("document.all." + id);
}

function initCaps(strText)
{
		var strName  = strText;
		strName = strName.toLowerCase();
		var firstChar;
		firstChar = strName.charAt(0);
		firstChar = firstChar.toUpperCase();
		strName =  strName.substring(1);
		strName = firstChar + strName; 
		return strName;
}

function getElementByClassName(classname)
{ 
    var inc=0; 
    var alltags=document.all? document.all : document.getElementsByTagName("*"); 
    for (i=0; i<alltags.length; i++){ 
        if (alltags[i].className==classname) 
        {
            return alltags[i];    
        }
    }
    return null;
}

//Function used to hide/show all select boxes at page level
function setWindowedControlsVisibility(win, vis)
{
	try
		{
		var i;
		var els = win.document.getElementsByTagName("SELECT");
		if (vis.toLowerCase() == "hidden")
		  for (i=0; i<els.length; i++)
			{
			if (els[i].style != null && els[i].style.visibility != null)
				{
				els[i].lastVisibility = els[i].style.visibility;
				els[i].style.visibility = vis;
				}
			}
		else if (vis.toLowerCase() == "visible")
		  for (i=0; i<els.length; i++)
			{
			if (els[i].style != null && els[i].style.visibility != null)
				{
				    if (els[i].lastVisibility != null) {
				        els[i].style.visibility = els[i].lastVisibility;
				    }
				}
			}
		for (i=0; i<win.frames.length; i++)
		  setWindowedControlsVisibility(win.frames[i], vis);
		}
	catch (ex)
		{
		alert(ex.description);
		}
}

function formatCurrency(num, currencySymbol) {
	//num = num.toString().replace(/\$|\,/g,'');
	var req = eval("/\\" + currencySymbol + "|\\,/g");
	num = num.toString().replace(req,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + currencySymbol + num + '.' + cents);
}


function leftTrim(string)
{
return string.replace(/^\s*/, "");
}

function rightTrim(string)
{
return string.replace(/\s*$/, "");
}

function trim(string)
{
return string.replace(/^\s*/, "").replace(/\s*$/, "");
}

  function isBlank(val)
   {
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	     }
	return true;
   	}
	
    function CheckSpecailChar(val)
	{
	
	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
        for (var i = 0; i < val.length; i++) {
  	    if (iChars.indexOf(val.charAt(i)) != -1) {
  	    return true;}
  	       }
  	}
var ClearTime;
var blnShowed;
blnShowed = false;

function moveit(spot)
{
  if (document.layers)
  {
	   var picture=document.FrachiseDetail;
       if (spot<21)
		  {
			picture.left= spot;
			spot+=20;
			ClearTime = setTimeout('moveit('+spot+')',0);
		   }
		   else 
			clearTimeout(ClearTime);      
    }
  
	if (document.all)
	  {
		   var picture=document.all.FrachiseDetail.style;
		   if (spot<21)
		   {
			picture.left= spot;
			if(spot == 0)
				spot+=1;
			else
				spot+=20;
			ClearTime = setTimeout('moveit('+spot+')',0);
		   }
		   else 
			clearTimeout(ClearTime);      
		}
}

function moveleft(spot)
{

  if (document.layers)
  {
   var picture=document.FrachiseDetail;
       if (spot>-321)
      {
        picture.left= spot;
        spot-=20;
        ClearTime = setTimeout('moveleft('+spot+')',0);
       }      
	   else
	   {
	   	clearTimeout(ClearTime);
		try{setWindowedControlsVisibility(window, 'visible');}catch(e){}
	   }
    }
  
	if (document.all)
  	{
  	 var picture=document.all.FrachiseDetail.style;
  	     if (spot>-321)
    	  {
        	picture.left= spot;
			spot-=20;
    	    ClearTime = setTimeout('moveleft('+spot+')',0);
       	  }
		   else
		   {
			clearTimeout(ClearTime);
			try{setWindowedControlsVisibility(window, 'visible');}catch(e){}
		   }
	}
}

function showHideVital()
{
	if (blnShowed == false)
	{
		setWindowedControlsVisibility(window, 'hidden');
		getElement('OpenProfile').style.display = 'none';
		getElement('CloseProfile').style.display = 'inline';
		moveit(-320);
		blnShowed = true;
	}
	else
	{
			getElement('CloseProfile').style.display = 'none';
			getElement('OpenProfile').style.display = 'inline';
			moveleft(20);
			
			blnShowed = false;
	}
}
function GetXmlHttpObject(handler)
{ 
		var objXmlHttp=null;

		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP";
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			} 
	
			try
			{ 
				objXmlHttp=new ActiveXObject(strName);
				objXmlHttp.onreadystatechange=handler;
				return objXmlHttp;
			} 
			catch(e)
			{ 
				return; 
			} 
		} 
}

//----------------------------------------


//Functon to get y-poisition of element 

function getRealTop(element)
{
		var position = element.offsetTop;
		var parent = element.offsetParent;
		while (parent != null)
		{
				position += parent.offsetTop;
				parent = parent.offsetParent
		}
		return position;
}

function getRealBottom(element)
{
		var position = element.offsetBottom;
		var parent = element.offsetParent;
		while (parent != null)
		{
				position += parent.offsetBottom;
				parent = parent.offsetParent
		}
		return position;
}

//Function to get Element by ID
function getElement(id)
{
	if (document.layers)            // Netscape 4
		return eval("document." + id);
	if (document.getElementById)    // Netscape 6
		return eval("document.getElementById('" + id + "')");
	if (document.all)               // IE4+
		return eval("document.all." + id);
}

function initCaps(strText)
{
		var strName  = strText;
		strName = strName.toLowerCase();
		var firstChar;
		firstChar = strName.charAt(0);
		firstChar = firstChar.toUpperCase();
		strName =  strName.substring(1);
		strName = firstChar + strName; 
		return strName;
}

function getElementByClassName(classname)
{ 
    var inc=0; 
    var alltags=document.all? document.all : document.getElementsByTagName("*"); 
    for (i=0; i<alltags.length; i++){ 
        if (alltags[i].className==classname) 
        {
            return alltags[i];    
        }
    }
    return null;
}

//Function used to hide/show all select boxes at page level
function setWindowedControlsVisibility(win, vis)
{
	try
		{
		var i;
		var els = win.document.getElementsByTagName("SELECT");
		if (vis.toLowerCase() == "hidden")
		  for (i=0; i<els.length; i++)
			{
			if (els[i].style != null && els[i].style.visibility != null)
				{
				els[i].lastVisibility = els[i].style.visibility;
				els[i].style.visibility = vis;
				}
			}
		else if (vis.toLowerCase() == "visible")
		  for (i=0; i<els.length; i++)
			{
			if (els[i].style != null && els[i].style.visibility != null)
				{
				    if (els[i].lastVisibility != null) {
				        els[i].style.visibility = els[i].lastVisibility;
				    }
				}
			}
		for (i=0; i<win.frames.length; i++)
		  setWindowedControlsVisibility(win.frames[i], vis);
		}
	catch (ex)
		{
		alert(ex.description);
		}
}

function formatCurrency(num, currencySymbol) {
	//num = num.toString().replace(/\$|\,/g,'');
	var req = eval("/\\" + currencySymbol + "|\\,/g");
	num = num.toString().replace(req,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + currencySymbol + num + '.' + cents);
}


function leftTrim(string)
{
return string.replace(/^\s*/, "");
}

function rightTrim(string)
{
return string.replace(/\s*$/, "");
}

function trim(string)
{
return string.replace(/^\s*/, "").replace(/\s*$/, "");
}

  function isBlank(val)
   {
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	     }
	return true;
   	}
	
    function CheckSpecailChar(val)
	{
	
	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
        for (var i = 0; i < val.length; i++) {
  	    if (iChars.indexOf(val.charAt(i)) != -1) {
  	    return true;}
  	       }
  	}
var ClearTime;
var blnShowed;
blnShowed = false;

function moveit(spot)
{
  if (document.layers)
  {
	   var picture=document.FrachiseDetail;
       if (spot<21)
		  {
			picture.left= spot;
			spot+=20;
			ClearTime = setTimeout('moveit('+spot+')',0);
		   }
		   else 
			clearTimeout(ClearTime);      
    }
  
	if (document.all)
	  {
		   var picture=document.all.FrachiseDetail.style;
		   if (spot<21)
		   {
			picture.left= spot;
			if(spot == 0)
				spot+=1;
			else
				spot+=20;
			ClearTime = setTimeout('moveit('+spot+')',0);
		   }
		   else 
			clearTimeout(ClearTime);      
		}
}

function moveleft(spot)
{

  if (document.layers)
  {
   var picture=document.FrachiseDetail;
       if (spot>-321)
      {
        picture.left= spot;
        spot-=20;
        ClearTime = setTimeout('moveleft('+spot+')',0);
       }      
	   else
	   {
	   	clearTimeout(ClearTime);
		try{setWindowedControlsVisibility(window, 'visible');}catch(e){}
	   }
    }
  
	if (document.all)
  	{
  	 var picture=document.all.FrachiseDetail.style;
  	     if (spot>-321)
    	  {
        	picture.left= spot;
			spot-=20;
    	    ClearTime = setTimeout('moveleft('+spot+')',0);
       	  }
		   else
		   {
			clearTimeout(ClearTime);
			try{setWindowedControlsVisibility(window, 'visible');}catch(e){}
		   }
	}
}

function showHideVital()
{
	if (blnShowed == false)
	{
		setWindowedControlsVisibility(window, 'hidden');
		getElement('OpenProfile').style.display = 'none';
		getElement('CloseProfile').style.display = 'inline';
		moveit(-320);
		blnShowed = true;
	}
	else
	{
			getElement('CloseProfile').style.display = 'none';
			getElement('OpenProfile').style.display = 'inline';
			moveleft(20);
			
			blnShowed = false;
	}
}
function GetXmlHttpObject(handler)
{ 
		var objXmlHttp=null;

		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP";
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			} 
	
			try
			{ 
				objXmlHttp=new ActiveXObject(strName);
				objXmlHttp.onreadystatechange=handler;
				return objXmlHttp;
			} 
			catch(e)
			{ 
				return; 
			} 
		} 
}
function check5Alphabets(sender,args)
{
    if(getElement(sender.controltovalidate).value.length>=5)
        args.IsValid = true;
    else
        args.IsValid = false;
}