var chars = "abcdefghijklmnopqrstuvwxyz0123456789";

function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}



function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}



function registration_disable_option(field_name)
{

	field_name.disabled=true;
}

function registration_enable_option(field_name)
{
	field_name.disabled=false;
}

function check_blank_fields(field_name,s)
{
	if(field_name.value=="")
	{
		var error="Cannot leave the "+ s+ " field blank";
		alert(error); 
		return false;
	}
	return true;
}

function frmgetname(name,val,frm)
{
	//alert(name);
	if(val.checked)
	{
		frm.author.value = name;	
		frm.author.disabled=true;
	}
	else
	{  		
		frm.author.value = "";
		//frm.hauthor.value = "";
		frm.author.disabled=false;
	}
}

//function to generate a random alphanumeric password string
function getRndStr(field_name)
{
	anum = new Array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

	nums=new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
	var endpass="";
	
	for(i=0;i<2;i++)
	{	
		nextChar = Math.floor(Math.random() * 52);
		nextDig = Math.floor(Math.random() * 10);
	}
		for(j=0;j<2;j++)
		{
			nextDig = Math.floor(Math.random() * 10);
			endpass = nums[nextDig] +endpass;
		}
		for(j=0;j<6;j++)
		{
			nextChar = Math.floor(Math.random() * 52);
			endpass = anum[nextChar] +endpass;
		}
	field_name.value = endpass;
}

function reset_field(field_name)
{
	field_name.value='';
}

//if it is enabled then it will be disabled and vice versa 
function enable_disable_field(field_name)
{
	//alert(field_name);
	if(field_name.disabled==true)
	{
			field_name.disabled=false;
	}
	else
	{
		field_name.disabled=true;
	}
}//EO function enable_disable_field(field_name)


//if it is enabled then it will be disabled and vice versa (this will work on onload only )
function enable_disable_field_onload(flag, field_name)
{
	//alert(field_name);
	if(flag==false)
	{
			field_name.disabled=false;
	}
	else
	{
		field_name.disabled=true;
	}
}//EO function enable_disable_field_onload(flag, field_name)


//function to check the maximum limit is reached or not 
function check_max_count(field_name, max_limit)
{
	if(count_characters(field_name) > max_limit)
	{
		alert('you can not Enter more than '+ max_limit + ' Characters');
		return false;
	}
}//EO function check_max_count(field_name, max_limit)



//function to count the number of characters 
function count_characters(field_name)
{
	return(field_name.value.length);
}//EO function count_characters(field_name)



//function to get the count of a field 
function display_total_characters(field_name)
{
	total = count_characters(field_name);
	return total;
	//document.write('you wrote'+total+ ' characters');
}

//function to show text in a div 
function show_text(divId,val,e)
{
	var myDiv = document.getElementById(divId);
	if(val<=-1 && (e.keyCode!=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40 && e.keyCode!=16))
	{
		alert("You have exceeded the limit.");
		return false;
	}
	else
	{
		myDiv.innerHTML = val;
	}
	
}

function showMyDiv(mydiv)
{
	var img_name=	document.ad_upload.ad_image.value;
	mydiv.style.visibility = "visible"; // Works in IE, not Netscape
	var pre_img = document.getElementById('preview_img');
	pre_img.src = img_name;
	//return name;
}

function show_list(mydiv)
{
	var mydiv=document.getElementById('mydiv');
	mydiv.style.visibility = "visible"; // Works in IE, not Netscape

}

function confirm_delete(field_name,type)
{
	var field_name;
	if(field_name.checked==true)
	var status =(confirm("Are you sure you want to delete this "+type+"? \nClick Submit to Delete it."));
	if(!status)
	field_name.checked = false;
	

}

function confirm_ie()
{

	if(navigator.appName != "Microsoft Internet Explorer")
	{
		alert("Compatible with Microsoft Internet Explorer Only");
		//form.checked=false;
	}
}

function compareDate(date,date1)
{
	
	if(Date.parse(date.value) > Date.parse(date1))
		{
		alert("Hire date cannot be greater than today's date" );
		return false;
		}
	return true;
}

function disable_option()
{
	//document.form1.paper_upload_type.visiblilty=true;
		document.form1.paper_upload_type[1].disabled=true;
		document.form1.paper_upload_type[0].disabled=false;
		//LE09/18 remarked to disable DOC option document.form1.paper_upload_type[2].disabled=true;
		document.form1.paper_upload_type[0].checked=true;

}
function enable_option()
{
	
	document.form1.paper_upload_type[0].disabled=false;
	document.form1.paper_upload_type[1].disabled=false;
	//LE09/18 remarked to disable the DOC option document.form1.paper_upload_type[2].disabled=false;

	//alert(document.form1.paper_upload_type.disabled);
}

