function getRemoteData(URL)
{	  
	var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	if(xmlHttp == null)
	{
		alert("Could not create XMLHTTP object");
	}
	else
	{
		xmlHttp.open("Post", URL, false);
		xmlHttp.send();
		var resultSet = xmlHttp.responseText;
		//window.status="Transfering Data ....";
		if(resultSet=='SESSIONEXPIRED')
		{
			return false;
			var str = document.location.href;
			var arr1=str.split("//");
			var arr2=arr1[1].split("/");
			DomainString = "http://" + arr2[0] + "/" + arr2[1];
			location.href = DomainString + "Error.aspx?Type=SessionExpired&Msg=YourSessionHasExpired."
		}
		return resultSet;
	}
}

function getCSVData(URL)
{
	var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	if(xmlHttp == null)
	{
		alert("Could not create XMLHTTP object");
	}
	else
	{
		xmlHttp.open("GET", URL, false);
		xmlHttp.send();
		var resultSet = xmlHttp.responseText;
		return resultSet;
	}
}

function Reconnect() 
{ 
	try
	{
		var str = document.location.href;
		var arr1=str.split("//");
		var arr2=arr1[1].split("/");
		DomainString = "http://" + arr2[0] + "/" + arr2[1];
		var url = DomainString + '/DummyPageToRefresh.aspx';
		//alert(url);
		xmlHttp=getObjectHTTP();
		xmlHttp.open('Post', url , false) ;
		xmlHttp.send();
		//var resultSet = xmlHttp.responseText;
		//alert(resultSet);
	}
	catch(err)
	{
		txt+="Error description: " + err.description + "\n\n"
		alert(txt)
	}
	finally
	{}
	//var resultSet = xmlHttp.responseText;
} 

function getObjectHTTP() 
{ 
	try
	{
		var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		return xmlHttp;
	}
	catch(err)
	{
		txt+="Error description: " + err.description + "\n\n"
		alert(txt)
	}
	finally
	{}

} 

/*
// error handling for all pages
// so this file needs to be included in
// all pages in the application
window.onerror = trapError;

function trapError(msg, URI, ln) 
{
	// wrap our unknown error condition in an object
	var error = new Error(msg);
	error.location = URI + ', line: ' + ln; // add custom property
	// logger.log(error);
	 alert("A javascript error has occurred in this page." +
		  " We are sorry for the inconvinence caused!");
	// drastic action

	//var str = document.location.href;
	//var arr1 = str.split("//");
	//var arr2 = arr1[1].split("/");
	//var DomainString = "";
	//DomainString = "http://" + arr2[0] +	 "/" + arr2[1] //http://localhost/Apexmarkdownmanager
	//alert(URL);
	//location.href = DomainString +  '/error.aspx?Type=JAVASCRIPT&Msg=A javascript error has occurred in this page. We are sorry for the inconvenience caused.';
	window.status = "Ready";
	return true; // stop the yellow triangle
}
*/

function OpenFilter_()
{
 	var str = document.location.href;
	var arr1 = str.split("//");
	var arr2 = arr1[1].split("/");
	var DomainString = "";
	DomainString = "http://" + arr2[0] + "/" + arr2[1] //http://localhost/Apexmarkdownmanager

	window.open(DomainString + "/DatePicker/DatePicker.aspx");
}
  

