
function send(form){
	if(form.txtuser.value==""){
		alert("Please specify Username.");
		form.txtuser.focus();
		return false;
	}
	if(form.txtpassword.value==""){
		alert("Please specify Password.");
		form.txtpassword.focus();
		return false;
	}
	form.submit();
}

function setVisible(obj,w,h)
{
	obj = document.getElementById(obj);
	obj.style.width=w;
	obj.style.height=h;
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}

function addrows(max,inputid,name,more){ 
	var num = Number(document.getElementById(inputid).value) + 1;
	document.getElementById(inputid).value = num;
	if(num <=max){
		text = name + num;
		document.getElementById(text).style.display='';
	}
	if(num==max)
		document.getElementById(more).style.display='none';
}

function CheckAll(fmobj) {
  fmobj=eval(fmobj);
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.type=='checkbox') && (!e.disabled) ) {
      fmobj.elements[i].checked=true;
    }
  }
}

function UnCheckAll(fmobj) {
  fmobj=eval(fmobj);
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.type=='checkbox') && (!e.disabled) ) {
      fmobj.elements[i].checked=false;
    }
  }
}
function validate_autoTrade(form)
{
	if(form.htype.value=="")
	{
	  alert("Please specify autoTrade Type.");
	  return false;
	 }
	/*else if(form.hicon.value=="")
	{
	   alert("Please upload icon for autoTrade.");
	   return false;
	}
	*/
}

function edit_autoTrade(form)
{
	if(form.htype.value=="")
	{
	  alert("Please specify autoTrade Type.");
	  return false;
	 }
	 /*else if(form.ictype.value=="1"){
		if(form.hicon.value=="")
		{
		   alert("Please upload icon for autoTrade.");
		   return false;
		}
	}
	*/
}
function changeIcon(){
	document.getElementById("aid").style.display='none';
	document.getElementById("rid").style.display="";
	document.hform.ictype.value='1';
}

function changeFile(){
	document.getElementById("aid").style.display='none';
	document.getElementById("rid").style.display="";
	document.hform.ictype.value='1';
	document.hform.btype.disabled=false;
	document.hform.size.disabled=false;
}

function changeCategory(val){
	if(val=="")
		document.getElementById("ctd").style.display="";
	else if(val=="I")
		document.getElementById("ctd").style.display="";
	else
		document.getElementById("ctd").style.display='none';
}

function changeBanner(val){
	if(val=="")
		document.getElementById("upid").value="Manish";
	else if(val=="flash")
		document.getElementById("upid").value="flash";
	else if(val=="gif")
		document.getElementById("upid").value="gif";
	else
		document.getElementById("upid").value="jpeg";
}

function validate_search(form){
	if(form.keywordsearch.value==""){
	  alert("Please Enter the Search Word.");
	  return false;
	 }
}


function initialize(){ 
	document.getElementById("lblCount").value ="0";
	document.getElementById("videoCount").value ="0";
   
   // var map = new google.maps.Map2(document.getElementById("map"));
    //map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);

}
 

/*function initialize() {
	document.getElementById("lblCount").value ="0";
	document.getElementById("videoCount").value ="0";
	//var map = new google.maps.Map2(document.getElementById("map"));
    //map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
  } */
 

function popUp(linkpage,wname,w, h,scroll){
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	w=w+18;
	//h=h+18;
	win=window.open(linkpage, wname, 'toolbars=0, scrollbars=' + scroll + ', location=0, statusbars=0, menubars=0, resizable=1, width='+w+', height='+h+', left = '+LeftPosition+', top = '+TopPosition+'');
	if(win.focus){
		win.focus();
	}
}


function rate(value,id) {
		document.getElementById('rankid').value=value;         
		new Ajax.Updater('rating','ratediary.php?id='+ id +'&v='+value );
}


function addcomment()
{ 
  new Ajax.Updater('comments','addcomment.php',
  {
    method: 'post',
    parameters: $('cform').serialize(),
    onSuccess: function() {
       $('comment_text').value = '';
    }
  } );
 
}

function viewcomment()
{
	document.getElementById('rating').style.display="block";
	document.getElementById('commentid').style.display="block";
}

function send_url(url)
{
	document.location.href="login.php?"+url;
}

function daysBetween(date1, date2){
   if (date1.indexOf("-") != -1) { date1 = date1.split("-"); } else if (date1.indexOf("/") != -1) { date1 = date1.split("/"); } else { return 0; }
   if (date2.indexOf("-") != -1) { date2 = date2.split("-"); } else if (date2.indexOf("/") != -1) { date2 = date2.split("/"); } else { return 0; }
   if (parseInt(date1[0], 10) >= 1000) {
       var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
   } else if (parseInt(date1[2], 10) >= 1000) {
       var sDate = new Date(date1[2]+"/"+date1[0]+"/"+date1[1]);
   } else {
       return 0;
   }
   if (parseInt(date2[0], 10) >= 1000) {
       var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
   } else if (parseInt(date2[2], 10) >= 1000) {
       var eDate = new Date(date2[2]+"/"+date2[0]+"/"+date2[1]);
   } else {
       return 0;
   }
   var one_day = 1000*60*60*24;
   var daysApart = Math.ceil((sDate.getTime()-eDate.getTime())/one_day);
   return daysApart;
} 
function actionAd(form,action,id){
	form.id.value=id;
	form.action=action;
}

