										/** NRI - Cities (classifieds.js)**/
			/**Global Variables **/	
var classifiedPage;
var classifiedReq;
var errMsg="";
var app_key_id="001";
var version_number=1;			
var iFlag=1;
					/**Call Classified Page **/
					
function callClassified()
{		
//        document.getElementById('curPage').innerHTML=" : Classified Page";         
		callTopClassified();		
}

function callTopClassified()
{
    classifiedPage="classifiedTop";
    classifiedReq="../public/classified.htm?mode=classifiedHomePage";
    makeClassifiedRequestPage(classifiedPage,classifiedReq); 
	callBottomClassified();
}

function callBottomClassified()
{	
    classifiedPage="classifiedBottom";
    classifiedReq="../public/classified.htm?mode=classifiedEntriesCloud";
    makeClassifiedRequestPage(classifiedPage,classifiedReq); 	
}
			
			/** Get Entries By TagID **/
function classifiedCollection(classified)
{	
	classifiedReq="../public/classified.htm?mode=getTagList&tagId="+classified.id;
    classifiedPage="EntryByTagId";
    makeClassifiedRequestPage(classifiedPage,classifiedReq); 
	document.getElementById("curCategory").innerHTML=classified.name;
}

        /**Search By Entry or By Description using TagId**/
function getListByClassifiedDesc() {	        			
            classifiedReq="../public/classified.htm?mode=searchByTag&tagId="+document.getElementById('tagCode').value+"&Keyword="+document.getElementById('Keyword').value+"&appKeyId="+app_key_id+"&versionNo="+version_number;
            classifiedPage="search";
		    makeClassifiedRequestPage(classifiedPage,classifiedReq); 			
}

				/**Get Detail of the Entry **/
function classifiedEntryDetails(val)
{
	classifiedReq="../public/classified.htm?mode=getDetail&contentId="+val;
	classifiedPage="viewClassifiedDetail";
	makeClassifiedRequestPage(classifiedPage,classifiedReq);
}
		/**get Custom Attributes **/
function getCustom()
{
	classifiedReq="../public/classified.htm?mode=getCustomeAtt&tagId="+document.getElementById('tagCode').value;
    classifiedPage="customTag";
    makeClassifiedRequestPage(classifiedPage,classifiedReq);
}

		/** Post Entry **/
function submitClassifiedEntry()
{
	iFlag=1;
	clearValidation();
	validateClassifiedEntry();		  
}
function addClassifiedEntry(){
    if(iFlag!=0){
		if(document.getElementById('tagCode').value!="0"){
			arr=document.getElementById('customField').elements;
			var customTags="";
			for(i=0;i<arr.length;i+=2){
			customTags+='<customAttribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="classifiedCustomTag">'
			+'<customTagId>'+arr[i].id+'</customTagId>'
			+'<datatype>'+arr[i+1].type+'</datatype>'
			+'<customTagDesc>'+arr[i].value+'</customTagDesc>'
			+'<customTagValue>'+arr[i+1].value+'</customTagValue>'
			+'</customAttribute>';
		}
	
   }
    imageName = document.getElementById("mediaName0").value;
    var imageNameArray = new Array();
    imageNameArray=imageName.split(".");
    var reqTxt= '<Classified>'                   
                   +'<tagCode>'+document.getElementById('tagCode').value+'</tagCode>'
		   +'<tagName>'+document.getElementById('tagName').value+'</tagName>'
                   +'<classifiedEntryId></classifiedEntryId>'
                   +'<header>'+document.getElementById('header').value+'</header>'
                   +'<contentTypeCode></contentTypeCode>'
                   +'<charsetCode></charsetCode>'
                   +'<statusCode>001</statusCode>'
                   +'<body>'+document.getElementById('body').value+'</body>'
                   +'<website>'+document.getElementById('website').value+'</website>'
                   +'<mediaResourceId>'+imageNameArray[0]+'</mediaResourceId>'
                   +'<cityCode>'+document.getElementById('cityCode').value+'</cityCode>'
                   +'<user>'
                   +'<partyId>'+partyId+'</partyId>'                   
                   +'<partyTypeId>0</partyTypeId>'
                   +'<isActive>true</isActive>'
                   +'<nameList/>'
                   +'<relationShipList>'
                   +'<relationShip xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="relationShip">'
                   +'<relationShipStatusId>27</relationShipStatusId>'
                   +'<relationShipTypeId>14</relationShipTypeId>'
                   +'<fromParty>2</fromParty>'                   
                   +'</relationShip>'
                   +'</relationShipList>'
                   +'<contactsList>'                   
                   +'<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="phoneNumber">'            
                   +'<contactType>1</contactType>'
                   +'<phoneNo>'+document.getElementById('phoneNo').value+'</phoneNo>'
                   +'</contact>'  
                   +'<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="emailAddress">'            
                   +'<contactType>2</contactType>'
                   +'<emailId>'+document.getElementById('emailId').value+'</emailId>'
                   +'</contact>'                 
                   +'</contactsList>'
                   +'<countryList/>'
                   +'<stateList/>'
                   +'<cityList/>'
                   +'<postalList/>'
                   +'</user>'
                   +'<endPosition>0</endPosition>'
                   +'<startPosition>0</startPosition>'
                   +'<classifiedResponse/>'
                   +'<classifiedCustomAttributeList>'+customTags+'</classifiedCustomAttributeList>'
                   +'<appId>'+app_key_id+'</appId>'
                   +'<versionNo>'+version_number+'</versionNo>'
                   +'</Classified>';   				   
                   classifiedReq="../secure/classified.htm?mode=newEntryPost&data="+reqTxt;
                   classifiedPage="posted";
                   //alert(reqTxt);
                   makeClassifiedRequestPage(classifiedPage,classifiedReq);
}   
}
				/** Delete the Classified **/
