// JavaScript Document

function addCategory(formName,fieldName,cal11)
{
	var objEl = document.forms[formName].elements[fieldName];
	var totLength = objEl.length;
	var i=0;
	
	for(i=0;i<totLength;i++)
	{
		
		if(objEl[i].selected == true)
		{
			var a = document.add_article.category_id.options[i].value;
			alert(a);
			document.add_article.cat11.options.value = a;
			alert(document.add_article.cat11.options.value);
		}
		
	}
	return false;
}


function addReferralCityID(frmName, cityDD, fieldName) {
	var flag;
	var ddObject = document.forms[frmName].elements[fieldName];
	var cityObj = document.forms[frmName].elements[cityDD];
	if(cityObj.length) {
		var currentTotalCity = parseInt(ddObject.length);
		var newLen = currentTotalCity;
		counter = 0;
		for(n=0; n<cityObj.length; n++){
			if(cityObj[n].selected == true){
			ID = cityObj[n].value;
			cityName = cityObj[n].text;
			flag = true;
			for (j=0; j<newLen; j++) {
			if(ddObject[j].value == ID) flag = false;
		}
			if(flag == true){
				ddObject.options[(newLen)] = new Option(cityName, ID);
				newLen = newLen+1;
				}
			}
		}
	}
	else{
			
	}
		
}

function removeReferralCityID(frmName, fieldName) {
	var flag;
	var ddObject = document.forms[frmName].elements[fieldName];
	var tmpID = new Array();
	var tmpTxt = new Array();
	counter = 0;
	if(ddObject.length) {
		for(n=0; n<ddObject.length; n++){
			if(ddObject[n].selected == false){
				tmpID[counter] = ddObject[n].value;
				tmpTxt[counter] = ddObject[n].text;
				counter = counter+1;
			}
		}
		ddObject.length = 0;
		for(i=0; i<tmpID.length; i++ ){
			ddObject.options[i] = new Option(tmpTxt[i], tmpID[i]);
		}
	}
	else{
			
	}
	
}

function selected_box()
{
	var ddArticle = document.forms['add_article'].elements['author_id'];
	var ddCategory = document.forms['add_article'].elements['category_id'];
	
	
	for(n=0;n<ddArticle.length;n++)
	{
		ddArticle[n].selected = true;
	}
	
	for(n=0;n<ddCategory.length;n++)
	{
		ddCategory[n].selected = true;
	}
	
	

}

function selected_alert(formName)
{
	var ddArticle = document.forms['search'].elements['channel_id'];
	var ddCategory = document.forms['search'].elements['category_id'];
	
	for(n=0;n<ddArticle.length;n++)
	{
		ddArticle[n].selected = true;
	}
	
	for(n=0;n<ddCategory.length;n++)
	{
		ddCategory[n].selected = true;
	}

}

function select_city_box()
{
	 var ddCity = document.forms['listForm'].elements['city_id'];
	 
	 for(n=0;n<ddCity.length;n++)
	{
		ddCity[n].selected = true;
	}
}



function select_videocat(formName)
{
	
	var ddCategory = document.forms[formName].elements['category_id'];
	
	for(n=0;n<ddCategory.length;n++)
	{
		ddCategory[n].selected = true;
	}
}
function select_status()
{
	if(document.add_video.type[0].checked == true)
	{
			
			document.getElementById("file_general").style.display = "block";
			document.getElementById("lbl_general").style.display = "block";
			
			document.getElementById("youtube").style.display = "none"
			document.getElementById("lbl_youtube").style.display = "none";
	}
	
	if(document.add_video.type[1].checked == true)
	{
		
			document.getElementById("file_general").style.display = "none";
			document.getElementById("lbl_general").style.display = "none";
			
			document.getElementById("youtube").style.display = "block"
			document.getElementById("lbl_youtube").style.display = "block";
		
	}
	
}

function select_editor()
{
	if(document.add_news.type[0].checked == true)
	{
		document.getElementById("html_editor").style.display = "block";
		document.getElementById("normal_editor").style.display = "none";
	}
	
	if(document.add_news.type[1].checked == true)
	{
		document.getElementById("html_editor").style.display = "none";
		document.getElementById("normal_editor").style.display = "block";
	}
}