function mapping(form)
{
	text=document.getElementById('txtplace').value;
	if(text!="")
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="mapping.php";
		url=url+"?q="+text;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}


function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

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 loadModules(make,web,lang){
//alert(make);
	if(make!=""){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url=web+"/ajax/getModelsforindex.php";
		url=url+"?make="+make+"&langCode="+lang;
		xmlHttp.onreadystatechange=getModules;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function getModules(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("modules").innerHTML=xmlHttp.responseText;
	}
}


function checkYears(obj){
		if(obj!='0'){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url="../ajax/maxYear.php";
		url=url+"?obj="+obj;
		xmlHttp.onreadystatechange=getMaxDate;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
		}
}
/*
function chkyear(obj)
{
	var minYears=eval(document.search.minYears);
	var maxYears=eval(document.search.maxYears);
	if(minYears.value <=0){
		alert("Please select Year Min.");
		document.search.error.value=0;
		minYears.focus();
	}
	else if(maxYears.value <=0){
		alert("Please select Year Max.");
		document.search.error.value=0;
		maxYears.focus();
	}
	else if(eval(minYears.value)>eval(maxYears.value)){
		alert("Year Min is greater then Year Max.");
		document.search.error.value=0;
		obj.focus();
	}
	else if{
		document.search.error.value=1;
	}
}*/

function getMaxDate(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("maxYear").innerHTML=xmlHttp.responseText;
	}
}

function checkYears(obj){
		if(obj!='0'){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
//		alert(obj);
		var url="../ajax/maxYear.php";
		url=url+"?obj="+obj;
		xmlHttp.onreadystatechange=getMaxDate;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
		}
}

function checkPrice(obj){
		if(obj!='0'){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url="../ajax/maxPrice.php";
		url=url+"?obj="+obj;
		xmlHttp.onreadystatechange=getMaxPrice;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
		}
}

function getMaxPrice(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("maxPrices").innerHTML=xmlHttp.responseText;
	}
}
/*
function checkPrice(obj){
	var minPrice=eval(document.search.minPrice);
	var maxPrice=eval(document.search.maxPrice);
	if(minPrice.value <=0){
		alert("Please select Price Min.");
		document.search.error.value=0;
		minPrice.focus();
	}
	else if(maxPrice.value <=0){
		alert("Please select Price Max.");
		document.search.error.value=0;
		maxPrice.focus();
	}
	else if(eval(minPrice.value)>eval(maxPrice.value)){
		alert("Price Min is greater then Price Max.");
		document.search.error.value=0;
		obj.focus();
	}
	else
		document.search.error.value=1;
}
*/
function checkError(obj){
	if((obj.makes.value=="%") && (obj.modules.value=="%") && (obj.minYears.value=="0") && (obj.maxYears.value=="9999") && (obj.minPrice.value=="0") && (obj.maxPrice.value=="99999999"))
	{
		alert("Please select at least one criteria");
		return false;
	}
}



function adv_delete(form)
{
	document.dform.submit();
}

function calcCharLen(sForm, sTextArea, sTextInput, iMaxLimit)
{
 var _oDF = document.forms[sForm];
 var _oTxtA = _oDF.elements[sTextArea];
 var _iMaxLength = (!iMaxLimit) ? 100 : iMaxLimit;
 var _iCharLeft = _oTxtA.value.length;

 _oDF.elements[sTextInput].value = _iCharLeft;

 if(_iCharLeft > _iMaxLength)
 {
 _oTxtA.value = _oTxtA.value.substring(0, _iMaxLength);
 _oDF.elements[sTextInput].value = _iMaxLength;
 alert('You can enter only '+_iMaxLength+' characters.');
 }
}

function viewon()
{
	document.getElementById('rankid').value='';
	document.getElementById('goldstar').style.display='none';
	document.getElementById('offstar').style.display='block';
}

