/**
 * @author Parth Arora <parth@savitriya.com>
 * @Desc function to toggle between basic text search and advanced search
 *       options
 *
 * @param flag -
 *            (string) takes one of the two arguments 'show' or 'hide'
 * @param searchUrl -
 *            (string) url from where the search form is to be fetched
 * @param containers -
 *            (array) conataining values for container ID for basicSearch &
 *            advancedSearch
 * @return will show hide the div's for basic text search and advanced search
 */



function searchOptions(flag,grid_id,searchUrl,containers){

	if(flag=='show'){
		$.ajax({
	        type: "POST",
	        url: searchUrl,
	        async:false,
	        success: function(response){

	        	document.getElementById(containers["advancedSearch"]).innerHTML = response;

	        	// remove the post data items of the basic text search
	        	var basicdivElements = document.getElementById(containers["basicSearch"]).getElementsByTagName('*');

	    		// remove post data items of advanced search from the grid post
				// data parameters
	    		for(var count=0;count<basicdivElements.length;count++){

	    			if(basicdivElements[count].tagName.toLowerCase()=='input' || basicdivElements[count].tagName.toLowerCase()=='select' || basicdivElements[count].tagName.toLowerCase()=='textarea'){

	    				if(basicdivElements[count].value!=""){
	    					basicdivElements[count].value = "";
	    					$("#"+grid_id).jqGrid('removePostDataItem',basicdivElements[count].id);
	    				}
	    			}
	    		}

	        	// attach events to elements of advanced search
	        	var divElements = document.getElementById(containers["advancedSearch"]).getElementsByTagName('*');

	    		for(var count=0;count<divElements.length;count++){

	    			if(divElements[count].tagName.toLowerCase()=='input' || divElements[count].tagName.toLowerCase()=='select' || divElements[count].tagName.toLowerCase()=='textarea'){

	    				document.getElementById(divElements[count].id).onkeyup = function(event){
	    	    			searchData(event,grid_id,'advanced',containers);
	    	    		};
	    			}
	    		}
			}
		});
	}

	if(flag=='hide'){
		var divElements = document.getElementById(containers["advancedSearch"]).getElementsByTagName('*');

		// remove post data items of advanced search from the grid post data
		// parameters
		for(var count=0;count<divElements.length;count++){

			if(divElements[count].tagName.toLowerCase()=='input' || divElements[count].tagName.toLowerCase()=='select' || divElements[count].tagName.toLowerCase()=='textarea'){

				if(divElements[count].value!=""){
					$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
				}
			}
		}

		// set the innerHTML of the advanced search to null
		document.getElementById(containers["advancedSearch"]).innerHTML = '';

	}
}

/**
 * @author Parth Arora <parth@savitriya.com>
 * @Desc set the grid params to search the data in grid and populate the results
 *       returned from the server in grid
 *
 * @param evt -
 *            (object) keycode event object to search when enter key is pressed
 * @param grid_id -
 *            (string) id of the jqgrid in which the data is to be searched and
 *            populated
 * @param params -
 *            (array) an array containing parameters and parameter values to be
 *            searched for
 *
 * @return will populate the jqgrid with data fetched based on the search string
 *         or multiple search parameters provided
 */
