var xmlHttp

/* Sub Category Result  */
function sub_category(CatId){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
	alert ("Browser does not support HTTP Request")
	return
}
var url="../../data/getCategory.php"
    url=url+"?Id="+CatId;
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}
function stateChanged(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
//	related_main_cat()
  }
}

/* Related Main Category Result  
function related_main_cat(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
        alert ("Browser does not support HTTP Request")
        return
}
var url="../../data/getRelatedMaincat.php"
    xmlHttp.onreadystatechange=RelatedMain
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}
function RelatedMain(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("DisplaymainCat").innerHTML=xmlHttp.responseText
	Full_Display_Related()
  }
}
*/

/* Related Sub Category Result  */
function RelatedSubCat(CatId){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
        alert ("Browser does not support HTTP Request")
        return
}
var url="../../data/getRelatedCategory.php"
    url=url+"?Id="+CatId;
    xmlHttp.onreadystatechange=RelatedSub
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}
function RelatedSub(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("DisplayRelatedSubCat").innerHTML=xmlHttp.responseText
	Full_Display_Related()
  }
}

/* Related Articles Result  */
function DisplayRelatedArticles(Id,SubId,countryValue){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
        alert ("Browser does not support HTTP Request")
        return
}

  var selectedArray = new Array();
var TagsVal=document.form.Tags.value
if(TagsVal==''){
	selectedArray='0';
}else{

  	var selObj = document.getElementById('Related_Tags');
  	var i;
  	var count = 0;
  	for (i=0; i<selObj.options.length; i++) {
    		if (selObj.options[i].selected) {
      			selectedArray[count] = selObj.options[i].value;
      			count++;
    		}
  	}
}
var url="../../data/getRelatedArticle.php";
    url=url+"?Id="+Id;
    url=url+"&SubId="+SubId;
    url=url+"&countryValue="+countryValue;
    url=url+"&tagValue="+selectedArray;
    xmlHttp.onreadystatechange=RelatedArticle
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}
function RelatedArticle(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("DisplayArticle").innerHTML=xmlHttp.responseText
  }
}