function fetch_mail_id()
{
	var test_mailId = document.add_news.test_mail_id.value;
	var subject = document.add_news.subject.value;
	if(document.add_news.type[0].checked==true){
	var type = document.add_news.type[0].value;
	}
	else
	{
	  var type = document.add_news.type[1].value;
	}
	
	var content = document.add_news.content.value;
	
	var textContent = document.add_news.normal_content.value;
	
	var at="@"
	var dot="."
	var lat=test_mailId.indexOf(at)
	var lstr=test_mailId.length 
	
	if(test_mailId == "")
	{
		document.getElementById("erreor").innerHTML = "Please give a mail address";
	}
	else if(test_mailId.indexOf(at)==-1)
	{
		document.getElementById("erreor").innerHTML = "Invalid Mail Address";
	}
	else if(test_mailId.indexOf(dot)==-1)
	{
		document.getElementById("erreor").innerHTML = "Invalid Mail Address";
	}
	else
	{
		
		//window.open ("/thinkdigit/admin/admin_newsletter_manager.php?mode=send_mail&test_mailId="+test_mailId+"&subject="+subject+"&type="+type+"&content="+content+"&textContent"+textContent, 1,'scrollbars=0,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=1,width=250,height=150');
		window.open ("admin_newsletter_manager.php?mode=send_mail&test_mailId="+test_mailId+"&subject="+subject+"&type="+type+"&content="+content+"&textContent="+textContent, 1,'scrollbars=0,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=1,width=250,height=150');
	}
	
}
function openWin(url)
{
	
	//window.open ("/thinkdigit/admin/admin_article_manager.php?mode=view_article&article_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
	window.open (url, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
}

function openWin_newsletter(id)
{
	//window.open ("/thinkdigit/admin/admin_newsletter_manager.php?mode=view_news&news_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
	window.open ("admin_newsletter_manager.php?mode=view_news&news_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
}


function openWin_product(id)
{
	//window.open ("/thinkdigit/admin/admin_newsletter_manager.php?mode=view_news&news_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
	window.open ("admin_product_manager.php?mode=view_product&product_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
}


function openyoutube_win(id)
{
	//window.open ("/thinkdigit/admin/admin_video_manager.php?mode=display_youtube&video_id="+id, 1,'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=1,width=500,height=450');
	window.open ("admin_video_manager.php?mode=display_youtube&video_id="+id, 1,'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=1,width=500,height=450');
}

function opengeneral_win(id)
{
	//window.open ("/thinkdigit/admin/admin_video_manager.php?mode=display_general&video_id="+id, 1,'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=1,width=300,height=250');
	window.open ("admin_video_manager.php?mode=display_general&video_id="+id, 1,'scrollbars=1,toolabars=0,resizable=1,status=0,menubar=0,directories=0,location=1,width=300,height=250');
}

function abc(val)
{
  alert(val.channel_id.value);
  return false;
}

function openWin_opinion(id)
{
	//window.open ("/thinkdigit/admin/admin_newsletter_manager.php?mode=view_news&news_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=600');
	window.open ("admin_opinion_manager.php?mode=view_opinion&opinion_id="+id, 1,'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=1,width=800,height=400');
}


function selectBrand(pageName,cat_id)
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	  
	var url=pageName;
	url=url+"?category_id="+cat_id;
	url=url+"&mode=brandDD";
			
	xmlHttp.onreadystatechange = function ()
	{
	  if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
		{
		
			var returned_text = xmlHttp.responseText;
			
			document.getElementById("brand").innerHTML=returned_text;
			
		}
	}
		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		// document.getElementById('blogPop').innerHTML='I am here';
}

function selectProduct(pageName,cat_id,brand)
{
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	  
	var url=pageName;
	url=url+"?category_id="+brand;
	url=url+"&brand_name="+cat_id;
	url=url+"&mode=productDD";
			
	xmlHttp.onreadystatechange = function ()
	{
	  if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
		{
		
			var returned_text = xmlHttp.responseText;
			
			document.getElementById("model").innerHTML=returned_text;
			
		}
	}
		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		// document.getElementById('blogPop').innerHTML='I am here';
}


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;
}


