// JavaScript Document
function watermark_on(txt, text)
{         
	   if (txt.value == text) {
           txt.value = "";
            }

}
function watermark_off(txt, text)
{    
	if (txt.value == "") {
          txt.value = text;
    }
}


var xmlhttp;

function loadXMLDoc(url,innerDiv)
{

	//alert(url);
	try{
		// Opera 8.0+, Firefox, Safari
		xmlhttp = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	xmlhttp.open("GET",url,true);
	//xmlhttp.onreadystatechange=onResponse;
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState == 4) //request 4: The request is complete (can get data)
	{
		//alert('test');
		var returnValue = xmlhttp.responseText;
		//alert(returnValue);
		if(innerDiv)
			document.getElementById(innerDiv).innerHTML = returnValue;
		//else	
			//return returnValue;
	}
}
		
	

xmlhttp.send(null);
}


function onResponse()
{
	if(xmlhttp.readyState == 4) //request 4: The request is complete (can get data)
	{
		//alert('test');
		returnValue = xmlhttp.responseText;
		if(innerDiv)
			document.getElementById(innerDiv).innerHTML = returnValue;
		//else	
			//return returnValue;
	}
}


function comments_submit()
{
		var errorTxt ='<ul>';
		var Email = document.getElementById('Email').value;
		if(Email =="")
		{
			errorTxt +="<li>Please enter your Email ID</li>";
			//return false
		}
		else
		{
			st=Email;
			if(checkEmail(st)==false)
			{
					errorTxt +="<li>Invalid Email ID \n"+st+"</li>";
					//return false;
			}
		}
		var commentsText = document.getElementById('commentsText').value;
		if(commentsText =="")
		{
			errorTxt +="<li>Please enter your Question Or Comment.</li>";
			//return false
		}
		if(	errorTxt != '<ul>')
		{
			document.getElementById('question_errorloc').innerHTML = errorTxt+'</ul>';
			return false; 
		}
		
		var id = document.getElementById('id').value;
		var page = document.getElementById('page').value;
		url ='templates/edel_golf/include/comments.php?Email='+Email+'&QuestionText='+commentsText+'&id='+id+'&page='+page;
		//alert(url);
		loadXMLDoc(url,'question');
}


function checkEmail(str)
	{
		if((str.indexOf("@")==-1) || (str.indexOf(".")==-1))
		{
			fstr="Please Enter @ or .";
			return false;
		}
		else
		{
		if((str.indexOf("@") == 0) || (str.indexOf(".") == 0))
		{
			fstr="@ or . Cannot Be first";
			return false;
		}
		if((str.indexOf("@") == (str.length-1)) || (str.indexOf(".") == (str.length-1)))
		{
			fstr="@ or . Cannot Be Last";
			return false;
		}

		if(str.indexOf("@") > str.indexOf("."))
		{
			fstr="@ Should be After .";
			return false;
		}
		if((str.indexOf("@")+1) == str.indexOf("."))
		{
			fstr="@. IS Invalid Email";
			return false;
		}
		}
		var cp=0;					
		for(i=0;i<str.length;i++)
		{
			c=str.charAt(i);
			b=(((c >= "0") && (c <= "9")) || ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == ".") || (c == "@") || (c == "_")|| (c == "-"))
			if(c=="@") cp++;
			if(b==true)
			   continue;
			else
			{
				fstr="Cannot include "+c;
				return false;
			}
		}
		if(cp==2)
		{
			fstr="@ cannnot be repetaed";
			return false;

		}
		return true;
	}