function deleteClassifiedPageEntry(id){
        classifiedReq="../public/classified.htm?mode=delete&data="+id;        
		classifiedPage="delete";
		makeClassifiedRequestPage(classifiedPage,classifiedReq);
}

			/**Post Response **/
function postresponse(id) {    
	  TB_ShowObj(id);
}				
				/**Edit Classified Entry**/				
					
function editclassifieds(val){
	window.location.href="../secure/classified.htm?mode=classifiedEditDetail&contentId="+val+"&_1="+Math.random();       				
}

function editCustom(val){
	classifiedReq="../secure/classified.htm?mode=editCustomDeatil&contentId="+val;
    classifiedPage="customTag";
    makeClassifiedRequestPage(classifiedPage,classifiedReq);	
}
				
function editClassifiedEntry(id){  
 iFlag=1;
 clearValidation();
 validateEditClassifiedEntry();
 if(iFlag!=0){    
	arr=document.getElementById('customField').elements;
    var customTags="";
    for(i=0;i<arr.length;i+=2){
    customTags+='<customAttribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="classifiedCustomTag">'
    +'<customTagId>'+arr[i].id+'</customTagId>'
    +'<datatype>'+arr[i+1].type+'</datatype>'
    +'<customTagDesc>'+arr[i].value+'</customTagDesc>'
    +'<customTagValue>'+arr[i+1].value+'</customTagValue>'
    +'</customAttribute>';
   }

    imageName = document.getElementById("mediaName0").value;
    var imageNameArray = new Array();
			imageNameArray=imageName.split(".");
   var reqTxt= '<Classified>'                   
                   +'<tagCode>'+document.getElementById('tagCode').value+'</tagCode>'
                   +'<classifiedEntryId>'+document.getElementById('hiddenClassifiedEntryId').value+'</classifiedEntryId>'
                   +'<header>'+document.getElementById('header').value+'</header>'
                   +'<contentTypeCode></contentTypeCode>'
                   +'<charsetCode></charsetCode>'
                   +'<statusCode>001</statusCode>'
                   +'<body>'+document.getElementById('body').value+'</body>'
                   +'<website>'+document.getElementById('website').value+'</website>'
                   +'<mediaResourceId>'+imageNameArray[0]+'</mediaResourceId>'
                   +'<cityCode>'+document.getElementById('cityCode').value+'</cityCode>'
                   +'<user>'
                   +'<partyId>'+partyId+'</partyId>'                   
                   +'<partyTypeId>0</partyTypeId>'
                   +'<isActive>true</isActive>'
                   +'<nameList/>'
                   +'<relationShipList>'
                   +'<relationShip xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="relationShip">'
                   +'<relationShipStatusId>27</relationShipStatusId>'
                   +'<relationShipTypeId>14</relationShipTypeId>'
                   +'<fromParty>2</fromParty>'                   
                   +'</relationShip>'
                   +'</relationShipList>'
                   +'<contactsList>'                   
                   +'<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="phoneNumber">'            
                   +'<contactType>1</contactType>'
                   +'<phoneNo>'+document.getElementById('phoneNo').value+'</phoneNo>'
                   +'</contact>'  
                   +'<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="emailAddress">'            
                   +'<contactType>2</contactType>'
                   +'<emailId>'+document.getElementById('emailId').value+'</emailId>'
                   +'</contact>'                 
                   +'</contactsList>'
                   +'<countryList/>'
                   +'<stateList/>'
                   +'<cityList/>'
                   +'<postalList/>'
                   +'</user>'
                   +'<contentId>'+id+'</contentId>'
                   +'<endPosition>0</endPosition>'
                   +'<startPosition>0</startPosition>'
                   +'<classifiedCustomAttributeList>'+customTags+'</classifiedCustomAttributeList>'
                   +'<appId>'+app_key_id+'</appId>'
                   +'<versionNo>'+version_number+'</versionNo>'
                   +'</Classified>';     
                   classifiedReq="../secure/classified.htm?mode=editClassifiedEntry&data="+reqTxt;
                   classifiedPage="update";
                   makeClassifiedRequestPage(classifiedPage,classifiedReq);
 } 
}
    /**For coming Back to Home**/