function Full_Display_Related(){
var MainCategorydropdownIndex = document.getElementById('Related_Main_Category').selectedIndex;
var MainCategorydropdownValue = document.getElementById('Related_Main_Category')[MainCategorydropdownIndex].value;
var SubCategorydropdownIndex = document.getElementById('Related_Sub_Category').selectedIndex;
var SubCategorydropdownValue = document.getElementById('Related_Sub_Category')[SubCategorydropdownIndex].value;
var Related_CountrydropdownIndex = document.getElementById('Related_Country').selectedIndex;
var Related_CountrydropdownValue = document.getElementById('Related_Country')[Related_CountrydropdownIndex].value;

	DisplayRelatedArticles(MainCategorydropdownValue,SubCategorydropdownValue,Related_CountrydropdownValue)
}
function  DisplayTags(){
	var Tags=document.form.Tags.value;
	var Tags_array=Tags.split(",");
	var Count=Tags_array.length;
	var content ='';
	    content+='<label><b>Related Tags</b></label><div>';
	    content+='<select name="Related_Tags" id="Related_Tags" size="7" multiple="multiple" onblur="Full_Display_Related()" onchange="Full_Display_Related()" onselect="Full_Display_Related()"  style="width:150px">';
			content+='<option value="0">Not Available</option>';
		for(i=0;i<Count;i++){
			content+='<option value="'+Tags_array[i]+'">'+Tags_array[i]+'</option>';			
		}
            content+='</select></div>';

	document.getElementById('DisplayTags').innerHTML=content;
}
function Hello(){
	alert('Helooooooooooooooooooo');
}
function addSubLinks(){
		var srcTable = document.getElementById("mytable");
		var lastRow = srcTable.rows.length;
		var iteration = lastRow + 1;
		var row = srcTable.insertRow(lastRow);

		var cellLeft0 = row.insertCell(0);
		cellLeft0.className='class-text' ;
		cellLeft0.width='auto';
		cellLeft0.align='left';
		var el0 = document.createTextNode('Title:');
		cellLeft0.appendChild(el0);		
		
		var cellRight0 = row.insertCell(1);
		cellRight0.className='class-input' ;
		cellRight0.width='auto';
		cellRight0.align='left';
		var el1 = document.createElement('input');
		el1.name ='Link[]';
		el1.size = 55;
		cellRight0.appendChild(el1);			

		var row1 = srcTable.insertRow(iteration);

		var cellLeft1 = row1.insertCell(0);
		cellLeft1.className='class-text' ;
		cellLeft1.width='auto';
		cellLeft1.align='left';
		var el2 = document.createTextNode('URL:');
		cellLeft1.appendChild(el2);		
		
		var cellRight1 = row1.insertCell(1);
		cellRight1.className='class-input' ;
		cellRight1.width='auto';
		cellRight1.align='left';
		var el3 = document.createElement('input');
		el3.name ='LinkURL[]';
		el3.size = 55;
		cellRight1.appendChild(el3);			

		var row2 = srcTable.insertRow(iteration+1);

		var cellLeft1 = row2.insertCell(0);
		cellLeft1.className='class-text' ;
		cellLeft1.width='auto';
		cellLeft1.align='left';
		var el4 = document.createTextNode('Link Hierarchy: ');
		cellLeft1.appendChild(el4);		
		
		var cellRight1 = row2.insertCell(1);
		cellRight1.className='class-input' ;
		cellRight1.width='auto';
		cellRight1.align='left';
		var el5 = document.createElement('input');
		el5.name ='Level[]';
		el5.size = 2;
		cellRight1.appendChild(el5);			

		div.appendChild(srcTable);

	return false;
}
function addSubLinksR(){
		var srcTable = document.getElementById("mytabler");
		var lastRow = srcTable.rows.length;
		var iteration = lastRow + 1;
		var row = srcTable.insertRow(lastRow);

		var cellLeft0 = row.insertCell(0);
		cellLeft0.className='class-text' ;
		cellLeft0.width='auto';
		cellLeft0.align='left';
		var el0 = document.createTextNode('Title:');
		cellLeft0.appendChild(el0);		
		
		var cellRight0 = row.insertCell(1);
		cellRight0.className='class-input' ;
		cellRight0.width='auto';
		cellRight0.align='left';
		var el1 = document.createElement('input');
		el1.name ='rLink[]';
		el1.size = 65;
		cellRight0.appendChild(el1);			

		var row1 = srcTable.insertRow(iteration);

		var cellLeft1 = row1.insertCell(0);
		cellLeft1.className='class-text' ;
		cellLeft1.width='auto';
		cellLeft1.align='left';
		var el2 = document.createTextNode('URL:');
		cellLeft1.appendChild(el2);		
		
		var cellRight1 = row1.insertCell(1);
		cellRight1.className='class-input' ;
		cellRight1.width='auto';
		cellRight1.align='left';
		var el3 = document.createElement('input');
		el3.name ='rLinkURL[]';
		el3.size = 65;
		cellRight1.appendChild(el3);			

		div.appendChild(srcTable);
	return false;
}
function addSubLinksB(){
		var srcTable = document.getElementById("mytableb");
		var lastRow = srcTable.rows.length;
		var iteration = lastRow + 1;
		var row = srcTable.insertRow(lastRow);

		var cellLeft0 = row.insertCell(0);
		cellLeft0.className='class-text' ;
		cellLeft0.width='auto';
		cellLeft0.align='left';
		var el0 = document.createTextNode('Title:');
		cellLeft0.appendChild(el0);		
		
		var cellRight0 = row.insertCell(1);
		cellRight0.className='class-input' ;
		cellRight0.width='auto';
		cellRight0.align='left';
		var el1 = document.createElement('input');
		el1.name ='bLink[]';
		el1.size = 65;
		cellRight0.appendChild(el1);			

		var row1 = srcTable.insertRow(iteration);

		var cellLeft1 = row1.insertCell(0);
		cellLeft1.className='class-text' ;
		cellLeft1.width='auto';
		cellLeft1.align='left';
		var el2 = document.createTextNode('URL:');
		cellLeft1.appendChild(el2);		
		
		var cellRight1 = row1.insertCell(1);
		cellRight1.className='class-input' ;
		cellRight1.width='auto';
		cellRight1.align='left';
		var el3 = document.createElement('input');
		el3.name ='bLinkURL[]';
		el3.size = 65;
		cellRight1.appendChild(el3);			

		div.appendChild(srcTable);
	return false;
}
function checkfilled(el){
	var elid = el.id;
	if(elid == 'edit-Link[]'){
		var LINK = elid;
		var URL = "edit-LinkURL[]";
		var level = "edit-Level[]";
		var container = document.getElementById('addmore');
	}
	if(elid == 'edit-LinkURL[]'){
		var LINK = "edit-Link[]";
		var URL = elid;
		var level = "edit-Level[]";
		var container = document.getElementById('addmore');
	}
	if(elid == 'edit-Level[]'){
		var LINK = "edit-Link[]";
		var URL = "edit-LinkURL[]";
		var level = elid;
		var container = document.getElementById('addmore');
	}
	if(elid == 'edit-rLink[]'){
		var LINK = elid;
		var URL = "edit-rLinkURL[]";
		var container = document.getElementById('addmoreR');
	}
	if(elid == 'edit-rLinkURL[]'){
		var LINK = "edit-rLink[]";
		var URL = elid;
		var container = document.getElementById('addmoreR');
	}
	if(elid == 'edit-bLink[]'){
		var LINK = elid;
		var URL = "edit-bLinkURL[]";
		var container = document.getElementById('addmoreB');
	}
	if(elid == 'edit-bLinkURL[]'){
		var LINK = "edit-bLink[]";
		var URL = elid;
		var container = document.getElementById('addmoreB');
	}

	var lvalue = document.getElementById(LINK).value;
	var urlvalue = document.getElementById(URL).value;

	if(LINK == "edit-Link[]"){
		var levelValue = document.getElementById(level).value;
		if(lvalue && urlvalue && levelValue){
			container.style.display = '';
		}
	}else{
		if(lvalue && urlvalue){
			container.style.display = '';
		}
	}
}
function getlinkset(value,path){
	if(value != ''){
		window.location = path+'link_set/edit/'+value;
	}else{
		window.location = path+'link_set/edit/';
	}
}
