function writeFlash(swfPath, width, height)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+swfPath+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#00000" />\n');
	document.write('<embed src="'+swfPath+'" quality="high" bgcolor="#000000" width="'+width+'" height="'+height+'" wmode="transparent"\n');
	document.write('align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"\n');
	document.write('pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	document.write('</object>');
}

function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//------------------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//------------------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}

//Function to validate String
//-----------------------------------------------------------------------------------
function chkString(tmpStr)
{
	var str_pat = /^[a-z0-9_\.\-\'\/\,\,\(\,\)\?\s]*$/i;
	return(str_pat.test(tmpStr));
}
function chkAddress(tmpStr)
{
	var str_pat = /^[a-z0-9_\.\-\"\'\/\,\?\s]*$/i;
	return(str_pat.test(tmpStr));
}

//----------------------------
var r={  'notnumbers':/[^\d]/g }

function valid(o,w)
{
 	o.value = o.value.replace(r[w],'');
}

//------------------
//does not allow numeric in name
function chkName(tmpStr)
{
	var str_pat = /^[a-z\.\,\s\&\-()]*$/i;
	return(str_pat.test(tmpStr));
}
function chkState(tmpStr)
{
	var str_pat = /^[a-z\s]*$/i;
	return(str_pat.test(tmpStr));
}
//does not allow character in pin
function chkPin(tmpStr)
{
	var str_pat = /^[0-9\s]*$/i;
	return(str_pat.test(tmpStr));
}
function chkString1(tmpStr)
{       
	var str_pat = /^[a-z0-9_\s]*$/i;
	return(str_pat.test(tmpStr));
}
//Checks URL against pattern
function chkURL(tmpStr)
{
	var url_pat = /^(http|https|ftp):\/\/([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&amp;,=#@\/:]*)?/;
	return(url_pat.test(tmpStr));
}

//Checks the Phone Number
function chkPhone(tmpStr)
{
	var str_pat = /^[a-z0-9]{3}-[a-z0-9]{3}-[a-z0-9]{4}$/i;
	return(str_pat.test(tmpStr));
}

function refreshCaptcha(imgid)
{
	var img = new Image();
	img.src = 'includes/captcha/captcha.php?hash='+parseInt(Math.random() * 10000000000);
	document.getElementById(imgid).src = img.src;
}
//-------------------------------------------------------------------------------------
function NewPopupWindow(pageName, width, height)
{
	window.open(pageName, '', 'width='+width+',height='+height+',toolbar=0,menubar=0,location=0,left=150,top=180,scrollbars=1');
}

function NewWindow(pageName)
{
	window.open(pageName, '', 'width=520,height=600,toolbar=0,menubar=0,location=0,left=0,top=0,scrollbars=1');
}

function printTimeLog(projectID)
{
	window.open('time_log_list.php?id='+projectID, '', 'width=800,height=450,left=200,scrollbars=1,top=50,toolbar=0,menubar=1,location=0');
}
//Opens a new window showing the uploaded image
function viewImage(imgFile)
{
	imgURL = imgFile;
	newWindow = window.open("","newWindow","titlebar=no,width=50,height=50,left=25,top=25");
	var doc = newWindow.document;
	doc.open();
	doc.write('<html>\n');
	doc.write('<head>\n');
	doc.write('<title>View Image</title>\n');
	doc.write('<meta http-equiv="imagetoolbar" content="no">\n');
	doc.write('</head>\n');
	doc.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" ondblclick="self.close();"  onblur="self.close();" onload="javascript:window.resizeTo(document.getElementById(\'theImage\').width + 10, document.getElementById(\'theImage\').height + 50)">\n');
	doc.write('<img src=\"'+imgURL+'\" alt=\"File: '+imgFile+'\n(Double Click to Close)\" border="0" name="theImage" id="theImage" />\n');
	doc.write('</body>\n');
	doc.write('</html>\n');
	newWindow.focus();
	doc.close();
}


//Right of string
function Right(str, n)
{
      if (n <= 0)
          return "";
      else if (n > String(str).length)
          return str;
      else
   {
          var iLen = String(str).length;
          return String(str).substring(iLen, iLen - n);
      }
}

//left of string
function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function ltrim(str, chars){
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

//------------------------------------------------------------------//
//Generic AJAX object for all types of HTTP get/post work			//
//Usage:															//
//	var ajax = new AJAX();											//
//	var arrParam = new Array();										//
//	arrParam['name1'] = 'value1';									//
//	arrParam['name2'] = 'value2';									//
//	arrParam['name3'] = 'value3';									//
//	ajax.getRequest(url, arrParam, responseHandler);				//
//	OR																//
//	ajax.postRequest(url, arrParam, responseHandler);				//
//																	//
//	NOTE: You do not need to escape() or encodeURIComponent() the	//
//	parameter names or values. AJAX will do it on its own.			//
//	You need to define responseHandler() function that will handle	//
//	response back from the server, be it XML or anything else		//
//------------------------------------------------------------------//
//The AJAX object
function AJAX()
{
	//Private variables (properties)
	var __httpRequest = null;
	var __callbackFunc = null;

	//Private method: __createHttpRequest()
	var __createHttpRequest = function()
	{
		if(window.XMLHttpRequest) //Mozilla, Safari etc
		{
			__httpRequest = new XMLHttpRequest();
		}
		else if(window.ActiveXObject) //IE
		{
			try
			{
				__httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					__httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					//Do whatever you need to do here
					alert("AJAX cannot be used with your browser!");
				}
			}
		}
	}

	//Private method: __createParameters(arr)
	var __createParameters = function(arr)
	{
		var parameters = ""; //Initialize
		for(x in arr)
		{
			var pName = encodeURIComponent(x);
			var pVal = encodeURIComponent(arr[x]);
			parameters = (parameters == "")?pName+'='+pVal:parameters+'&'+pName+'='+pVal;
		}
		return parameters;
	}

	//Private method: __handleResponse()
	var __handleResponse = function()
	{
		if(__httpRequest.readyState == 1)
		{
			__callbackFunc('<img src=images/loader1.gif> Loading.....');
		}
		else if(__httpRequest.readyState == 4)
		{
			__callbackFunc(__httpRequest.responseText);
		}
	}

	//Public method: getRequest(url, arrParam, callbackFunc)
	this.getRequest = function(url, arrParam, callbackFunc)
	{
		__createHttpRequest() //recreate ajax object to defeat cache problem in IE
		__callbackFunc = callbackFunc;
		if(__httpRequest)
		{
			var param = __createParameters(arrParam);
			__httpRequest.onreadystatechange = __handleResponse;
			//Include a random number to defeat IE cache problem
			__httpRequest.open('GET', url+"?ajaxhash="+Math.random()+'&'+param, true);
			__httpRequest.send(null)
		}
	}

	//Public method: postRequest()
	this.postRequest = function(url, arrParam, callbackFunc)
	{
		__createHttpRequest() //recreate ajax object to defeat cache problem in IE
		__callbackFunc = callbackFunc;
		if (__httpRequest)
		{
			var param = __createParameters(arrParam);
			__httpRequest.onreadystatechange = __handleResponse;
			__httpRequest.open('POST', url, true);
			__httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
			__httpRequest.setRequestHeader("Content-length", param.length);
			__httpRequest.setRequestHeader("Connection", "close");
			__httpRequest.send(param);
		}
	}
}

function validateSearch()
{
	obj1.keywords.value = strTrim(obj1.keywords.value);
	if(obj1.keywords.value == '' || obj1.keywords.value == 'Enter your Keywords')
	{
		alert("Please enter your Keywords.");
		obj1.keywords.focus();
		return false;
	}
	obj1.action = "search_results.php";
	obj1.submit();
}

///**************************////////////////
///START FOR ALL LIGHT BOX CODE ONLY////////
///**************************////////////////
//>>>>>>>>>>>>>>>FOR Change Password Modal Box<<<<<<<<<<<<<<<<<<<<<<<
function changePassword(UID)
{
     //this part is called RTI/modalfiles/modal.js
    passwordwindow=dhtmlmodal.open('Password', 'iframe', 'modalfiles/change_password.php?id='+UID, 'Change Password', 'width=500px,height=300px,center=1,resize=0,scrolling=1');

} 

//>>>>>>>>>>>>>>>> FOR Show Addtional Cost Of Information<<<<<<<<<<<<<<
//Calling page title = Additional Charges Details(You can change here for required title)
function show_Cost_inf(UID)
{
    //this part is called RTI/modalfiles/modal.js
    passwordwindow=dhtmlmodal.open('Additional Charges', 'iframe', 'modalfiles/additional_charge_details.php?id='+UID, 'Additional Charges Details', 'width=500px,height=300px,center=1,resize=0,scrolling=1');

} 

//>>>>>>>>>>>>>>>> FOR Show manage_rule_cont[Rule[11]]<<<<<<<<<<<<<<
//Calling page title = manage_rule_11(You can change here for required title)
function manage_rule_cont()
{
    //this part is called RTI/modalfiles/modal.js
    passwordwindow=dhtmlmodal.open('manage_rule_11', 'iframe', 'modalfiles/manage_rule_11.php', 'Orissa RTI(Amendment) Rules, 2006', 'width=500px,height=300px,center=1,resize=0,scrolling=1');

}

//>>>>>>>>>>>>>>>> FOR Show manage_cash_rule_11[Rule[11]]<<<<<<<<<<<<<<
//Calling page title = manage_rule_11(You can change here for required title)
function manage_cash_rule()
{
    //this part is called RTI/modalfiles/modal.js
    passwordwindow=dhtmlmodal.open('manage_rule_11', 'iframe', 'modalfiles/manage_cash_rule_11.php', 'Orissa RTI(Amendment) Rules, 2006', 'width=500px,height=300px,center=1,resize=0,scrolling=1');

}
function showPreview()
{
    //this part is called RTI/modalfiles/modal.js
    passwordwindow=dhtmlmodal.open('Preview', 'iframe', 'modalfiles/online_e_filing_form_preview.php', 'Preview', 'width=800px,height=500px,center=1,resize=0,scrolling=1');

}
function caseTransfer(OID,RID)
{
    //this part is called RTI/modalfiles/modal.js
    casetransfer=dhtmlmodal.open('Transfer Case', 'iframe', 'modalfiles/manage_transfer_cases_select_pio.php?oid='+OID+'&rid='+RID, 'Transfer Case', 'width=350px,height=200px,center=1,resize=0,scrolling=1');

}
function caseDecline(OID,RID)
{
    //this part is called RTI/modalfiles/modal.js
    casetransfer=dhtmlmodal.open('Decline Case', 'iframe', 'modalfiles/manage_transfer_cases_decline.php?oid='+OID+'&rid='+RID, 'Decline Case', 'width=450px,height=200px,center=1,resize=0,scrolling=1');

}
function recycleOption()
{
    //this part is called RTI/modalfiles/show_recycle_option.php
    
    recycleoption=dhtmlmodal.open('Recycle Bin', 'iframe', 'modalfiles/show_recycle_option.php', 'Recycle Bin', 'width=480px,height=200px,center=1,resize=0,scrolling=1');

}


function showPopup()
{
    //this part is called RTI/modalfiles/show_recycle_option.php
    
    recycleoption=dhtmlmodal.open('Award', 'iframe', 'modalfiles/rti-site.html', '', 'width=700px,height=500px,center=1,resize=0,scrolling=1');

}





////*************************************/////////////////////
///////////END FOR ALL LIGHT BOX CODE ONLY////////////////////
///*************************************/////////////////////

//-----------------------------------------------------------------------------------------------------------
function delete1(evt)
{
	var isOpera, isIE, isNav, isFox, isOther = false;
	if(navigator.userAgent.indexOf("Opera")!=-1) {
	isOpera = true;
	} else if(navigator.userAgent.indexOf("Firefox")!=-1) {
	isFox = true;
	} else if(navigator.appName == "Microsoft Internet Explorer") {
	isIE = true;
	} else if(navigator.appName == "Netscape") {
	isNav = true;
	} else {
	isOther = true;
	}
	
	if(isIE)
	{
		
		if(window.event.clientX < 0 && window.event.clientY < 0)
		{
			var ajax = new AJAX();
			var arrParam = new Array();
			ajax.getRequest('delete_session.php', arrParam, showResponseA);
			alert("Thank you for Visiting RTI CMM");
		}

	}
	else
	{
		 
		
		
		if(document.body.clientWidth <= 0 && document.body.clientHeight <= 0)	
		{      
			var ajax = new AJAX();
			var arrParam = new Array();
			ajax.getRequest('delete_session.php', arrParam, showResponseA);
			alert("Thank you for Visiting RTI CMM");

		}	
	}        
}

function showResponseA(retVal)
{	
}


//@@@@@@@@##########IMAGE MOUSE OVER SCRIPT HERE#############@@@@@@@@@@@@@@@@@@@@@@@@@@@
    var dom = (document.getElementById) ? true : false;
    var ns5 = (!document.all && dom || window.opera) ? true: false;
    var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
    var ie4 = (document.all && !dom) ? true : false;
    var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
    
    var origWidth, origHeight;
    
    // avoid error of passing event object in older browsers
    if (nodyn) { event = "nope" }
    
    ///////////////////////  CUSTOMIZE HERE   ////////////////////
    // settings for tooltip 
    // Do you want tip to move when mouse moves over link?
    var tipFollowMouse= true;   
    var tipWidth= 238;
    var offX= 20;   // how far from mouse to show tip
    var offY= 20; 
    var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
    var tipFontSize= "10pt";
    var tipFontColor= "#D67307";
    var tipBgColor= "#DDECFF"; 
    var tipBorderColor= "#000080";
    var tipBorderWidth= 1;
    var tipBorderStyle= "ridge";
    var tipPadding= 3;
    
    
    var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
    var midStr = '" border="0" width="230" height="230"></td></tr><tr><td>';
    var endStr = '</td></tr></table>';
    
    var tooltip, tipcss;
    function initTip() {
        if (nodyn) return;
        tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
        tipcss = tooltip.style;
        if (ie4||ie5||ns5) {    // ns4 would lose all this on rewrites
            tipcss.width = tipWidth+"px";
            tipcss.fontFamily = tipFontFamily;
            tipcss.fontSize = tipFontSize;
            tipcss.color = tipFontColor;
            tipcss.backgroundColor = tipBgColor;
            tipcss.borderColor = tipBorderColor;
            tipcss.borderWidth = tipBorderWidth+"px";
            tipcss.padding = tipPadding+"px";
            tipcss.borderStyle = tipBorderStyle;
        }
        if (tooltip&&tipFollowMouse) {
            document.onmousemove = trackMouse;
        }
    }
    
    window.onload = initTip;
    
    var t1,t2;  // for setTimeouts
    var tipOn = false;  // check if over tooltip link
    
    function doTooltip(evt,num,imgv,caption_img,app_name) 
    {
        var val_img="writereaddata/online_e_filing/"+imgv;
        var caption_img1=" Identity Proof (<span class='wht2b'>"+caption_img+"</span>) of "+app_name;
        //alert(val_img);
        
        if (!tooltip) return;
        if (t1) clearTimeout(t1);   if (t2) clearTimeout(t2);
        tipOn = true;
    
    
        // tooltip content goes here (image, description, optional bgColor, optional textcolor)
        var messages = new Array();
        messages[0] = new Array(val_img,caption_img1,"#000000");
        if (document.images) {
            var theImgs = new Array();
            for (var i=0; i<messages.length; i++) {
            theImgs[i] = new Image();
                theImgs[i].src = messages[i][0];
          }
        }

        // set colors if included in messages array
        if (messages[num][2])   var curBgColor = messages[num][2];
        else curBgColor = tipBgColor;
        if (messages[num][3])   var curFontColor = messages[num][3];
        else curFontColor = tipFontColor;
        if (ie4||ie5||ns5) {
            var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
            tipcss.backgroundColor = curBgColor;
            tooltip.innerHTML = tip;
        }
        if (!tipFollowMouse) positionTip(evt);
        else t1=setTimeout("tipcss.visibility='visible'",100);
    }
    
    var mouseX, mouseY;
    function trackMouse(evt) {
        standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
        mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
        mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
        if (tipOn) positionTip(evt);
    }
    
    function positionTip(evt) {
        if (!tipFollowMouse) {
            standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
            mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
            mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
        }
        var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
        var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
        var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
        var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
        if ((mouseX+offX+tpWd)>winWd) 
            tipcss.left = mouseX-(tpWd+offX)+"px";
        else tipcss.left = mouseX+offX+"px";
        if ((mouseY+offY+tpHt)>winHt) 
            tipcss.top = winHt-(tpHt+offY)+"px";
        else tipcss.top = mouseY+offY+"px";
        if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
    }
    
    function hideTip() {
        if (!tooltip) return;
        t2=setTimeout("tipcss.visibility='hidden'",100);
        tipOn = false;
    }
    
    document.write('<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>')
    
//@@@@@@@@@@@@@@@##########END IMAGE MOUSE OVER#####################@@@@@@@@@@@@@@@@@@@@@@@

function changeFont(fontsize)
{
	if(fontsize != '')
	{
		var ajax = new AJAX();
		var arrParam = new Array();
		arrParam['fontsize'] = fontsize;
		ajax.getRequest('change_font_size.php', arrParam, showResponseFontsize);	
	}
}
function showResponseFontsize(retVal)
{
	//alert(retVal);
	setTimeout("reloadWindow()", 1000);
}
function reloadWindow()
{
	window.location.reload();
}
function checkTextStrength(BR,RadioI)
{
	if(BR == 'B')
	{
		document.getElementById('search_type').value = '';
	}
	else
	{
		var currText = document.getElementById('search_type').value;
			currText = trim(currText);
		if(currText == 'Write your required office name' || currText == 'Write your required information' || currText == '' )
		{
			if(RadioI == 'public_authority')		
				document.getElementById('search_type').value = 'Write your required office name';	
			else if(RadioI == 'information_search')	
				document.getElementById('search_type').value = 'Write your required information';		
		}
	}	
}
function checkTextStrengthBlur()
{
	var currText = document.getElementById('search_type').value;
			currText = trim(currText);
	if(currText == 'Write your required office name' || currText == 'Write your required information' || currText == '' )
	{
		if(document.getElementById('public_authority').checked == true)	
			document.getElementById('search_type').value = 'Write your required office name';	
		if(document.getElementById('information_search').checked == true)
			document.getElementById('search_type').value = 'Write your required information';		
	}		
}

//FUNCTION FOR TOOLTIP TIP WINDOW
function showTipwindow()
{	   
	$("a.tipImage").mouseover(function(){ 
		title = this.title;
		this.title ="";
		$("body").append("<div id='tooltipWindow'></div>");
        $("#tooltipWindow").html('');
		$("a.tipImage").mousemove(function(e){
			
            if(($(this).position().left)+276 < $(window).width())
			{
                $("#tooltipWindow").css('left',($(this).position().left)+36+'px');
				$("#tooltipWindow").css('top',$(this).position().top+'px');
				$("#tooltipWindow").show('slow');
            }
			else
			{
                 if($(window).width() <= 1224)
				 {
					$("#tooltipWindow").css('left',($(this).position().left)-216+'px');
					$("#tooltipWindow").css('top',$(this).position().top+'px');
					$("#tooltipWindow").show();
				 }
				 else
				 {
					$("#tooltipWindow").css('left',($(this).position().left)+16+'px');
					$("#tooltipWindow").css('top',$(this).position().top+'px');
					$("#tooltipWindow").show('slow');
				 }				
			}
		 });
		document.getElementById('tooltipWindow').innerHTML = title;
	});
	$("a.tipImage").mouseout(function(){ 
			this.title = title;
			$("#tooltipWindow").hide('fast');
            $("#tooltipWindow").html('');				   
	});
}