function backToClassifiedPage(){
	window.location.href="../public/classified.htm";
}
					/** Post Response **/
function sendResponse(classifiedEntryId){
    if((document.getElementById('postResponse').value==null)||(isBlank(document.getElementById('postResponse').value)==true)) {
        alert("Please enter a response message.")
    } else {
        var reqTxt='<Classified>'                   
                   +'<classifiedEntryId>'+classifiedEntryId+'</classifiedEntryId>'
                   +'<contentId>'+document.getElementById('contentId').value+'</contentId>'
                   +'<user>'
                   +'<partyId>'+partyId+'</partyId>'                   
                   +'</user>'
                   +'<classifiedResponse>'
                   +'<classifiedResponseDesc>'+document.getElementById('postResponse').value+'</classifiedResponseDesc>'
                   +'<classifiedResponseCode>101</classifiedResponseCode>'                   
                   +'</classifiedResponse>' 
                   +'<appId>'+app_key_id+'</appId>'
                   +'<versionNo>'+version_number+'</versionNo>'
                   +'</Classified>';    
                   classifiedReq="../public/classified.htm?mode=postResponse&data="+reqTxt;
                   classifiedPage="postResponse";
                   makeClassifiedRequestPage(classifiedPage,classifiedReq);				   
    }
}
					/**Genral Ajax Function **/
					
function makeClassifiedRequestPage(classifiedPage,classifiedReq){
	$.ajax({
		   type:"GET", url:classifiedReq+"&_1="+Math.random(),dataType:"textvalue",cache: false,success: function(response){
	if(classifiedPage=="classifiedTop"){
		$("#topContent").html(response);
		doWordWrap();
	}if(classifiedPage=="classifiedBottom"){
		$("#categoryCloud").html(response);
	}if(classifiedPage=="EntryByTagId"){
		$("#topContent").html(response);
	}if(classifiedPage=="viewClassifiedDetail"){
		$("#topContent").html(response);
		$("#city_navigation1").css("display","none");
		$("#cities_navigation").css("display","none");
		if (window.attachEvent == undefined) { 
				var tag1 = document.getElementsByTagName("span");
				for (var i = 0; i < tag1.length; i++) 
				{
				if (tag1.item(i).className == "style11") 
				{
				var text1 = tag1.item(i).innerHTML; 
				tag1.item(i).innerHTML = text1.replace(/(.*?)/g, "<wbr />"); 
				}
				}
				} 
	}if(classifiedPage=="search"){
		$("#topContent").html(response);
		$("#city_navigation1").css("display","inline");
		$("#cities_navigation").css("display","inline");
		doWordWrap();
	}if(classifiedPage=="customTag"){  	   		
		$("#customAttributeContent").html(response);                    
	}if(classifiedPage=="delete"){  	   		
		alert("Selected Entry Deleted");         
		backToClassifiedPage();
	}if(classifiedPage=="update"){  	   		
		alert("Successfully Entry Updated");
		backToClassifiedPage();
	}if(classifiedPage=="posted"){  	   		
		alert("Successfully Entry Posted");                    
		backToClassifiedPage();
	}if(classifiedPage=="postResponse"){  	   		
		alert("Successfully Response Posted");                    
		backToClassifiedPage();
	}
	
	},error : function(XMLHttpRequest,textStatus,errorThrown){
		alert("Not Loaded Properly")
		}
		}); 	
}			 


			/**Verify Classified**/
			