function Validate(ctl, val, Type, FieldName)
{
	//alert('ctl=' + ctl + 'val=' + val + 'Type=' +  Type + 'FieldName=' + FieldName);

	//var ctl = document.getElementByID(ctl1);
	//alert(ctl1);	
	var _Type='';

	//check for empty values
	
	if(val == '')
	{
		alert(FieldName + " is empty.");
		ctl.focus();
		return false;
	}	
	
	var str1 = Type.split("&");	//AN&MinL|3&MaxL|10
	//alert("Val: " + Type + " Len: " + str1.length);
	
	for(var j=0;j < str1.length;j++)
	{
	
		var _Type = str1[j];  
		//alert(_Type + j);
							
		//checks if the given val is numeric
		if(_Type == 'N')
		{ 
			var StoreReg = /^([0-9]+)$/
			var isvalid=StoreReg.test(val);
			//alert(isvalid);
			if(isvalid==true)
			{
			}
			else
			{
				alert(FieldName + " should be Numeric.");
				ctl.select();
				ctl.focus();
				return false;
			} 
		}
		//checks if the given val is Numeric or '*' 
		if(_Type == 'N*')
		{
			var StoreReg=/^(^[0-9]+$)|(^([*]{1})$)+$/
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " should be Numeric or *.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
		//checks if the given val is Numeric with '*' 
		if(_Type == '*N*')
		{
			var StoreReg=/^(([\w]+)|[\w]+([*]{1})[\w]*|([\w]*([*]{1})[\w]+([*]{1})*)+)$/
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " should be AlphaNumeric or *.(Only * is not Allowed).");
				ctl.select();
				ctl.focus();
				return false;
			}
		}

		//checks if the given val is Alphabets  
		//if(_Type == 'A')
		//{
		//	var StoreReg=/^([a-z]+)$/i
		//	if (StoreReg.test(val))
		//	{
		//	}
		//	else
		//	{
		//		alert(FieldName + " should be Alphabets.");
		//		ctl.select();
		//		ctl.focus();
		//		return false;
		//	}
		//}	
		
		//check if Alpha numeric for Alert Names (Don't Allow character "'") 
		if(_Type == 'ANA')
		{	
			var StoreReg=/^([\w\s\D]*[']+[\w\s\D]*)+$/ 
			//alert(StoreReg.test(val));
			if (StoreReg.test(val))
			{
				alert(FieldName + " should not contain the character (').");
				ctl.select();
				ctl.focus();
				return false;
			}
			else
			{
				//alert('done');
			}
		}
		
		//check if Alpha numeric 
		//if(_Type == 'ANU')
		//{	
		//	var StoreReg=/^([a-z0-9]+)$/i   
		//	//alert(StoreReg.test(val));
		//	if (StoreReg.test(val))
		//	{	
		//	}
		//	else
		//	{	
		//		alert(FieldName + " should contain only Alphabets or Numbers.");
		//		ctl.select();
		//		ctl.focus();
		//		return false;			
		//	}
		//}
		
		//check if valid UserName
		//if(_Type == 'USERNAME')
		//{	
		//	var StoreReg=/^([a-z0-9_]+)$/i   
		//	//alert(StoreReg.test(val));
		//	if (StoreReg.test(val))
		//	{	
		//	}
		//	else
		//	{	
		//		alert(FieldName + " should contain only Alphabets or Numbers.");
		//		ctl.select();
		//		ctl.focus();
		//		return false;			
		//	}
		//}

		//check if Quotes are present '/' in val'
		if(_Type == 'ANC')
		{
			//var StoreReg=/^[a-z0-9_\,]+$/i
			var StoreReg=/^[a-z0-9_\s]+[\,]?[a-z0-9_\s]+([a-z0-9_]*[\,]?[a-z0-9_]+)*$/i
			//alert(StoreReg.test(val));
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " should not contain Quotes( ' ), multiple Commas and should not end with Comma.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
			
		//Checks Maximum/Minimum length
		var str3 = _Type.split("|");
		var str4 = str3[0];
		var str5 = str3[1];
	
		//Checks Maximum length to be less than some cutoff
		if(str4 == 'MaxL')
		{	
			var ValidLength = parseInt(str5);
			if(val.length > ValidLength)
			{
				alert(FieldName + " cannot be longer than " + ValidLength + " characters.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
		//Checks Minimum length to be more than some cutoff
		if(str4 == 'MinL')
		{
			var ValidLength = parseInt(str5);
			if(val.length < ValidLength)
			{
				alert(FieldName + " cannot be less than " + ValidLength + " characters.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}

		//Checks Maximum/Minimum val (in case of numeric values):

		//Checks Maximum val to be less than some cutoff
		if(str4 == 'MaxVal')
		{	
			var ValidVal = parseInt(str5);
			if(parseInt(val) > ValidVal)
			{
				alert(FieldName + " cannot be greater than " + ValidVal + ".");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
		
		//Checks Minimum val to be more than some cutoff
		if(str4 == 'MinVal')
		{
			var ValidVal = parseInt(str5);
			if(parseInt(val) < ValidVal)
			{
				alert(FieldName + " cannot be less than " + ValidVal + ".");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
		
		//check if val is Alpha 
		if(_Type == 'ANHP')
		{
			var StoreReg=/^([a-z0-9\s]*)$/i
			//alert(StoreReg.test(val));
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " should not contain Special characters");
				ctl.select();
				ctl.focus();
				return false;
			}
		}	
		
		//check if val is Alpha 
		if(_Type == 'EMAILID')
		{
			var StoreReg=/^([a-zA-Z'][\w\.-_']*[a-zA-Z0-9']@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])$/i
			//alert(StoreReg.test(val));
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " is invalid.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}			
		//check if val is Decimal or int 
		if(_Type == 'D2')
		{
			var StoreReg=/^(\d)+[.]?(\d){0,2}$/i
			//alert(StoreReg.test(val));/^(\d)+([.]+)*(\d){0,2}$/i
			if (StoreReg.test(val))
			{
			}
			else
			{
				alert(FieldName + " should be Numeric Or Decimal.");
				ctl.select();
				ctl.focus();
				return false;
			}
		}							
	}
	return true;
}

function Mid(str, start, len)
/***
        IN: str - the string we are LEFTing
            start - our string's starting position (0 based!!)
            len - how many characters from start we want to get

        RETVAL: The substring from start to start+len
***/
{
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
            iEnd = iLen;
    else
            iEnd = start + len;

    return String(str).substring(start,iEnd);
}   

function GetDomainBaseURL()
{
	var str = document.location.href;
	var arr1 = str.split("//");
	var arr2 = arr1[1].split("/");
	var DomainString = "";
	DomainString = "http://" + arr2[0] + "/" + arr2[1] //http://localhost/Apexmarkdownmanager
	return DomainString;
}

//for holding the currently opened 
//popup window
var w = null;
var cwActive = false;

function OpenWindow(url,WName,width,height,left,top,cwFlag, Resizable)
{
	if(w != null)
	w.close();

	//if some args not supplied, put defaults
	if(left == "")
		left = "80px";
	if(top == "")
		top = "80px";
		
	w = window.open(url,WName,"width=" + width + "px,height=" + height + "px,top=" + top + ",left=" + left + ",resizable=" + Resizable + ",toolbar=0,location=0,directories=0,status=yes,menubar=0,titlebar=0");	
	cwActive = cwFlag;
}



function IntimateParentWindow()
{
	cwActive = false;
}

function GetFocus()
{
   //alert();
	//var e = self.event ;//, s = self.screen;
	//alert('cX=' + e.clientX + 's.left=' + window.screenLeft );
	//if(e.clientX<0)
	//{
		//if(cwActive == false)
		//{
		//	window.focus();
		//}
	
	//if(cwActive == false)
	//{
	//	window.focus();
	//}
}

//to disable all child controls in and obj
function DisableChildNodesRecursively(node,OnlyThis)
{ 
	var i,j;
	var cns = node.childNodes;
	
	for(i =0; i < cns.length;i++)
	{
		if(cns[i].nodeType == 1)
		{	
			if(OnlyThis == "")
			{
				cns[i].disabled = true;
			}
			else
			{ 
				if(OnlyThis == cns[i].nodeName)
					cns[i].disabled = true;
			}
		}
		DisableChildNodesRecursively(cns[i],OnlyThis); //call it recursively
	}			
}	

window.onunload = CommonUnload;
function CommonUnload()
{ 
	if(w != null)
		w.close();
}

//not used till now
function CancelClick()
{
	if(cwActive == true)
	{
		event.cancelBubble=true;
		event.returnValue=false; 
		return false;
	}
}

//to blur an object
function BlurControl(obj, OnlyThis)
{
	//decrease the opacity of the object
	obj.style.opacity = 5/10;
	obj.style.filter = 'alpha(opacity=' + 5*10 + ')';
	
	//optionally disable some controls like ddl
	//as they are not blurred by the filter
	var i;
	var tn = obj.childNodes; //top node
	var cns = tn[0].childNodes; //child nodes
	for(i =0; i < cns.length;i++)
	{
		DisableChildNodesRecursively(cns[i],OnlyThis);
	}			
}


//To trim By Manju 20 Aug 08
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function replace(string,text,by) 
{
	// Replaces text with by in string
	//alert(string + '--'+ text+'--'+by);
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function scriptCheck(quantity) 
{
	var state = true;
	var ch;
	for(i=1;i<quantity.length;i++)
	{
		ch = quantity.charAt(i);
		if(ch>="0" && ch<="9")
			continue;
		else 
			return false;
	}
	return true;
}

function Search()
{
	//var arr = obj.id.split("_");
	//var txtHSearch = replace(obj.id,arr[arr.length-1],"txtHSearch");
	if(!Validate(document.getElementById("txtHSearch"), document.getElementById("txtHSearch").value, "ANA", "Search Word"))
	{
		return false;
	}
	else
	{
		alert("harish");
		//document.location.href = "http://Localhost/Search/Global_search.aspx";
		return true;
	}


}
