	var sType	= 0; 
	var option	= 'FUT';
	var sPrice	= 0;
	var	eDate	= '';
	var strikePriceArray = new Array();

	var tradeType	= 1;
	var tradeAction	= 1;

            var arrReturn	= new Array();
            arrReturn[1]	= 2 ; 
            arrReturn[7]	= 4 ;
            arrReturn[14]	= 4 ;
            arrReturn[30]	= 5 ;
            arrReturn[90]	= 7 ;
            arrReturn[180]	= 8 ;
            arrReturn[365]	= 15 ;
            
            var derivativeReturn =  new Array();
            derivativeReturn[0]	= 5 ; 
            derivativeReturn[1]	= 7;
            derivativeReturn[2]	= 7 ;

	var msg1 = 'Please Login.';
	var msg5 = 'Please Select Company Name.';
	var msg7 = 'Please Select Trade Type.';
	var msg8 = 'Invalid Trade Type.';
	var msg9 = 'Please Enter Target Period.';
	var msg10 = 'Please Select Instrument.';
	var msg11 = 'Please Enter Valid Strike Price.';
	var msg12 = 'Please Select Expiry Date.';
	var msg13 = 'Please Enter Valid Target Price.';
	var msg14 = 'Please Enter Valid Stop Loss Price.';
	var msg15 = 'This Tip already exists.';
	var msg21 = 'No Input.';

	var msg25 = 'Stop Loss cannot be greater than Target Price';
	var msg26 = 'Stop Loss cannot be less than Target Price';

	var msg27 = 'Target Price should be greater than LTP';
	var msg28 = 'Target Price should be less than LTP';
	var msg29 = 'LTP not found, Could not submit tip, Please try again.';

	var msg31 = 'Target Price should be greater than ';
	var msg32 = 'Target Price should be less than ';

	var msg33 = 'Stop Loss should be less than Current Market Price';
	var msg34 = 'Stop Loss should be grater than Current Market Price';

	var msg41 = 'You Can Put Intraday Tip Before 3:00 PM Only.';
	var msg42 = 'You Can Put Intraday Tip On Trading Day Only.';

	var msg43 = 'Invalid Tip, Please check NSE CODE and Trade type.';

	var msgAddSuccess = 'Tip Added Successfully.';

	var action = 'add';
	var submitQuery		= '';

	var org_tradeAction	= '';
	var org_companyName	= '';
	var org_tipperName	= '';
	var org_targetPrice	= '';
	var org_targetPeriod 	= '';
	var org_instrument	= '';
	var org_strikePrice 	= '';
	var org_expiry		= '';

	var tipperId		= 1;
	var tipperName		= '';

	function validateData(){
		
		getEl('errorMsg').className	= 'mangoPeopleErrorMessageText';

		if( tipperId=='' || tipperId == 0 || tipperId == 'undefined'){
			getEl('errorMsg').innerHTML	= msg1;
			alert(msg1);
			sd('errorMsg');
			return false;
		}

		if(getEl('tip_action1').checked){
			tradeAction =  1 ;
		} else if(getEl('tip_action2').checked){
			tradeAction =  2 ;
		} else if(getEl('tip_action3').checked){
			tradeAction =  3 ;
		}

		org_tradeAction	= (tradeAction ==1)? 'BUY' : (tradeAction ==2)? 'SELL' : 'HOLD';
		var companyName		= getCompanyName();
		if(companyName==''){
			getEl('errorMsg').innerHTML	= msg5;
			sd('errorMsg');
			getEl('submit-tip-company').focus();
			return false;
		} else {
			org_companyName	= companyName;
		}

		var tradeTypeFlag = getEl('tip-instrument1').checked ;

		if(tradeTypeFlag) { 
			tradeType = 1 ;
		} else {
			tradeTypeFlag = getEl('tip-instrument2').checked ;
			if(tradeTypeFlag) { 
				tradeType = 2 ;
			}
		}

		var docTP = docSL = null;
		
		if(tradeType == 1){
			var	targetPeriod= trim(getEl('tip-stock-period').value);
			postText = "&targetPeriod="+targetPeriod ;
			x = getEl('tip-stock-period').selectedIndex;
			org_targetPeriod	= getEl('tip-stock-period').options[x].text;

			docTP	= document.fTip.submit_tip_price_eq;
			docSL	= document.fTip.submit_tip_stoploss_eq;

		} else if(tradeType == 2){
			var	instrument	= trim(getEl('tip-derivative-instrument').value);
			var	expiryDate	= trim(getEl('tip-derivative-expiry').value);

			x = getEl('tip-derivative-instrument').selectedIndex;
			org_instrument	= getEl('tip-derivative-instrument').options[x].text;

			x = getEl('tip-derivative-expiry').selectedIndex;
			org_expiry	= getEl('tip-derivative-expiry').options[x].text;

			postText = "&instrument="+instrument+"&expiry="+expiryDate;

			if(instrument == '2' || instrument == '3'){
				var	strikePrice	= trim(getEl('submit-strike-price').value);
				if(strikePrice=='' || strikePrice == 0 || !validNumber(strikePrice)){
					getEl('errorMsg').innerHTML	= msg11;
					sd('errorMsg');
					getEl('submit-strike-price').focus();
					return false;
				} else {
					org_strikePrice = strikePrice;
				}
				postText += "&strikePrice="+strikePrice;
			}

			docTP	= document.fTip.submit_tip_price_dr;
			docSL	= document.fTip.submit_tip_stoploss_dr;
		}

		
		var	targetPrice	= trim(docTP.value);
		var	stopLoss	= trim(docSL.value);

		if(targetPrice=='' || targetPrice == 0 || !validNumber(targetPrice) ){
				getEl('errorMsg').innerHTML	= msg13;
				sd('errorMsg');
				docTP.select();
				return false;
		}  else {
			org_targetPrice	= targetPrice;
			targetPrice		= parseFloat(targetPrice);
		}

		if( stopLoss != '' && (  !validNumber(stopLoss) || stopLoss < 0 ) ){
				getEl('errorMsg').innerHTML	= msg14;
				sd('errorMsg');
				docSL.select();
				return false;
		} else {
			stopLoss		=  parseFloat(stopLoss);
		}

		//getLTP();
		var LTP	=  trim(getEl('LTP').innerHTML);
		//LTP		= parseFloat(LTP);
		//var compareLTP=parseFloat((4 * LTP)/100);
		LTP		= parseFloat(LTP);
		/*if(tradeAction == 1 || tradeAction == 3)
		{
			LTP		= LTP+compareLTP;
		}
		else if(tradeAction == 2)
		{
			LTP		= LTP-compareLTP;
		}*/
		
		if( LTP > 0 ){
			if( ( tradeAction == 1 || tradeAction == 3 ) &&  targetPrice <= LTP ){
					getEl('errorMsg').innerHTM="";
					getEl('errorMsg').innerHTML	= msg27;
					sd('errorMsg');
					docTP.select();
					return false;

			} else if ( tradeAction == 2 && targetPrice >= LTP ){
					getEl('errorMsg').innerHTM="";
					getEl('errorMsg').innerHTML	= msg28;
					sd('errorMsg');
					docTP.select();
					return false;
			}
		}else {
			//alert(LTP);
			getEl('errorMsg').innerHTML	= msg29;
			sd('errorMsg');
			docTP.select();
			return false;
		}

		if( stopLoss !='' && ( tradeAction == 1 || tradeAction == 3 ) && ( targetPrice <= stopLoss )){
				getEl('errorMsg').innerHTML	= msg25;
				sd('errorMsg');
				docSL.select();
				return false;

		} else if ( stopLoss !='' && tradeAction == 2 && (targetPrice >= stopLoss) ){
				getEl('errorMsg').innerHTML	= msg26;
				sd('errorMsg');
				docSL.select();
				return false;
		}

		if( ( tradeAction == 1 || tradeAction == 3 ) &&  stopLoss >= LTP ){
			getEl('errorMsg').innerHTML	= msg33;
			sd('errorMsg');
			docSL.select();
			return false;

		} else if ( tradeAction == 2 && stopLoss <= LTP ){
			getEl('errorMsg').innerHTML	= msg34;
			sd('errorMsg');
			docSL.select();
			return false;
		}
                    
                    if(tradeType == 1){
                            var tipReturnPercent = arrReturn[targetPeriod];
                            if(tradeAction == 1 || tradeAction == 3 ){
                                var tVal	= 100 + tipReturnPercent;
                            } else if(tradeAction == 2){
                                var tVal	= 100 - tipReturnPercent;
                            }
                            var tipReturn	= (LTP * ( tVal )) / 100 ;
                            var pText	= tipReturnPercent + " % ";

                    }else if (tradeType == 2){
                              x = getEl('tip-derivative-expiry').selectedIndex;                              
                              var tipReturnPercent = derivativeReturn[x];                              
                            if(tradeAction == 1 || tradeAction == 3 ){
                                var tVal	= 100 + tipReturnPercent;
                            } else if(tradeAction == 2){
                                var tVal	= 100 - tipReturnPercent;
                            }
                            var tipReturn	= (LTP * ( tVal )) / 100 ;
                            var pText	= tipReturnPercent + " % ";
                    
                    }
                            if( ( tradeAction == 1 || tradeAction == 3 ) &&  targetPrice < tipReturn ){
                                    getEl('errorMsg').innerHTML	= msg31 + pText;
                                    sd('errorMsg');
                                    docTP.select();
                                    return false;

                            } else if ( tradeAction == 2 && targetPrice > tipReturn ){
                                    getEl('errorMsg').innerHTML	= msg32 + pText;
                                    sd('errorMsg');
                                    docTP.select();
                                    return false;
                            }
                   

		hd('errorMsg');
		var companyCode1	= getSymbolGeneric('#submit-tip-company');
		companyCode		= companyCode1.replace(/&/g,'-');
		var query = "action="+action+"&tradeAction="+tradeAction+"&companyCode="+companyCode+"&companyName="+companyName+"&tradeType="+tradeType+"&targetPrice="+targetPrice+"&stopLoss="+stopLoss + postText ;

		

		if(action=='add'){
			var uri	= siteURL  + '/tip/chkduplicate';
			$.ajax({
                    type : "POST",
                    url : uri ,
                    data : query,
                    dataType : "html",
                    success: function( data ) {
						iOp = parseInt(data);
						if(iOp == 0 ){
							tipSubmit(action);	
						}else{
							getEl('errorMsg').innerHTML	=  'Duplicate Tip.';
							sd('errorMsg');
						}
                    }
                });


			submitQuery = query;
		} else {
			getEl('errorMsg').innerHTML	= 'Action Not Defined';
		}
		return false;
	}

	function tipSubmit(tAction){
			
			if(tAction=='edit') tAction ='edit';
			var uri		 = siteURL + 'tip/'+ tAction ;
			$.ajax({
                    type : "POST",
                    url : uri ,
                    data : submitQuery,
                    dataType : "html",
                    success: function( data ) {
						ajaxAddReady(data)
                    }
                });

			return false;
	}

	function ajaxAddWaiting(xhrObj){}
	
	function ajaxAddReady(data){
		
		op = parseInt(data);
		getEl('errorMsg').className	= 'mangoPeopleErrorMessageText';
		sd('errorMsg');

		if(tradeType == 1){
			docTP	= document.fTip.submit_tip_price_eq;
			docSL	= document.fTip.submit_tip_stoploss_eq;
		} else if(tradeType == 2){
			docTP	= document.fTip.submit_tip_price_dr;
			docSL	= document.fTip.submit_tip_stoploss_dr;
		}

		if(op == -1 ){
			alert('Please login');
		} else if(op == -4 ){
			getEl('errorMsg').innerHTML	= msg4;
			getEl('tip_action1').focus();
		} else if(op == -5 ){
			getEl('errorMsg').innerHTML	= msg5;
			getEl('submit-tip-company').select();
		} else if(op == -6 ){
			getEl('errorMsg').innerHTML	= msg6;
			getEl('submit-tip-company').select();
		} else if(op == -7 ){
			getEl('errorMsg').innerHTML	= msg7;
			getEl('tip-instrument1').focus();
		} else if(op == -8 ){
			getEl('errorMsg').innerHTML	= msg8;
			getEl('tip-instrument1').focus();
		} else if(op == -9 ){
			getEl('errorMsg').innerHTML	= msg9;
			getEl('tip-stock-period').select();
		} else if(op == -10 ){
			getEl('errorMsg').innerHTML	= msg10;
			getEl('tip-derivative-instrument').focus();
		} else if(op == -11 ){
			getEl('errorMsg').innerHTML	= msg11;
			getEl('submit-strike-price').select();
		} else if(op == -12 ){
			getEl('errorMsg').innerHTML	= msg12;
			getEl('tip-derivative-expiry').focus();
		} else if(op == -13 ){
			getEl('errorMsg').innerHTML	= msg13;
			docTP.select();
		} else if(op == -14 ){
			getEl('errorMsg').innerHTML	= msg14;
			docSL.select();
		} else if(op == -15 ){
			getEl('errorMsg').innerHTML	= msg15;
			getEl('submit-tip-company').select();
		} else if(op == -16 ){
			window.location.href = siteURL + '/login';
		} else if(op == -21 ){
			getEl('errorMsg').innerHTML	= msg21;
			getEl('submit-tip-company').select();
		} else if(op == -29 ){
			getEl('errorMsg').innerHTML	= msg29;
		} else if(op == -41 ){
			getEl('errorMsg').innerHTML	= msg41;
		} else if(op == -42 ){
			getEl('errorMsg').innerHTML	= msg42;
		} else if(op == -43 ){
			getEl('errorMsg').innerHTML	= msg43;
		} else {
			getEl('errorMsg').className	= 'mangoPeopleNoticeMessageText';
			if( action=='add'){
				if(op > 1 ){					
					submitQuery = '';
					getEl('errorMsg').innerHTML	= '';
					var tipper_url=	siteURL+"profiles/"+getCookie("tuid"); //Tipper Profile URL
					var tipper_share_title_fb='I have just posted a '+org_tradeAction+' call for '+org_companyName+' on UTVmoney.com. Check';
                    var tipper_share_title='I have just posted a '+org_tradeAction+' call for '+org_companyName+' on UTVmoney.com. Check';
					var fburl = 'href="http://www.facebook.com/share.php?u='+encodeURIComponent(tipper_url)+'&t='+encodeURIComponent(tipper_share_title_fb)+'"';					
					var tipper_share_html='<div class="tip-share-container"><h2>Tip Added Successfully</h2><p>Share with your friends on </p><p><a rel="nofollow" '+fburl+' onclick="return fbs_click()" target="_blank"><img src="'+imageURL+'FaceBook_48x48.png" alt="Facebook"/></a><a href="http://twitter.com/home?status='+tipper_share_title+' '+tipper_url+'" title="Click to share on Twitter" onclick="return twitter_click()" target="_blank"><img src="'+imageURL+'Twitter_48x48.png" alt="Twitter"/></a></p><p><a onclick="continue_tip_submit()" class="medium-submit-button">Continue</a></p></div>';				
                    getEl('submit-tips-leadin').innerHTML = tipper_share_html;
                }
			} 
		}
	}
	function continue_tip_submit()
	{   var tipper_url=	siteURL+"profiles/"+getCookie("tuid"); //Tipper Profile URL
		window.location=tipper_url;
    }
        
	function fbs_click() {
		var tipper_url=	siteURL+"profiles/"+getCookie("tuid"); //Tipper Profile URL
		var tipper_share_title="Hi! I have just posted a tip on UTVmoney.";
		var tipper_share_title='I have just posted a '+org_tradeAction+' call for '+org_companyName+' on UTVmoney.com. Check';
		tipper_url_full = tipper_url+"/fb/"+org_tradeAction+"/"+org_companyName;		
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(tipper_url_full)+'&hpt='+encodeURIComponent(tipper_share_title),'sharer','toolbar=0,status=0,width=626,height=436');		
		window.location=tipper_url_full;	
		return false;
	}
	function twitter_click() {
		var tipper_url=	siteURL+"profiles/"+getCookie("tuid"); //Tipper Profile URL
		var tipper_share_title='Posted a '+org_tradeAction+' call for '+org_companyName+'. Check';
		window.open('http://twitter.com/home?status='+encodeURIComponent(tipper_share_title+' '+tipper_url));
		window.location=tipper_url;
		return false;
	}
	
	function ajaxWaiting(){}

	function getLTP_dr(){

		getLTP(sType);
		return false;
	}
	function getLTP(sType){
		symbol1		= getSymbolGeneric('#submit-tip-company');
		var tquery	= '';
		
		getEl('LTP').className='ltp_loading';
		
		symbol		= symbol1.replace(/&/g,'-');
		if(symbol!=''){
			if( sType > 0 ){
				tquery	= "&option="+option ;
				sPrice	= trim(getEl('submit-strike-price').value);
				if( ( sType == '2' || sType == '3' ) && sPrice == '') return false;
				eDate	= trim(getEl('tip-derivative-expiry').value);
				tquery	+= "&sPrice="+sPrice ;
				tquery	+= "&eDate="+eDate ;
			}
		}
		
		$.ajax({
				type : "GET",
				url : siteURL+'getLTP.php',
				data : "random="+Math.random()+"&source=cache&sType="+sType + "&symbol=" + symbol + tquery,
				dataType : "html",
				success: function( data ) {
						getEl('LTP').className='';
						getEl('LTP').innerHTML = data ;
				}
                });
		return false;
	}

	function getSymbolGeneric( div ){
		var tText = tipSymbol = false;
		var sym = $(div).val();
		if( sym.length > 1 ){
			 tText	= trim(sym);
			 var start	= tText.lastIndexOf('(');
			 start	+= 1;
			 var length	= tText.length -1 ;
			 symb		= tText.substring(start,length);			 		 
			 tipSymbol	= trim(symb);
		}    
		return tipSymbol;
	}

	function showEquity(){
		sType	= 0;
		getLTP();
	}

	function showDerivative(){
		chkInstrument();
	}

	function chkInstrument(){
		indx = getEl('tip-derivative-instrument').selectedIndex;
		if( indx == 0 ){
			option	= 'FUT';
			sType	= 1;
			hd("drStrike");
			
			getLTP_dr();
		} else if( indx == 1 ){
			option	= 'CA';
			sType	= 2;
	        sd("drStrike");
			showStrikePrice();
		} else if( indx == 2  ){
			option	= 'PA';
			sType	= 3;
	        sd("drStrike");
			showStrikePrice();
		}
	}

	function chkExp(){
		chkInstrument();
	}

	function refreshPage(){
		window.location.href = siteURL + '/';
	}

	function validNumber(num){
		op = /^\d+(\.\d+)?$/.test(num);
		if ( op ) return true ; else return false;
	}



	function showStrikePrice(){
		var symbol		= getSymbolGeneric('#submit-tip-company');
		var instrument	= $('#tip-derivative-instrument').val();
		var expdate		= $('#tip-derivative-expiry').val();
		if(instrument==2){
			instrument	= 'CA';
		}else if(instrument==3){
			instrument	= 'PA';
		}
        
        query	= 'type=sp&symbol='+symbol+ "&instrument=" + instrument+'&expdate='+expdate+"&rand=" +Math.random();
	
		sd('indicator');
		sd('indicator1');

		$.ajax({
				type : "GET",
				url : siteURL+'ajaxStrikeInfo.php',
				data : query,
				dataType : "html",
				success: function( data ) {
					var tArr = data.split('|');
					strikePriceArray = tArr[1].split(',');
					$('#submit-strike-price').html(tArr[0]) ;
					hd('indicator1');
					setLTP();
				}
         });

	}

	function setLTP(){
		var idx = getEl('submit-strike-price').selectedIndex ;
		if(typeof(strikePriceArray[idx])!='undefined'){
			getEl('LTP').innerHTML = strikePriceArray[idx];
		}else{
			getEl('LTP').innerHTML = "";
		}
		hd('indicator');
	}