function validateClassifiedEntry(){
	document.getElementById("city_error_main").style.display = "none";
	document.getElementById("city_error_main").innerHTML ="";	
	document.getElementById("errJcaptchachars").innerHTML="";
	if ((document.getElementById('header').value==null)||(isBlank(document.getElementById('header').value)==true))
	{   
		document.getElementById("errTitle").innerHTML="<span class='err_txt1'>" + sMsg + "</span>";
		iFlag=0;
	}
   /* if(document.getElementById('tagCode').value=="0")
	{
		document.getElementById("errTag").innerHTML="<span class='err_txt1'>Please Select Category</span>";
		iFlag=0;
	}*/
	/* validation for Tag */
	if(document.getElementById("tagCode").value=="0" && document.getElementById("tagName").value==""){
		 $("#errTag").html("<span class='err_txt1'>Please select a tag or add new tag</span>");
	 	 iFlag=0;
	 }
	 else if(document.getElementById("tagCode").value!="0" && document.getElementById("tagName").value!=""){
	 	$("#errTag").html("<span class='err_txt1'>Please select either a tag or add new tag</span>");
	 	 iFlag=0;
	 }else{
		$("#errTag").html("");
	}
	if(document.getElementById("tagCode").value!="0"){
		customValidation();
	}
	if(document.getElementById('countryCode').value=="0")
	{
		document.getElementById("errCountry").innerHTML="<span class='err_txt1'>"+ sCountryMsg +"</span>";
		iFlag=0;
	}
	if(document.getElementById('stateCode').value=="0")
	{
		document.getElementById("errState").innerHTML="<span class='err_txt1'>"+ sStateMsg +"</span>";
		iFlag=0;
	}
	if(document.getElementById('metroAreaId').value=="-1")
	{
		document.getElementById("errMetroCity").innerHTML="<span class='err_txt1'>Please Select MetroCity</span>";
		iFlag=0;		
//		errMsg=errMsg+"Please Select State\n";
	}
        if(document.getElementById('cityCode').value=="0")
	{
		document.getElementById("errCity").innerHTML="<span class='err_txt1'>Please Select City</span>";
		iFlag=0;
	}	
	if(false==isBlank(document.getElementById('phoneNo').value))
	{
		if((document.getElementById('phoneNo').value.length)==12 || (document.getElementById('phoneNo').value.length)==10) {
			if((document.getElementById('phoneNo').value.length)==12)
	       	{
				if(document.getElementById('phoneNo').value.charAt(3)=='-' && document.getElementById('phoneNo').value.charAt(7)=='-'){
				
				}else {
					document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
				}
			} else {
				if(isInteger(document.getElementById('phoneNo').value)==false) {
					document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
				}
			}
		} else {
			document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
		}
	}else{ 
		document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;
	}
	if ((document.getElementById('emailId').value==null)||(isBlank(document.getElementById('emailId').value)==true))
	{
			document.getElementById("errMail").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
			iFlag=0;
	}
	if(false==isBlank(document.getElementById('emailId').value))
	{		 
		if (eCheck(document.getElementById('emailId').value)==false)
		{
				document.getElementById("errMail").innerHTML="<span class='err_txt1'> Invalid E-mailId </span>";
				iFlag=0;
		}
	}
	/*if ((document.getElementById('website').value==null)||(isBlank(document.getElementById('website').value)==true))
	{
		document.getElementById("errWebSite").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;			
	} */	
	if ((document.getElementById('body').value==null)||(isBlank(document.getElementById('body').value)==true))
	{
		document.getElementById("errDescription").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;
	}         
	
/*Validation for Jcaptcha*/
		if ((document.getElementById('jcaptchachars').value==null)||(isBlank(document.getElementById('jcaptchachars').value)==true)){	
			document.getElementById("errJcaptchachars").innerHTML="<span class='err_txt1'>" + sValCode + "</span>";;
			iFlag=0;			
		}else if (isalpha(document.getElementById('jcaptchachars').value)==false){
			document.getElementById("errJcaptchachars").innerHTML="<span class='err_txt1'>" + sAlphaMsg + "</span>";
			iFlag=0;						
		}else{
			document.getElementById("errJcaptchachars").innerHTML="";
		}
		/*Check for flag*/
		if(iFlag==0){			
			document.getElementById("city_error_main").style.visibility = "visible";
			document.getElementById("city_error_main").style.display = "block";
			document.getElementById("city_error_main").innerHTML = "Please correct error fields for successful post entry. Errors are mentioned below respective fields";						
		}else{
			checkPostEntryJcaptcha("classified"); 
		}	
}		
		/**Edit Validation for Classfied**/
		
