/*
	@Description :	All the admin validation will control from this javascript file
	@author		 :	Vinod Kumar Keshri
	@Email		 : 	vkkeshri@gmail.com (Any Query regarding this javascript function just mail me with application url in Subject)
	@date		 :	20 April 2010
*/
//path = 'http://localhost/121pressrelease/';
path = 'http://www.121pressrelease.com/';
// ajax function
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 to check white space on both the end*/
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
/* Function to check white space on left end*/
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
/* Function to check white space on right end*/
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
/* Function to check validation for admin profile */
function chk_admin_profile(){
	admin 	= document.getElementById('AdminAdmin');
	email	 	= document.getElementById('AdminEmail');	
	var errorString = "";	
	if(trim(admin.value)==''){
		errorString = errorString + "<li> Admin user name is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
			errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to check email format*/
function checkemail(email){
	var testresults
	var str=$email
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults=false
	}
	return (testresults)
}
/* Function to check validation for change password*/
function chk_change_password(){
	var opassword = document.getElementById('AdminOpassword');
	var npassword = document.getElementById('AdminNpassword');
	var cpassword = document.getElementById('AdminCpassword');
	var errorString = "";	
	if(trim(opassword.value)==''){
		errorString = errorString + "<li> Old password is mandatory. </li>";
	}
	if(trim(npassword.value)==''){
		errorString = errorString + "<li> New password is mandatory. </li>";
	}
	if(trim(cpassword.value)==''){
		errorString = errorString + "<li> Confirm password is mandatory. </li>";
	}
	if(trim(npassword.value)!=trim(cpassword.value)){
		errorString = errorString + "<li> Password mismatch. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to check validation for change password*/
function userChangePassword(){
	var opassword = document.getElementById('UserOpassword');
	var npassword = document.getElementById('UserNpassword');
	var cpassword = document.getElementById('UserCpassword');
	var errorString = "";	
	if(trim(opassword.value)==''){
		errorString = errorString + "<li> Old password is mandatory. </li>";
	}
	if(trim(npassword.value)==''){
		errorString = errorString + "<li> New password is mandatory. </li>";
	}
	if(trim(cpassword.value)==''){
		errorString = errorString + "<li> Confirm password is mandatory. </li>";
	}
	if(trim(npassword.value)!=trim(cpassword.value)){
		errorString = errorString + "<li> Password mismatch. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/*Function to check global configuration*/
function chk_global_conf(){
	var title		= document.getElementById('ConfigurationTitle');
	var keywords	= document.getElementById('ConfigurationKeywords');
	var description = document.getElementById('ConfigurationDescription');
	var errorString = "";
	if(trim(title.value)==''){
		errorString = errorString + "<li> Meta title is mandatory. </li>";
	}
	if(trim(keywords.value)==''){
		errorString = errorString + "<li> Meta keyword is mandatory. </li>";
	}
	if(trim(description.value)==''){
		errorString = errorString + "<li> Meta description is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/*function to check content page*/
function chk_contact(){
	PageName 	= document.getElementById('PageName');
	PageEmail 	= document.getElementById('PageEmail');
	PageContact = document.getElementById('PageContact');
	PageSecurity= document.getElementById('PageSecurity');
	var errorString = "";
	if(trim(PageName.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(PageEmail.value)==''){
		errorString = errorString + "<li> Email is mandatory. </li>";
	}
	if(trim(PageEmail.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = PageEmail.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(trim(PageContact.value)==''){
		errorString = errorString + "<li> Message is mandatory. </li>";
	}
	if(trim(PageSecurity.value)==''){
		errorString = errorString + "<li> Security word is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to validate user from admin*/
function chk_user(){
	var name 		= document.getElementById('UserName');
	var login 		= document.getElementById('UserLogin');
	var password 	= document.getElementById('UserPassword');
	var repassword 	= document.getElementById('UserRepassword');
	var email 		= document.getElementById('UserEmail');
	var company 	= document.getElementById('UserCompany');
	var type 		= document.getElementById('UserType');
	var hereabout 	= document.getElementById('UserHereabout');
	var errorString = "";	
	if(trim(name.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(login.value)==''){
		errorString = errorString + "<li> User name is mandatory. </li>";
	}
	if(trim(password.value)==''){
		errorString = errorString + "<li> Password is mandatory. </li>";
	}
	if(trim(repassword.value)==''){
		errorString = errorString + "<li> Confirm password is mandatory. </li>";
	}
	if(trim(password.value)!=trim(repassword.value)){
		errorString = errorString + "<li> Password mismatch. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email address is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(trim(company.value)==''){
		errorString = errorString + "<li> Company name is mandatory. </li>";
	}
	if(trim(type.value)==''){
		errorString = errorString + "<li> User type is mandatory. </li>";
	}
	if(trim(hereabout.value)==''){
		errorString = errorString + "<li> Here about is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to update user from admin*/
function updateUser(){
	var name 		= document.getElementById('UserName');
	var password 	= document.getElementById('UserPassword');
	var email 		= document.getElementById('UserEmail');
	var company 	= document.getElementById('UserCompany');
	var type 		= document.getElementById('UserType');
	var hereabout 	= document.getElementById('UserHereabout');
	var errorString = "";	
	if(trim(name.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(password.value)==''){
		errorString = errorString + "<li> Password is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email address is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(trim(company.value)==''){
		errorString = errorString + "<li> Company name is mandatory. </li>";
	}
	if(trim(type.value)==''){
		errorString = errorString + "<li> User type is mandatory. </li>";
	}
	if(trim(hereabout.value)==''){
		errorString = errorString + "<li> Here about is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to validate user login*/
function userSignin(){
	var login 		= document.getElementById('UserLogin');
	var password 	= document.getElementById('UserPassword');
	var errorString = "";	
	if(trim(login.value)==''){
		errorString = errorString + "<li> User name is mandatory. </li>";
	}
	if(trim(password.value)==''){
		errorString = errorString + "<li> Password is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to validate user*/
function userSignup(){
	var name 		= document.getElementById('UserName');
	var login 		= document.getElementById('UserLogin');
	var password 	= document.getElementById('UserPassword');
	var repassword 	= document.getElementById('UserRepassword');
	var email 		= document.getElementById('UserEmail');
	var contact		= document.getElementById('UserContact');
	var company 	= document.getElementById('UserCompany');
	var type 		= document.getElementById('UserType');
	var hereabout 	= document.getElementById('UserHereabout');
	var errorString = "";	
	if(trim(name.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(login.value)==''){
		errorString = errorString + "<li> User name is mandatory. </li>";
	}
	if(trim(password.value)==''){
		errorString = errorString + "<li> Password is mandatory. </li>";
	}
	if(trim(repassword.value)==''){
		errorString = errorString + "<li> Confirm password is mandatory. </li>";
	}
	if(trim(password.value)!=trim(repassword.value)){
		errorString = errorString + "<li> Password mismatch. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email address is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(trim(contact.value)==''){
		errorString = errorString + "<li> Contact number is mandatory. </li>";
	}
	if(trim(company.value)==''){
		errorString = errorString + "<li> Company name is mandatory. </li>";
	}
	if(trim(type.value)==''){
		errorString = errorString + "<li> User type is mandatory. </li>";
	}
	if(trim(hereabout.value)==''){
		errorString = errorString + "<li> Here about is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/*Function to validate category*/
function chk_category(){
	var id 	= document.getElementById('CategoryId');
	var category 	= document.getElementById('CategoryCategory');
	var errorString = "";
	if(trim(id.value)==''){
		errorString = errorString + "<li> Category code is mandatory. </li>";
	}
	if(trim(category.value)==''){
		errorString = errorString + "<li> Category is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div style='background-color:#fff5f5;	color:#ff3939;	border:1px solid #ff3939;clear:both;margin:10px 0;padding:5px;font-size:12px;' ><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/*function to check user available*/
function ajaxcheck(){
	var ajaxRequest;
	try
	{
		ajaxRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				alert("Your browser broke!");
				return false;
			}
		}
	}
	name = document.getElementById('UserLogin').value;
	ajaxRequest.open("GET", path+"admins/check_user/name:"+name, true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				result = ajaxRequest.responseText;
				if(result==1){
					document.getElementById('login').innerHTML='User name already in use';	
					document.getElementById('UserLogin').value='';
					document.getElementById('UserLogin').focus();
				} else{
					document.getElementById('login').innerHTML='User is available';			
				}
			}
		}		
}
/*function to check user available*/
function checkUserAvailabl() {
	var name=document.getElementById("UserLogin").value;
	if(name){
		var url=path+"users/check_user/name:"+name;
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} else {
		document.getElementById("UserLogin").innerHTML="";
	}
}
function stateChanged() {
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
		if(xmlHttp.responseText==1 ) {
			document.getElementById("login").innerHTML="User name already in use.";
			document.getElementById("login").style.display="block";
			document.getElementById("UserLogin").value = '';
			document.getElementById("UserLogin").focus();
		}
		if(xmlHttp.responseText==0 ) {
			document.getElementById("login").innerHTML="User is avaliable.";
			document.getElementById("login").style.display="block";
		}
	} else {
			document.getElementById("login").style.display="none";
	}
}
/*function to check company name available*/
function checkCompanyAvailable(){
	var ajaxRequest;
	try
	{
		ajaxRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				alert("Your browser broke!");
				return false;
			}
		}
	}
	name = document.getElementById('CompanyCompanyName').value;
	ajaxRequest.open("GET", path+"users/check_company/name:"+name, true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				result = ajaxRequest.responseText;
				if(result==1){
					document.getElementById('companyDiv').innerHTML='Company name already in used';	
					document.getElementById('CompanyCompanyName').value='';
					document.getElementById('CompanyCompanyName').focus();
				} else{
					document.getElementById('companyDiv').innerHTML='Company is available';			
				}
			}
		}		
}
/* Function to Check uncheck all checkbox, Start*/
function checkUncheckAll(chk){
	if(document.form.checkBox.checked==false){
		if(chk.length==undefined){
			chk.checked=false;
		}
		else{
			for(i=0;i<chk.length;i++)
			chk[i].checked=false;
		}
	}
	else{
		if(chk.length==undefined){
			chk.checked=true;
		}
		else{
			for(i=0;i<chk.length;i++)
			chk[i].checked=true;
		}
	}
}
/* Function to update user profile*/
function updateProfile(){
	name = document.getElementById('UserName');
	company = document.getElementById('UserCompany');
	email = document.getElementById('UserEmail');
	var errorString = "";	
	if(trim(name.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(company.value)==''){
		errorString = errorString + "<li> Company name is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email address is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to check validation for add company */
function addCompany(){
	var companyName 	= document.getElementById('CompanyCompanyName');
	var companyType 	= document.getElementById('CompanyCompanyType');
	var url 			= document.getElementById('CompanyUrl');
	var email 			= document.getElementById('CompanyEmail');
	var contactPerson 	= document.getElementById('CompanyContactPerson');
	var contactNumber 	= document.getElementById('CompanyContactNumber');
	var zipCode		 	= document.getElementById('CompanyZipCode');
	var companyDetail 	= document.getElementById('CompanyCompanyDetail');
	var errorString 	= "";	
	if(trim(companyName.value)==''){
		errorString = errorString + "<li> Company name is mandatory. </li>";
	}
	if(trim(companyType.value)==''){
		errorString = errorString + "<li> Company type is mandatory. </li>";
	}
	if(trim(url.value)==''){
		errorString = errorString + "<li> Url is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
			errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(trim(contactPerson.value)==''){
		errorString = errorString + "<li> Contact person name is mandatory. </li>";
	}
	if(trim(contactNumber.value)==''){
		errorString = errorString + "<li> Contact number is mandatory. </li>";
	}
		if(trim(zipCode.value)==''){
		errorString = errorString + "<li> Zip code is mandatory. </li>";
	}
	if(trim(companyDetail.value)==''){
		errorString = errorString + "<li> Company detail is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to check validation for update company */
function updateCompany(){
	var companyType 	= document.getElementById('CompanyCompanyType');
	var url 			= document.getElementById('CompanyUrl');
	var email 			= document.getElementById('CompanyEmail');
	var contactPerson 	= document.getElementById('CompanyContactPerson');
	var companyDetail 	= document.getElementById('CompanyCompanyDetail');
	var errorString 	= "";	
	if(trim(companyType.value)==''){
		errorString = errorString + "<li> Company type is mandatory. </li>";
	}
	if(trim(url.value)==''){
		errorString = errorString + "<li> Url is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
			errorString = errorString + "<li> Email Id is not valid. </li>";
		}
	}
	if(trim(contactPerson.value)==''){
		errorString = errorString + "<li> Contact person name is mandatory. </li>";
	}
	if(trim(companyDetail.value)==''){
		errorString = errorString + "<li> Company detail is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to forgot user password*/
function forgotPassword(){
	var login 		= document.getElementById('UserLogin');
	var email 		= document.getElementById('UserEmail');
	var errorString = "";	
	if(trim(login.value)==''){
		errorString = errorString + "<li> User name is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email address is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email Id is not valid. </li>";
		}
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to show the preview, Start */ 
function popup(path,winname,W,H,M,S,b,f){
	var brd = b||0;
	var tsz = 20;
	f = f||0;
	var c=(document.all&&navigator.userAgent.indexOf("Win")!=-1)?1:0
	var w=window.screen.width / 2; var h=window.screen.height / 2;
	var W=W||w; W=(typeof(W)=='string'?Math.ceil(parseInt(W)*w/100):W); W+=(brd*2+2)*c; W += f;
	var H=H||h; H=(typeof(H)=='string'?Math.ceil(parseInt(H)*h/100):H); H+=(tsz+brd+2)*c; H += f;
	var X=X||Math.ceil((w-W/2))
	var Y=Y||Math.ceil((h-H/2))

	var hPopup = window.open(path, null, "left="+X+",top="+Y+",width="+W+",height="+H+",menubar="+M+",toolbar=0,scrollbars="+S+",resizable=0");
	hPopup.focus();
}
function preview(){
	popup('preview', 'preview', 650, 500, 0, 1);
}
function getHeadline(){
	return document.getElementById('PressreleaseHeadlines').value;
}
function getShortDesc(){
	return document.getElementById('PressreleaseShortDesc').value;
}
function getDescription(){
	return document.getElementById('PressreleaseDescription').value;
}
function getTickerSymbol(){
	return document.getElementById('PressreleaseTickerSymbol').value;
}
function getKeywords(){
	return document.getElementById('PressreleaseKeywords').value;
}
function getReleaseType(){
	f = document.getElementById('PressreleaseReleaseType');
	return f.options[f.selectedIndex].text;
}
function getCategory(){
	f = document.getElementById('PressreleaseCategoryId');
	return f.options[f.selectedIndex].text;
}
function getCountry(){
	f = document.getElementById('PressreleaseCountryId');
	return f.options[f.selectedIndex].text;
}
/*function getReleaseDate(){
	return document.getElementById('PressreleaseReleaseDate').value;
}*/
function getCompany(){
	f = document.getElementById('PressreleaseCompanyId');
	return f.options[f.selectedIndex].text;
}
function getUrl(){
	return document.getElementById('PressreleaseUrl').value;
}
function getEmail(){
	return document.getElementById('PressreleaseEmail').value;
}
function getContactName(){
	return document.getElementById('PressreleaseContactPerson').value;
}
function getContactNumber(){
	return document.getElementById('PressreleaseContactNumber').value;
}
function getZipCode(){
	return document.getElementById('PressreleaseZipCode').value;
}
function getOtherDetails(){
	return document.getElementById('PressreleaseOtherDetails').value;
}
/* Function to show the preview, End */ 

/* Function to validate press release*/
function validatePressrelease(){
	var headline 	= document.getElementById('PressreleaseHeadlines');
	var shortDesc 	= document.getElementById('PressreleaseShortDesc');
	var description = document.getElementById('PressreleaseDescription');
	var keywords 	= document.getElementById('PressreleaseKeywords');
	var releaseType = document.getElementById('PressreleaseReleaseType');
	var category_id = document.getElementById('PressreleaseCategoryId');
	var country_id 	= document.getElementById('PressreleaseCountryId');
	//var releaseDate = document.getElementById('PressreleaseReleaseDate');
	var company_id 	= document.getElementById('PressreleaseCompanyId');
	var errorString = "";	
	if(trim(headline.value)==''){
		errorString = errorString + "<li> Headline is mandatory. </li>";
	}
	if(trim(shortDesc.value)==''){
		errorString = errorString + "<li> Summary is mandatory. </li>";
	}
	if(trim(description.value)==''){
		errorString = errorString + "<li> Press Release is mandatory. </li>";
	}
	if(trim(keywords.value)==''){
		errorString = errorString + "<li> Keywords is mandatory. </li>";
	}
	if(trim(releaseType.value)==''){
		errorString = errorString + "<li> Press Release Type is mandatory. </li>";
	}
	if(trim(category_id.value)==''){
		errorString = errorString + "<li> Category is mandatory. </li>";
	}
	if(trim(country_id.value)==''){
		errorString = errorString + "<li> Country is mandatory. </li>";
	}
	//if(trim(releaseDate.value)==''){
		//errorString = errorString + "<li> Release date is mandatory. </li>";
	//}
	if(trim(company_id.value)==''){
		errorString = errorString + "<li> Company is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</li></div>";
		return false;
	}
	else{
		return true;
	}
}
/* Function to validate contact us page*/
function contactUs(){
	var name 	= document.getElementById('PageName');
	var email 	= document.getElementById('PageEmail');
	var subject = document.getElementById('PageSubject');
	var comment	= document.getElementById('PageComment');
	var errorString = "";	
	if(trim(name.value)==''){
		errorString = errorString + "<li> Name is mandatory. </li>";
	}
	if(trim(email.value)==''){
		errorString = errorString + "<li> Email is mandatory. </li>";
	}
	if(trim(email.value) != ''){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email.value;
		if(reg.test(address) == false) {
		errorString = errorString + "<li>  Email is not valid. </li>";
		}
	}
	if(trim(subject.value)==''){
		errorString = errorString + "<li> Subject is mandatory. </li>";
	}
	if(trim(comment.value)==''){
		errorString = errorString + "<li> Comment is mandatory. </li>";
	}
	if(errorString != ""){
		window.scrollTo(0,0);
		document.getElementById("jsErrors").innerHTML =  "<div id='jsError'><ul>"+errorString+"</ul></div>";
		return false;
	}
	else{
		return true;
	}
}
//function to show the company
function company(id){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	  	alert ("Your browser does not support AJAX!");
  		return;
  	}
	var url="show_company";
	url=path+"users/show_company/id:"+id;
	xmlHttp.onreadystatechange=showCompany;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showCompany(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById("comDiv").innerHTML=xmlHttp.responseText;
	}
}
//limit text
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