function searchData(evt,grid_id,searchType,containers){
	if(searchType=="advance"){
		$("#MsgBar").html("");
		$("#MsgBar").html(messageload+"<span>Searching...</span>");
		document.getElementById("MsgBar").style.display="inline-block";
	}
	// optional key event argument
	if(evt==null)evt = '';
	var searchFlag = false;

	if(searchType=='basic'){
		var divElements = document.getElementById(containers["basicSearch"]).getElementsByTagName('*');
	}
	else if(searchType=='advanced'){
		var divElements = document.getElementById(containers["advancedSearch"]).getElementsByTagName('*');
	}

	/*
	 * set Post Data for grid to include all search parameters and parameter
	 * values
	 */
	for(var count=0;count<divElements.length;count++){

		if(divElements[count].tagName.toLowerCase()=='input' || divElements[count].tagName.toLowerCase()=='select' || divElements[count].tagName.toLowerCase()=='textarea'){
			if(divElements[count].id!="SearchCountryId" && divElements[count].id!="SearchStateId" && divElements[count].id!="SearchCityId" && divElements[count].id!="SearchAreaId" && divElements[count].id!="SearchContactId" && divElements[count].id!="SearchCompanyId" && divElements[count].id!="SearchNextActivityBy" && divElements[count].id!="SearchTemplateflag"){
				if(divElements[count].value!=""){
					$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,divElements[count].value.toLowerCase());
					searchFlag = true;
				}
				else{
					$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
				}
			}
			// this for country,state,city,area autocomplete
			else{
				if(divElements[count].id=="SearchCountryId"){
					if(document.getElementById("searchcountryid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchcountryid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchContactId"){
					if(document.getElementById("searchcontactid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchcontactid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchCompanyId"){
					if(document.getElementById("searchcompanyid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchcompanyid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchNextActivityBy"){
					if(document.getElementById("searchnextactivitybyid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchnextactivitybyid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchStateId"){
					if(document.getElementById("searchstateid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchstateid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchCityId"){
					if(document.getElementById("searchcityid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchcityid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchAreaId"){
					if(document.getElementById("searchareaid").value!=""){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,document.getElementById("searchareaid").value);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}

				if(divElements[count].id=="SearchTemplateflag"){
					if(document.getElementById("SearchTemplateflag").checked==true){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,1);
						searchFlag = true;
					}
					else if(document.getElementById("SearchTemplateflag").checked==false){
						$("#"+grid_id).jqGrid('setPostDataItem',divElements[count].id,0);
						searchFlag = true;
					}
					else{
						$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
					}
				}
			}
		}
	}

	/*
	 * set searchType parameter
	 */
	$("#"+grid_id).jqGrid('setPostDataItem','searchType',searchType);
	/*
	 * detects the keycode of the key pressed. this should cover all major
	 * browsers evt.keycode is used for IE and browsers belonging to its family
	 * and evt.which is used for Browsers belonging to family of Firefox,
	 * Chrome, etc
	 */
	if(evt!=null && evt!='')var charCode = (evt.which) ? evt.which : evt.keyCode;
	else var charCode = '';
	if((evt!=null && evt!="" && charCode==13) || evt=="" || evt==null){
		if(searchFlag==true){
			$("#"+grid_id).jqGrid('setPostDataItem','search','true');
			if(searchType=='advanced'){
				displaymessage("MsgBar",messageload+"<span class='modelmsgtext'>Saving..</span>");
			}
			$("#"+grid_id).trigger("reloadGrid");
			if(searchType=='advanced'){
				gettotalrecords(grid_id);
			}
		}
		else if(searchFlag==false){
			resetSearch(grid_id,containers);
		}
	}

}

function gettotalrecords(gridid)
{
	document.getElementById('MsgBar').style.display="block";
    if(jQuery("#"+gridid).getGridParam("records")==0)
    {
    	$("#MsgBar").html("No Records Found");
		document.getElementById("MsgBar").style.display="inline-block";
		setTimeout("if(document.getElementById('MsgBar'))document.getElementById('MsgBar').style.display='none'","5000");
    }
    else
    {
        document.getElementById('MsgBar').innerHTML=jQuery("#"+gridid).getGridParam("records")+"\t Records Found";
        document.getElementById("MsgBar").style.display="inline-block";
		setTimeout("if(document.getElementById('MsgBar'))document.getElementById('MsgBar').style.display='none'","5000");
    }
}

/**
 *
 * @param grid_id -
 *            (string) id of the grid
 * @param containers -
 *            (array) - consisting the id's of the two containers in which the
 *            search elements have been placed
 * @return resets values and removes all the search parameters that are passed
 *         to the grid
 */
function resetSearch(grid_id,containers){

	// remove post data items for all advanced search parameters
	var divElements = document.getElementById(containers["advancedSearch"]).getElementsByTagName('*');
	for(var count=0;count<divElements.length;count++){

		if(divElements[count].tagName.toLowerCase()=='input' || divElements[count].tagName.toLowerCase()=='select' || divElements[count].tagName.toLowerCase()=='textarea'){
			if(divElements[count].id!=""){
				$("#"+grid_id).jqGrid('removePostDataItem',divElements[count].id);
				document.getElementById(divElements[count].id).value = "";
			}
		}
	}

	// remove post data items for all basic search parameters
	var basic_divElements = document.getElementById(containers["basicSearch"]).getElementsByTagName('*');
	for(var count=0;count<basic_divElements.length;count++){

		if(basic_divElements[count].tagName.toLowerCase()=='input' || basic_divElements[count].tagName.toLowerCase()=='select' || basic_divElements[count].tagName.toLowerCase()=='textarea'){

			$("#"+grid_id).jqGrid('removePostDataItem',basic_divElements[count].id);
			document.getElementById(basic_divElements[count].id).value = "";
		}
	}

	// remove other parameters
	$("#"+grid_id).jqGrid('removePostDataItem',"search");
	$("#"+grid_id).jqGrid('removePostDataItem',"searchType");

        $("#"+containers["advancedSearch"]).dialog('close');
// // set the innerHTML of the advanced search to null
// document.getElementById(containers["advancedSearch"]).innerHTML = '';
// document.getElementById(containers["advancedSearch"]).style.display = 'none';
//
	// show the basic text search box
	document.getElementById(containers["basicSearch"]).style.display = 'block';

	// reload grid to show all data
	$("#"+grid_id).trigger("reloadGrid");
}
function allcheckboxxlick(chkid,gridid,queryid){
	var records_per_pages = jQuery("#"+gridid).getGridParam("rowNum");
	var total_records = jQuery("#"+gridid).getGridParam("records");
	var valid_count = parseInt(parseInt(total_records)/parseInt(records_per_pages));
	if(valid_count>0){
		if(document.getElementById(chkid).checked==true){
			document.getElementById("notification_mainmsgsave").style.display="inline-block";
			document.getElementById("notification_msgsave").innerHTML="Loading...";
			var total = $("#"+gridid).getGridParam('records');
			document.getElementById("notification_msgsave").innerHTML = 'All records of this page has been selected.For selecting <font color="#003333">'+total+'</font> Records. </b><a href="#" onclick=\'selectAll("'+queryid+'","'+total+'","'+chkid+'")\'> Click Here</a> |<a href="#" onclick=\'unselectAll("'+queryid+'","'+chkid+'")\'> Close</a>';
		}
		else{
			document.getElementById("notification_mainmsgsave").style.display="none";
			document.getElementById("notification_msgsave").innerHTML="";
		}
	}
}

function selectAll(queryid,total,chkid){
	document.getElementById(queryid).value="selectall";
	document.getElementById("notification_mainmsgsave").style.display="inline-block";
	$("#notification_msgsave").html('<div style="background-color:#ffff99;width:55%;margin-left:20%;z-index:1500;"><b><font color="#003333">'+total+'</font> Records has been selected. </b><a href="#" onclick=\'unselectAll("'+queryid+'","'+chkid+'")\'> Clear selection</a></div>');
}

function unselectAll(queryid,chkid){
	document.getElementById(queryid).value="";
	document.getElementById("notification_mainmsgsave").style.display ='none';
	document.getElementById("notification_msgsave").innerHTML ='';
	document.getElementById(chkid).checked=false;
}

//function modelpopupcenter(modeldivid,height,width){
//	$("#"+modeldivid).dialog( "option", "height",height);
//	$("#"+modeldivid).dialog( "option", "width",width);
//
//}
//function modelpopupinner(innerdivid,height,width){
//        $("#"+innerdivid).css('height',height);
//        $("#"+innerdivid).css('overflow','auto');
//}
/*
 * this function arrange the model pup up in center and give overflow property to form div if it needed
 * @param formdiv:Id of that div which is exject below the model pop div
 * @param modelpopdiv:model pop up div id
 * @param innerformdiv:Id of that div which contain all the elements except all buttons
 */
function arrangemodelpopup(formdiv,modelpopupdiv,innerformdiv,flag,defheight){
	if(flag==null)flag="";
	if(defheight==null)defheight="";
	//get the formdiv height
	var totalelement_height="";
	if(defheight=="")totalelement_height = $("#"+formdiv).height();
	else totalelement_height =defheight;
	//get the value of model pop up margin which is from top left
	var modelpopup_margin = Math.round(Number(winH/8));
	//calculate innerdiv height
	var final_innerdiv_height = Number(winH-totalelement_height-Number(2*modelpopup_margin));
	//if innerdiv height is greater than 0 then no scroll bar else scroll bar
	if(final_innerdiv_height>0)final_innerdiv_height=Number(totalelement_height-50);
	else final_innerdiv_height = Number(winH-Number(2*modelpopup_margin)-50);
	$("#"+innerformdiv).height(final_innerdiv_height);
	//set model pop up height and position
	if(flag=="tabs"){
		var total_modelpop_height = Number(final_innerdiv_height+45+50+70);
	}
	else{
		var total_modelpop_height = Number(final_innerdiv_height+45+50);
	}

	$( "#"+modelpopupdiv).dialog( "option","height",total_modelpop_height);
	$( "#"+modelpopupdiv).dialog( "option","position","[200,"+modelpopup_margin+"]");
}
var row_count=0;
function gridaltrow(gridid,rowid){
	// efefef
	var colModelcount = jQuery("#"+gridid).jqGrid ('getGridParam', 'colModel');
	if(row_count==0){
		row_count=1;
	}
	else{
		for(var i=0;i<colModelcount.length;i++){
			$("#"+gridid).setCell(rowid,i,'',{backgroundColor:'#efefef'});
		}
		row_count=0;
	}
}

function resizegrid(maindiv,griddiv,gridid,gridcapsonid,flag,nongridflag){
	var innerwidth = getinnerWidth();
	$("#"+maindiv).css('width',winW);
	if(nongridflag==null)nongridflag='';
	if(flag=="decrease"){

		 $("#"+griddiv).css('width',Number(innerwidth-43));
		 if(nongridflag!=""){
			 $("#"+gridcapsonid).css('width',Number(innerwidth-32));
			 $("#"+gridid).css('width',Number(innerwidth-32));
		 }
		 else{
			 $("#"+gridcapsonid).css('width',Number(innerwidth-31));
			 $("#"+gridid).setGridWidth(Number(innerwidth-33));
		 }
	}
	else if(flag=="increase"){
		 $("#"+griddiv).css('width',Number(innerwidth-211));
		 if(nongridflag!=""){
			 $("#"+gridcapsonid).css('width',Number(innerwidth-221));
			 $("#"+gridid).css('width',Number(innerwidth-221));

		 }
		 else{
			 $("#"+gridcapsonid).css('width',Number(innerwidth-219));
			 $("#"+gridid).setGridWidth(Number(innerwidth-221));
		 }
	}
}

function menucollapse(cdivid,ncdivid,griddiv,gridid,gridcapsonid,flag,nongriddiv){
	if(nongriddiv==null)nongriddiv="";
	if(flag=="collapse"){
		$("#"+cdivid).hide("slow",function() {
			if(nongriddiv!="")resizegrid("maindivparent",griddiv,gridid,gridcapsonid,"decrease",nongriddiv);
			else resizegrid("maindivparent",griddiv,gridid,gridcapsonid,"decrease");
			$("#"+ncdivid).show("slow");
		});
	}
	else if(flag=="expand"){
		$("#"+ncdivid).hide("slow",function() {
			if(nongriddiv!="")resizegrid("maindivparent",griddiv,gridid,gridcapsonid,"increase",nongriddiv);
			else resizegrid("maindivparent",griddiv,gridid,gridcapsonid,"increase");
		    $("#"+cdivid).show("slow");
		});
	}

}

function disabledbutton(btid){
	$('#'+btid).attr("disabled","disabled");
}

function enabledbutton(btid){
	$('#'+btid).attr("disabled", false);
}

function errortooltip(id,msg,msgbarid,flag){
	$("#"+id).css("background-color","#cc0000");
	var targ;
	var toltip;
		if(flag=="left"){
			targ="rightTop";
			toltip="leftTop"
		}
		else if(flag=="right"){
			targ="leftBottom";
			toltip="rightBottom"
		}
		if(!$('#'+id).qtip('api').destroy){
			$('#'+id).qtip({
			content:{
				text:msg
			},
			 position: {
				 corner: {
			         target: targ,
			         tooltip: toltip
			      }
			   },
			   show: { when: {target: $("#"+id),event:'focus'} },
			   hide: { when: {target: $("#"+id),event:'focusout'} },
			   style: {
				      width: 200,
				      background: '#ccc',
				      color: 'black',
				      textAlign: 'center',
				      border: {
				         width: 1,
				         radius: 1,
				         color: '#cc0000'
				      }
			   },
				name:'dark'
			});
	}
	else{
		$('#'+id).qtip('api').updateContent(msg,false);
	}

	displaymessage(msgbarid,"Validation Failed!Please corrrect all the information","error");
}
/*
 * Author:Maulik Desc:Function to validate input,Check wheter input value is
 * empty,numeric @param:id id of the HTML Form Element @param:flag if
 * flag=2,check for numeric validation only if flag=1,check for empty value and
 * numeric validation both if flag not passed do only empty value validation
 */

function validate(id,msgbarid,flag)
	{
		var x=document.getElementById(id);
		if(flag==2 && isNaN(x.value))
		{
			errortooltip(id,x.getAttribute("errortag") + " must be digit",msgbarid,document.getElementById(id).getAttribute('errortool'));
		}
		else if(flag!=2 && (x.value=="" || x.value==null))
		{
			errortooltip(id,x.getAttribute("errortag") + " can not be empty",msgbarid,document.getElementById(id).getAttribute('errortool'));
		}
		else if(flag==1 && isNaN(x.value) )
		{
			errortooltip(id,x.getAttribute("errortag") + " must be digit",msgbarid,document.getElementById(id).getAttribute('errortool'));
		}
		else{
			removeerror(id,msgbarid);
		}
	}

function removeerror(id){
	document.getElementById(id).style.display="none";
}

function displaymessage(msgid,msg,flag){
	if(flag==null)flag="";
	if(flag!=""){
		document.getElementById(msgid).innerHTML="<font color='red'>"+msg+"</font>";
	}
	else{
		document.getElementById(msgid).innerHTML=msg;
	}
    if(document.getElementById(msgid).style.display!="block"){
    	document.getElementById(msgid).style.display="block";
    }
}

function hidemessage(msgid){
	document.getElementById(msgid).style.display="none";
}
function getorder(ids,url_id,id,rateid){
	if(ids!=""){
                if(ids.indexOf("_")!="-1"){
                    var temp = ids.split("_");
                    id = id+"_"+temp[1];
                    rateid = rateid+"_"+temp[1];
                }
                var flag=ids.substr(0,3);

                if(flag=="Pro")flag="product";
                else if(flag=="Cat")flag="category";

               var val = document.getElementById(ids).value;
           $.ajax({
			type: "POST",
			url: url_id+'/client/populatecategory/'+val,
			data:"flag="+flag,
			success: function(response){

				if(response!=""){

					var myObject = eval('(' + response + ')');

					if(myObject.returnvalue=="valid"){
						//document.getElementById(id).value=myObject.categoryid;
						document.getElementById(rateid).value=myObject.rate;
						//document.getElementById(id).disabled=true;
					}
					else{
						jAlert(myObject.exceptionMessage)
					}
				}
			}
		});
	}
	else{
		//sdocument.getElementById(id).value="";
		document.getElementById(rateid).value="";
		//document.getElementById(id).disabled=false;
	}
}

function getproducts(ids,url_id,rateid){
	if(ids!=""){
		if(ids.indexOf("_")!="-1"){
			var temp = ids.split("_");
			var pro_id = "ProductId"+"_"+temp[1];
		}
		else{
			var pro_id = "ProductId";
		}
        var val = document.getElementById(ids).value;
        var e = document.getElementById(pro_id);
        if(val!=""){
	        $.ajax({
				type: "POST",
				url: url_id+'/client/populateproduct/'+val,
				success: function(response){
					if(response!=""){
						e.options.length=0;
						var myObject = eval('(' + response + ')');
						if(myObject.returnvalue=="valid"){
							myObject = myObject.data;
							var loop=0;
							for(var key in myObject){
								if(loop==0)var pid = myObject[key].id;
								e.options[loop] = new Option(myObject[key].name,myObject[key].id);
								loop++;
							}
							if(pid>0){
								getorder(ids,url_id,"CategoryId","Rate");
							}
						}
						else if(myObject.returnvalue=="invalid")
						{
							document.getElementById(rateid).value="";
						}
						else{
							jAlert(myObject.exceptionMessage)
						}
					}
				}
			});
        }
        else{
        	e.options.length=0;
        }
	}
}
function getcategory(val,url_id,id,rateid){
    if(val!=""){
            $.ajax({
                    type: "POST",
                    url: url_id+'/productcategory/populatecategory/'+val,
                    success: function(response){

                            if(response!=""){

                                    var myObject = eval('(' + response + ')');

                                    if(myObject.returnvalue=="valid"){
                                            document.getElementById(id).value=myObject.categoryid;
                                            document.getElementById(rateid).value=myObject.rate;
                                            document.getElementById(id).disabled=true;
                                    }
                                    else{
                                            jAlert(myObject.exceptionMessage)
                                    }
                            }
                    }
            });
        }
	else{
		document.getElementById(id).value="";
		document.getElementById(rateid).value="";
		document.getElementById(id).disabled=false;
	}
}


function changetemplate(templateid,url_id){
	if(document.getElementById(templateid).value=="")return false;
	var template_id = document.getElementById(templateid).value;
	jConfirm("Selecting this template will overwrite any data already entered within the email body. Do you wish to continue?","Confirmation",function(r){
		if(r){
			$.ajax({
				url:url_id+'/emailtemplates/gettemplate/'+template_id,
				type:'post',
				async:false,
				success: function(response){
					response = eval('('+response+')');
					CKEDITOR.instances.editor1.setData(response.body);
					document.getElementById("Subject").value =response.subject;
				},
				error: function(XMLHttpRequest,textStatus){
					jAlert("This Operation Could not be Completed. Please check your Internet Connection and try Again. If problem persists please contact Support");
				}
			});
		}
	});
}

function getcharcount(id){

	var txt = document.getElementById(id).value;
	document.getElementById("charactercount").innerHTML =txt.length;
}


function changesmstemplate(templateid,url_id){
	if(document.getElementById(templateid).value=="")return false;
	var template_id = document.getElementById(templateid).value;
	jConfirm("Selecting this template will overwrite any data already entered within the sms message. Do you wish to continue?","Confirmation",function(r){
		if(r){
			document.getElementById("smstemplateloading").innerHTML = messageload;
			$.ajax({
				url:url_id+'/smstemplates/gettemplate/'+template_id,
				type:'post',
				success: function(response){
					document.getElementById("smstemplateloading").innerHTML ="";
					document.getElementById("Message").value =response;
					getcharcount("Message");
				},
				error: function(XMLHttpRequest,textStatus){
					jAlert("This Operation Could not be Completed. Please check your Internet Connection and try Again. If problem persists please contact Support");
				}
			});
		}
	});
}

function defaulttimevalue(id,timevalue,msgbarid){
	var x = document.getElementById(id);
	if(timevalue==""){
		document.getElementById(id).value="0w 0d 0h 0m 0s";
	}
	else if(timevalue=="0w 0d 0h 0m 0s"){
		errortooltip(id,x.getAttribute("errortag") + " can not be empty",msgbarid,document.getElementById(id).getAttribute('errortool'));
	}
	else{
		removeerror(id,msgbarid,0);
	}
}