function paper_enable_option()
{
	
	document.form1.paper_upload_type[0].disabled=false;
	document.form1.paper_upload_type[1].disabled=false;
	document.form1.paper_upload_type[1].checked=true;

        //UW10/26 remarked to disable DOC 
	
}

function pdf_enable_option()
{
	
	document.form1.paper_upload_type[1].disabled=false;
	document.form1.paper_upload_type[1].checked=true;
	document.form1.paper_upload_type[0].disabled=true;

        //UW10/26 remarked to disable DOC 
	
}
function press_release_enable_option()
{
	
	document.form1.paper_upload_type[0].disabled=false;
	document.form1.paper_upload_type[1].disabled=false;
	document.form1.paper_upload_type[0].checked=true;


        //UW10/26 remarked to disable DOC 
	
}
function del_community()
{
	if(confirm('Are you sure you want to delete this community?'))
		return true;
	else
		return false;
}

/* New function added to confirm logout----Rohit 15-1-2007 */
function confirm_sponsor()
{
	if(confirm('Are you sure you want to proceede to sponsor this page? You will get logged out of your current account.'))
		return true;
	else
		return false;
}

function doedit(id,action)
{
	//alert(id);
	if(action=='show')
	{
		//alert('hi');
		document.getElementById(id).style.visibility = "visible";
		document.getElementById(id).style.position = "static";
	}
	if(action=='hide')
	{
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(id).style.position = "absolute";

	}

}

//  check for valid numeric strings	
function IsNumeric(strString)
{

   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function frmsubmit(id1, id2, tempvar, action)
{
	//alert(id1 +"--"+ id2 +"--"+tempvar+"--"+action);
	var commentid = "edit_comments"+id1;
	var ratingid = "editrating"+id2+""+tempvar;

	var rating="";

	if(id1 != 0)
	{
		var comment = document.comment.elements[commentid].value;
		
	}


	if(id2 != 0)
	{
		var rating  = document.comment.elements[ratingid].value;

	}
	
	//alert(rating);
	//alert(comment);
	if(action=="update" && comment=="")
	{
	 alert("comment cannot be blank ");
	 document.comment.elements[commentid].focus();
		
	}
	else if(action=="update" && (rating=="" || rating > 5 || rating < 0 || (!IsNumeric(rating))) && id2 != 0)
	{
	if(rating=="")
		{
		 alert("Rating cannot be blank ");
		}
		else if(rating < 0 || rating > 5) 
		{
		 alert("Rating Must be between 0 to 5");
		}
		else if(!IsNumeric(rating))
		{
			alert("Please Enter Number for Rating");
		}

		 document.comment.elements[ratingid].focus();
	}
	else
	{
		document.comment.elements['hidaction'].value =action;
		document.comment.elements['hratingid'].value =id2;
		document.comment.elements['hid'].value =id1;
		document.comment.elements['tempvar'].value =tempvar;
		//alert(tempvar);
		document.comment.submit();
	}


}//EO function frmsubmit(id1, id2, tempvar, action)

/*######################################################################################################*/

/*#######################functions to show and hide a div-----modified by rohit on 7-2-2007  #########################*/

function div_visible(id,text,textb,comm_id,type_flag) 
{
	var e = document.getElementById(id);
	var text = document.getElementById(text);
	var textb = document.getElementById(textb);
	textb.value=text.value;
	document.getElementById('comment_id').value=comm_id;
	document.getElementById('type_flag').value=type_flag;
	e.style.visibility = '';
	
}

function div_invisible(id) 
{
	var e = document.getElementById(id);
	e.style.visibility = 'hidden';
}
/*######################################################################################################*/


//below function will check whether passes argument is blank or not a number and return accordingly 
function is_number_temp(field_name,s)
{
	if(field_name.value=="")
	{
		var error="Cannot leave the "+ s+ " field blank";
		alert(error); 

		
		return false;
	}

	if(isNaN(field_name.value))
	{
		var error= s+" field Should Be Numberic";
		alert(error); 
		return false;
	}
	
	return true;
	
}

/**************added by rohit on 5-2-2007 for tooltip functionality**************************************************************************************************/


function div_invisible_tooltip(id,id1) 
{
	var e = document.getElementById(id);
	e.style.visibility = 'hidden';
}

function div_visible_tooltip(id,id1,m) 
{
	var e = document.getElementById(id);
	var f = document.getElementById(id1);
	
	if(m.pageX!=null)
	{
		e.style.left=m.pageX + 5+ "px";
		e.style.top=m.pageY + 5 + "px";
	}
	else
	{
		var xcoord = m.clientX;
		var ycoord = m.clientY;

		if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
		{
			xcoord += document.body.scrollLeft;
			ycoord += document.body.scrollTop;
		} 
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
		{
			xcoord += document.documentElement.scrollLeft;
			ycoord += document.documentElement.scrollTop;
		}
		
		e.style.left= xcoord + 5+ "px";
		e.style.top= ycoord + 5 + "px";
	}
	e.innerHTML=f.value;
		
	e.style.visibility = '';
	
}

function func(frmElem,domain)
{		
		
	/*if(frmName=="pressrelease")
	{
		var frm = document.formnames;
	}
	else if(frmName=="paper")
	{
		var frm = document.formname;
	}
	else if(frmName=="presspdf")
	{
		var frm = document.formnamespdf;
	}
	else if(frmName=="paperpdf")
	{*/
		var frm = document.formname;
	
	

		if(frmElem.value =="scat" )
	{
		if(domain =="WS1" )
		{
			var domainid = frm.domain
			[frm.domain.selectedIndex].value;
			var domaintext = frm.domain
			[frm.domain.selectedIndex].text;
		}
		else
		{
			domainid="";
			domaintext="";
		}
		var catid = frm.category
		[frm.category.selectedIndex].value;
		
		var cattext =frm.category
		[frm.category.selectedIndex].text;
	
		//frm.scat.value =
		var win = window.open("/Paper/My_papers/get_subcategory.php?did="+domainid+"&dtxt="+domaintext+"&catid="+catid+"&cattxt="+cattext,"win1","left=20,top=20,width=350,height=200") ;
		win.focus();
	}
}
/*****************************************************************************************************************************/

/**************added by rohit on 8-2-2007 for ajax functionality***********************************************************/
function ajax_call() 
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	xmlHttp.onreadystatechange=function ()
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById('result').innerHTML =xmlhttp.responseText;
			window.location.reload();
		} 
	}
	xmlhttp.open("GET","edit_comment.php?comment_id="+document.getElementById('comment_id').value +"&comment_text="+document.getElementById('textb').value+"&type_flag="+document.getElementById('type_flag').value,true);
	
	xmlHttp.send(null);
}	