function validateEditClassifiedEntry(){	
	customValidation();
	if ((document.getElementById('header').value==null)||(isBlank(document.getElementById('header').value)==true))
	{   
		document.getElementById("errTitle").innerHTML="<span class='err_txt1'>" + sMsg + "</span>";
		iFlag=0;
	}       
	if(document.getElementById('countryCode').value=="0")
	{
		document.getElementById("errCountry").innerHTML="<span class='err_txt1'>"+ sCountryMsg +"</span>";
		iFlag=0;
	}
	if(document.getElementById('stateCode').value=="0")
	{
		document.getElementById("errState").innerHTML="<span class='err_txt1'>"+ sStateMsg +"</span>";
		iFlag=0;
	}
	if(document.getElementById('cityCode').value=="0")
	{
		document.getElementById("errCity").innerHTML="<span class='err_txt1'>Please Select City</span>";
		iFlag=0;
	}	
	if(document.getElementById('metroAreaId').value=="-1")
	{
		document.getElementById("errMetroCity").innerHTML="<span class='err_txt1'>Please Select MetroCity</span>";
		iFlag=0;		
//		errMsg=errMsg+"Please Select State\n";
	}	
	if(false==isBlank(document.getElementById('phoneNo').value))
	{
	      	if((document.getElementById('phoneNo').value.length)==12 || (document.getElementById('phoneNo').value.length)==10) {
			if((document.getElementById('phoneNo').value.length)==12)
	       	{
				if(document.getElementById('phoneNo').value.charAt(3)=='-' && document.getElementById('phoneNo').value.charAt(7)=='-'){
				
				}else {
					document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
				}
			} else {
				if(isInteger(document.getElementById('phoneNo').value)==false) {
					document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
				}
			}
		} else {
			document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>Phone Number should have 10 digit or Phone Number Format can be ###-###-####</span>";
					iFlag=0;				
		}
    }else
	{ 
		document.getElementById("errPhoneNumber").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;
	}
    if ((document.getElementById('emailId').value==null)||(isBlank(document.getElementById('emailId').value)==true))
	{
		document.getElementById("errMail").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;
	}
    if(false==isBlank(document.getElementById('emailId').value))
	{		 
		if (eCheck(document.getElementById('emailId').value)==false)
		{
			document.getElementById("errMail").innerHTML="<span class='err_txt1'> Invalid E-mailId </span>";
			iFlag=0;
		}
	}
	
/*	if ((document.getElementById('website').value==null)||(isBlank(document.getElementById('website').value)==true))
	{
		document.getElementById("errWebSite").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
		iFlag=0;			
	} 	*/
	/*if ((document.getElementById('body').value==null)||(isBlank(document.getElementById('body').value)==true))
	{
			document.getElementById("errDescription").innerHTML="<span class='err_txt1'>"+ sMsg +"</span>";
			iFlag=0;
	} */        
/*Check for flag*/
	if(iFlag==0){			
		document.getElementById("city_error_main").style.visibility = "visible";
		document.getElementById("city_error_main").style.display = "block";
		document.getElementById("city_error_main").innerHTML = "Please correct error fields for successful update entry. Errors are mentioned below respective fields";						
	} 	
}