function uploadImage(id,basename){
	url=basename+"/imageupload.php";
	var binary;
	var filename;
	var mytext;
	//File Text Box Name
	text=document.getElementById('img'+id);
	//File Name
	filename=text.value;
	//Title Text Box Name
	title=document.getElementById('imgtitle'+id);
	//Title 
	mytext=title.value;
	document.getElementById('upimg'+id).disabled = true;
	/*try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to read file was denied.");
		document.getElementById('upimg'+id).disabled = false;
		return false;
	}*/

	http_request = false;
	http_request = new GetXmlHttpObject();
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		document.getElementById('upimg'+id).disabled = false;
		return false;
	}
	http_request.onreadystatechange = HandleStateChange;
	var parameters = "fileSize=" + encodeURI(this.fileSize) +
 "&fileName=" + encodeURI(this.fileName)+
 "&overwriteFile=" + encodeURI(document.getElementById("overwriteFile").checked);
	/*
	// prepare the MIME POST data
	var boundaryString = 'capitano';
	var boundary = '--' + boundaryString;
	var requestbody =  boundary + '\n' + 'Content-Disposition: form-data; name="id"' + '\n' 	+ '\n' 	+ id + '\n' + '\n' + boundary + '\n' + 'Content-Disposition: form-data; name="title"' + '\n' 	+ '\n' 	+ title + '\n' + '\n' + boundary + '\n' + 'Content-Disposition: form-data; name="text"; filename="' + filename + '"' + '\n' + 'Content-Type: application/octet-stream' + '\n' + '\n' + escape(binary.readBytes(binary.available())) + '\n'	+ boundary;
	//var requestbody = boundary + '\n' + 'Content-Disposition: form-data; name="id"' + '\n' 	+ '\n' 	+ id + '\n' + '\n' + boundary + '\n' + 'Content-Disposition: form-data; name="title"' + '\n' 	+ '\n' 	+ title + '\n' + '\n' + boundary + '\n' + 'Content-Disposition: form-data; name="text"; filename="' + filename + '"' + '\n' + 'Content-Type: application/octet-stream' + '\n' + '\n' + boundary;
	//document.getElementById('sizespan'+id).innerHTML = "requestbody.length=" + requestbody.length;
	// do the AJAX request
	http_request.onreadystatechange = requestdone;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "multipart/form-data; \ boundary=\"" + boundaryString + "\"");
	http_request.setRequestHeader("Connection", "close");
	http_request.setRequestHeader("Content-length", requestbody.length);
	http_request.send(requestbody);

	*/
}
function requestdone() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			result = http_request.responseText;
			document.getElementById('myspan0').innerHTML = result;            
		} else {
			alert('There was a problem with the request.');
		}
		//document.getElementById('ajaxbutton').disabled = false;
	}
}
function cnt(w,x){
	var y=w.value;
	var r = 0;
	a=y.replace(/\s/g,' ');
	a=a.split(' ');
	for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
	x.value=r;
	if(r>=600)
		alert("You have reached maximum word limits.");
}

//auto-populate e-mail from username function
function autoPopulateEmail() {
    var usernameValue = document.signupUserForm.username.value;
    var emailValue = document.signupUserForm.email.value;
    if ((emailValue == null || emailValue == "") &&
        usernameValue.indexOf("@") != -1 && usernameValue.indexOf(".") != -1) {
        document.signupUserForm.email.value = usernameValue;
    }
}

function sendRequestAndGetResponse(sUrl, oElement, sMsg, sErrMsg, sMethod, sParams)
{
	var oXmlHttp = GetXmlHttpObject();
	if(typeof(oXmlHttp) == "object")
	{
		oXmlHttp.onreadystatechange = function()
		{
			if(oXmlHttp.readyState == 4)
			{
				if(oXmlHttp.status == 200)
				{
					//prompt("", oXmlHttp.responseText);
					oElement.innerHTML = oXmlHttp.responseText;
				}
				else
				{
					oElement.innerHTML = sErrMsg;
				}

			}
			else
			{
				oElement.innerHTML = sMsg;
			}

		}

		if(sMethod == "POST")
		{
			oXmlHttp.open("POST", sUrl, true);
			oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			oXmlHttp.setRequestHeader("Content-length", sParams.length);
			oXmlHttp.setRequestHeader("Connection", "close");
			oXmlHttp.send(sParams);
		}
		else
		{
			oXmlHttp.open("GET", sUrl, true);
			oXmlHttp.send(null);
		}

	} // EO if(oXmlHttp != null)
	else
	{
		oElement.innerHTML = sErrMsg;
	}

} // EO sendRequestAndGetResponse()

function AllStates(country,web){
	if(country!=""){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url=web+"/ajax/allStates.php";
		url=url+"?countryId="+country;
		xmlHttp.onreadystatechange=getStates;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function getStates(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("state").innerHTML=xmlHttp.responseText;
	}
}

function selectState(stateId){
	if(stateId != "%"){
		document.getElementById('stateId').value=stateId;
	}
}

function AllPStates(country,web){
	if(country!=""){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url=web+"/ajax/allPStates.php";
		url=url+"?countryId="+country;
		xmlHttp.onreadystatechange=getPStates;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function getPStates(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("state").innerHTML=xmlHttp.responseText;
	}
}

function AllSearchStates(country,web){
	if(country!=""){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url=web+"/ajax/allSearchStates.php";
		url=url+"?countryId="+country;
		xmlHttp.onreadystatechange=getSearchStates;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function getPStates(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("state").innerHTML=xmlHttp.responseText;
	}
}

function getSearchStates(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("stateCMB").innerHTML=xmlHttp.responseText;
	}
}

function AllCities(state,web){
	if(state!=""){
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url=web+"/ajax/allCities.php";
		url=url+"?stateId="+state;
		xmlHttp.onreadystatechange=getCities;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function getCities(){
	if(xmlHttp.readyState==4){ 
		document.getElementById("city").innerHTML=xmlHttp.responseText;
	}
}