/*****************************************************************************************************************************/
function disable_submit()
{
		document.formname.get_reg.disabled = true;
}
/*
function validate()
{
	if(
			document.formname.uname.value != ''
			&& document.formname.lname.value != ''
			&& document.formname.c_id.value != ''
			&& document.formname.password.value != ''
			&& document.formname.rpassword.value != ''
			&& document.formname.a1.value != ''
			&& document.formname.a2.value != ''
			&& document.formname.check_value.value != ''
			&& document.formname.terms_conditions.checked == true
			&& document.formname.adult.checked == true
			&& document.formname.select_country.value != ''
			&& document.formname.questions1.value != ''
			&& document.formname.questions2.value != ''

		)
	{
		document.formname.get_reg.disabled = false;
	}
	else
	{
		document.formname.get_reg.disabled = true;
	}
}
*/
/*
function GetXmlHttpObject()
{
	var xmlHttp=null;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
*/

function hideall(count)
	{
		//alert('m here');
		
		var i;
				for(i=0;i<count;i++)
				{
					var  divId='layer'+i;
					var  div1Id='layer_hot'+i;
					var menu=document.getElementById(divId);
					var menu1=document.getElementById(div1Id);
					if(menu.style.visibility=='visible')
						menu.style.visibility='hidden';
					if(menu1.style.visibility=='visible')
						menu1.style.visibility='hidden';

				}

	}

function startTime() {
	        if (timerOn == false) {

              timerID=setTimeout( 'hideall(5)' , timecount);
                timerOn = true;

	        }

		}


		function stopTime() {
			alert(hi);
	        if (timerOn) {
				clearTimeout(timerID);
                timerID = null;
                timerOn = false;
	        }
		}
		
/********************Reports Validation**************************/
function validateReportPrice(price,errorDiv)
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 

	xmlHttp.onreadystatechange=function()
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById(errorDiv).innerHTML =xmlHttp.responseText;
			
		}
		else
		{
			if(price != "")
			{
				document.getElementById(errorDiv).innerHTML ="<img src='/Images/ajax-loader1.gif' height='20' width='20'/>";
			}
			
		} 
	}
	xmlHttp.open("GET","validate_price.php?price="+price,true);
	
	xmlHttp.send(null);
}

/********************Reports Validation**************************/
