/******************************************
Function name : getMasterString
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string
User instruction : getMasterString()
******************************************/
function getMasterString()
{
	return "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n";
}


/******************************************
Module name : Js Function file
Parent module : None
Date created : 
Date last modified : 
Author :  
Last modified by : 
Comments : The functions_js.js file contains various functions related to the web directory project.
******************************************/	


function SubmitOLXForm()
{
	document.forms.frmXMLCreateForm.action = "OLX_XML_Gen_action.php";
	document.forms.frmXMLCreateForm.submit();	
}

function SubmitVastForm()
{
	document.forms.frmXMLCreateForm.action = "Vast_XML_Gen_action.php";
	document.forms.frmXMLCreateForm.submit();	
}

//////////PR 2///////////////


/******************************************
Function name : validateCouponTemplateUpload
Return type : boolean
Date created : 
Date last modified : 
Author : 
Last modified by : 
Comments : Function will return the true or error message after validation
User instruction : validateCouponTemplateUpload(formname)
******************************************/
function validateCouponTemplateUpload(formname) 
{ 
	var i,errors='',args=validateForm.arguments; 
	
			///Template Title checking
			varTemplateTitle = trim(document.forms["frmCouponTempUp"].elements["frmTempTitle"].value);
			if(varTemplateTitle.length==0){
			errors += '- '+' Template Title is required.\n'; 
			}
				     
			///Service Name checking
			varServiceName = trim(document.forms["frmCouponTempUp"].elements["frmServiceName"].value);
			if(varServiceName.length==0){
			errors += '- '+' Service Name is required.\n'; 
			}
			
			///DIscount value checking
			varDiscVal = trim(document.forms["frmCouponTempUp"].elements["frmDiscountValue"].value);
			if(varDiscVal.length==0){
			errors += '- '+' Discount value is required.\n'; 
			}
			
			///Station Name checking
			varStationName = trim(document.forms["frmCouponTempUp"].elements["frmStationName"].value);
			if(varStationName.length==0){
			errors += '- '+' Station Name is required.\n'; 
			}
			
			///Station Name checking
			varCouponExpiry = trim(document.forms["frmCouponTempUp"].elements["frmExpiryDate"].value);
			if(varCouponExpiry.length==0){
			errors += '- '+' Coupon Expiry date is required.\n'; 
			}
			
			///Disclaimer checking
			varDisclaimer = trim(document.forms["frmCouponTempUp"].elements["frmDisclaimer"].value);
			if(varDisclaimer.length==0 && varDisclaimer.length<=25){
			errors += '- '+' Disclaimer required atleast 25 Characters.\n'; 
			}
			
			
if (errors)
{
var MasterString = getMasterString();
alert(MasterString+'\n'+errors);
//focusitem.focus();
return false;
}
else
return true;
				
				
}
				
				
				
////////////////////				

function user_template_image_attempt(item)
{
	if(item == 'Valid')
	{		
		window.location.reload();
	}
	//else //if(item == 'Invalid')
	//{
	//	document.getElementById('spanMsg').innerHTML = 'In Valid';
	//}
}


function usercoupontemplateimage(stationid,temptitle,servicename, discount, stationname, expirydate, disclaimer,tempimgname)
{	 
	 var QryStr = "stationids="+stationid+"&templatetitles="+temptitle+"&servicenames="+servicename+"&discounts="+discount+"&stationnames="+stationname+"&expdate="+expirydate+"&disclaimers="+disclaimer+"&tempimg="+tempimgname;
	 doAjax('coupon_user_template_act.php',QryStr,'user_template_image_attempt','get','2');
}

function setTemplateImage(imgID)
{
	document.getElementById('spanCouponTempImg').innerHTML = '<img src="common/coupon_templates_prundo/Template-'+ imgID +'.gif" height="100" width="100" />';
}

/******************************************
Function name : validateFormCheckValues
Return type : boolean
Date created : 
Date last modified : 
Author : 
Last modified by : 
Comments : Function will check the coupon template manage form check boxes
User instruction : validateFormCheckValues(formname)
******************************************/
function validateFormCheckValues(formname)
{
	var errors='';
	var varCheckedTemplatesID="";
	
		for(var i=0;i<document.forms["frmCouponTempManage"]["frmCouponTempId[]"].length;i++)
		{
			if(document.forms["frmCouponTempManage"]["frmCouponTempId[]"][i].checked)
			{
				varCheckedTemplatesID +=document.forms["frmCouponTempManage"]["frmCouponTempId[]"][i].value + ",";
			}
		}
		
		if(varCheckedTemplatesID.length==0){ errors += '- '+' Select atleast one template to delete.\n'; }
		
if(errors)
{
var MasterString = getMasterString();
alert(MasterString+'\n'+errors);
return false;
}
else
{
//alert('hasabs');
return true;
}


}




/*****************************
Function name : getUserZipCouponsAvailable
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function to get the user's zip services count
User instruction : getUserZipCouponsAvailable(varZip)
************************************/	   
function getUserZipCouponsAvailable()
{
	 //var userZip = document.getElementById('frmNewLocation').value;
     //var QryStr = "userzip="+userZip;
	 //doAjax('coupons.availability.inc.php',QryStr,'displayUserZipCouponsAvailable','get','2');
	 
	 	var userZip = document.getElementById('frmNewLocation').value;
		
		document.getElementById('zip').value=userZip;
		
		$("#spnUserSelectedCity").load("cityname.byzip.inc.php?userzip="+userZip);	 
		 
		 // Put an animated GIF image inside of content
	 //$("#true").empty().html('<img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:60px; margin-left:100px;"/>'); //div id named content
	// $("#true").load("coupons.availability.inc.php?userzip="+userZip);
	 //$("#spnUserSelectedCity").load("cityname.byzip.inc.php?userzip="+userZip);
	 
	// $("#true").empty().html('<img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:60px; margin-left:100px;"/>'); //div id named content
	 $("#true").empty().html('<DIV><DIV><img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:30px; margin-left:100px;"/></DIV><DIV><P style="text-align:center; margin-right:135px; font-size:10px;">Loading Coupons</P></DIV></DIV>'); //div id named content
	 $("#true").load("coupons.availability.inc.php?userzip="+userZip);
	 //$("#spnUserSelectedCity").load("cityname.byzip.inc.php?userzip="+userZip);	 	 
	 
	 	$().ajaxSend(function(r,s){  
		$("#true").show();  
		});  
		  
		$().ajaxStop(function(r,s){  
		$("#true").fadeIn("slow");  
		});  

}
/*****************************
Function name : displayUserZipCouponsAvailable
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function ao get the user's zip services count list
User instruction : displayUserZipCouponsAvailable(responsetext)
************************************/
function displayUserZipCouponsAvailable(item)
 {
	document.getElementById('true').innerHTML = item;
 }
 
 
 /*****************************
Function name : getUserZipScrollingCoupons
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function to get the user's zip services count
User instruction : getUserZipScrollingCoupons(varZip)
************************************/	   
function getUserZipScrollingCoupons()
{
		var $container			= $('#slider .scrollContainer');
		$container
			.css('left', "10px");

	 	$("#true1").empty().html('<DIV style="padding-top:100px; padding-left:220px; text-align:center; border: solid 0px #000000; width:250px;"><DIV style="border: solid 0px #000000;"><img src="common/images/ajax-loader2.gif"  /></DIV><DIV><P style="text-align:center; font-size:10px;">Loading Coupons</P></DIV></DIV>'); //div id named content
		$("#true1").load("coupons.scroll.inc.php");	 
	 
  	  
	 	$().ajaxSend(function(r,s){  
		$("#true1").show();  
		});  
		  
		$().ajaxStop(function(r,s){  
		$("#true1").fadeIn("slow");  
		});  
 
 		//$.curPanel=3;
		
 
}
/*****************************
Function name : displayUserZipScrollingCoupons
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function ao get the user's zip services count list
User instruction : displayUserZipScrollingCoupons(responsetext)
************************************/
function displayUserZipScrollingCoupons(item)
 {
 //	document.getElementById('true1').innerHTML = '';	
	document.getElementById('true1').innerHTML = item;
 }










/////////////////////////

/*****************************
Function name : addNewServicesforStation
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function to add New Service for a station
User instruction : getUserZipCouponsAvailable(varZip)
************************************/	   
/*
function addNewServicesforStation()
{
	 //var userZip = document.getElementById('frmNewLocation').value;
	 // Put an animated GIF image inside of content
	 $("#addServices").empty().html('<img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:60px; margin-left:100px;"/>'); //div id named content
	 $("#addServices").load("station_services_add.inc.php");
	 
	 	$().ajaxSend(function(r,s){  
		$("#true").show();  
		});  
		  
		$().ajaxStop(function(r,s){  
		$("#true").fadeIn("slow");  
		});  

}
*/

function addNewServicesforStation(action)
{
	 //var action = document.getElementById('frmNewLocation').value;
	 // Put an animated GIF image inside of content
	 $("#addServices").empty().html('<img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:60px; margin-left:100px;"/>'); //div id named content
	 $("#addServices").load("station_services_add.inc.php?act="+action);
	 
	 	$().ajaxSend(function(r,s){  
		$("#true").show();  
		});  
		  
		$().ajaxStop(function(r,s){  
		$("#true").fadeIn("slow");  
		});  

}


function editServicesforStation(action,serviceid)
{
	 //var action = document.getElementById('frmNewLocation').value;
	 // Put an animated GIF image inside of content
	 $("#addServices").empty().html('<img src="common/images/ajax-loader2.gif"  style="text-align:center; margin-top:60px; margin-left:100px;"/>'); //div id named content
	 $("#addServices").load("station_services_add.inc.php?act="+action+"&ServiceID="+serviceid);
	 
	 	$().ajaxSend(function(r,s){  
		$("#true").show();  
		});  
		  
		$().ajaxStop(function(r,s){  
		$("#true").fadeIn("slow");  
		});  

}


/******************************************
Function name : validateCouponTemplateUpload
Return type : boolean
Date created : 
Date last modified : 
Author : 
Last modified by : 
Comments : Function will return the true or error message after validation
User instruction : validateCouponTemplateUpload(formname)
******************************************/
function validateStationServicesAdd(formname) 
{ 
	var i,errors='',args=validateForm.arguments; 
	
			///Service Name checking
			varServiceName = trim(document.forms["frmAddServices"].elements["frmService"].value);
			if(varServiceName.length==0){
			errors += '- '+'Select a Service is required.\n'; 
			}
				     
			///Service Charge checking
			varServiceCharge = trim(document.forms["frmAddServices"].elements["frmServiceCharge"].value);
			if(varServiceCharge.length==0)
			{
				errors += '- '+' Service Charge is required.\n'; 
			}
			else
			{
				if(isNaN(varServiceCharge))
				{
				errors += '- '+' Service Charge should be numeric value.\n'; 
				}
				if(varServiceCharge==0)
				{
				errors += '- '+' Service Charge should not be zero.\n'; 
				}
			}
			
			///DIscount value checking
			varDiscVal = trim(document.forms["frmAddServices"].elements["frmServiceDiscount"].value);
			if(varDiscVal.length==0)
			{
				errors += '- '+' Discount value is required.\n'; 
			}
			else
			{
				if(isNaN(varDiscVal))
				{
					errors += '- '+' Discount value should be numeric value.\n'; 
				}
			}
			
			
			   for (var i=0; i < document.frmAddServices.frmServiceDiscType.length; i++)
			   {
				   if (document.frmAddServices.frmServiceDiscType[i].checked)
					  {
					  	var varDiscTypeVal = document.frmAddServices.frmServiceDiscType[i].value;
					  }
			   }
			   
			    if(varDiscTypeVal!='Flat' && varDiscTypeVal!='Percent' && varDiscTypeVal!='Final')
				{
					errors += '- '+' Select one discount type.\n'; 
				}
			   
			   if(varServiceCharge>0 && varDiscVal>0 && varDiscTypeVal=='Flat')
				{
					if(parseFloat(varServiceCharge)<=parseFloat(varDiscVal))
					{
						errors += '- '+' Discount value should be less than regular price.\n'; 
						//errors += '- '+' Discount value should be less than regular price ' + varServiceCharge + ', ' + varDiscVal + '.\n'; 
					}
				}
				
				if(varServiceCharge>0 && varDiscVal>0 && varDiscTypeVal=='Percent')
				{
					if(parseFloat(varDiscVal)>=100)
					{
						errors += '- '+' Discount Percent should be less than 100.\n'; 
					}
				}
				
				if(varServiceCharge>0 && varDiscVal>0 && varDiscTypeVal=='Final')
				{
					if(parseFloat(varDiscVal)>=parseFloat(varServiceCharge))
					{
						errors += '- '+' Final Price value should be less than regular price.\n'; 
					}
				}

				//errors += '- '+' Discount Type ' + varDiscTypeVal + '.\n'; 
			
			
if (errors)
{
var MasterString = getMasterString();
alert(MasterString+'\n'+errors);
return false;
}
else
return true;
				
				
}
	
	
/////////////	
	

function changeDiscountHeading(value)
{
	if(value=="Flat" || value=="Percent")
	{
		$("#frmSpanDisccountHead").empty().html('Discount');
	}
	else
	{
		$("#frmSpanDisccountHead").empty().html('Final Price');
	}

}

////////////		

function hideServicesWindow() 
{
	//$("#btnServicesReset").click(function(){
		$("#divAddStationServices").toggle();
	//});
}







//////////////////////


/******************************************
Function name : validateCouponAddTemplate
Return type : boolean
Date created : 
Date last modified : 
Author : 
Last modified by : 
Comments : Function will return the true or error message after validation
User instruction : validateCouponAddTemplate(formname)
******************************************/
function validateCouponAddTemplate(formname) 
{ 
	var i,errors=''; 
	
			///Coupon Name checking
			varCouponName = trim(document.forms["frmAddCouponTemplate"].elements["frmTempTitle"].value);
			if(varCouponName.length==0){
			errors += '- '+' Coupon Name is required.\n'; 
			}
			
			///Station Name checking
			varStationName = trim(document.forms["frmAddCouponTemplate"].elements["frmStationName"].value);
			if(varStationName.length==0){
			errors += '- '+' Station Name is required.\n'; 
			}
			
			///Discount checking
			varDiscount = trim(document.forms["frmAddCouponTemplate"].elements["frmDiscountValue"].value);
			if(varDiscount.length==0){
			errors += '- '+' Discount is required.\n'; 
			}
			else
			{
				if(isNaN(varDiscount))
				{
					errors += '- '+' Discount value should be numeric value.\n'; 
				}
			}
			
			///Service Names (combo) in Station checking
			varServiceName = trim(document.forms["frmAddCouponTemplate"].elements["frmCouponService"].value);
			if(varServiceName.length==0){
			errors += '- '+' Select a Service.\n'; 
			}
			
			///Service Names (textbox) checking
			varServiceNameText = trim(document.forms["frmAddCouponTemplate"].elements["frmServiceName"].value);
			if(varServiceNameText.length==0){
			errors += '- '+' Service Name is required.\n'; 
			}
			
			///Coupon Expiry checking
			varCouponExpiry = trim(document.forms["frmAddCouponTemplate"].elements["frmExpiryDate"].value);
			if(varCouponExpiry.length==0){
			errors += '- '+' Coupon Expiry is required.\n'; 
			}
			
			if(validateCouponExpiryDate(varCouponExpiry)==false)
			{
				errors+='- Expiry date should be greater than current date.\n';
			}
			
			//errors += '- '+validateCouponExpiryDate(varCouponExpiry) + ' ss.\n'; 
			
			
if (errors)
{
var MasterString = getMasterString();
alert(MasterString+'\n'+errors);
return false;
}
else
return true;
				
				
}


/******************************************
Function name : validateCouponExpiryDate
Return type : boolean
Date created : 
Date last modified : 
Author : 
Last modified by : 
Comments : Function will return the true or error message after validation
User instruction : validateCouponAddTemplate(formname)
******************************************/
function validateCouponExpiryDate(val) 
{ 
		p=val.indexOf('-');
		var sliptdate	= val.split("-");
		
		/*******************get current date and month*********************/
		var today=new Date(),TY=today.getFullYear(),TM=today.getMonth(),TD=today.getDate(),TH=today.getHours();
		TM+=1;			
		if(TM<=9) 
		{	
			TM='0'+TM;
		}
		if(TD<=9)
		{
			TD='0'+TD;
		}
		/*******************Get Expiry Date*********************/
		
		var sY=sliptdate[0];
		var sM=sliptdate[1];
		var sD=sliptdate[2];
		
		/*******************Check Date*********************/
		//alert(TM);
		if(sY<TY ) {
			
			//errors+='- '+nm+' should be greater than current date.\n';
			return false;
		}
		else if(sM==TM && sD<TD && sY==TY) { 

			//errors+='- '+nm+' should be greater than current date.\n';
			return false;
			
		}
		else if(sM<TM && sY==TY) { 

			//errors+='- '+nm+' should be greater than current date.\n';
			return false;
			
		}
		else
		{
			return true;
		}

}













/*****************************
Function name : checkPromotioncode
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function 
User instruction : checkPromotioncode(frmServiceRegistration)
************************************/	   
function checkPromotioncode(frmServiceRegistration)
{
	 var varPcode = document.getElementById('frmPromocode').value;
	   for (var i=0; i < document.frmServiceRegistration2.frmSubscriptionTypeID.length; i++)
	   {
		   if (document.frmServiceRegistration2.frmSubscriptionTypeID[i].checked)
			  {
				var varScode = document.frmServiceRegistration2.frmSubscriptionTypeID[i].value;
			  }
	   }
     var QryStr = "promocode="+varPcode+"&substype="+varScode;
	 doAjax('ajax_act.php',QryStr,'addPromotionMessage','get','2');
}	
/*****************************
Function name : addPromotionMessage
Return type : 
Date created : 
Date last modified :  
Author : 
Last modified by :
Comments : This function is used to call ajax function 
User instruction : addPromotionMessage(CategoryValue)
************************************/
function addPromotionMessage(item)
 {
	document.getElementById('promo').innerHTML = item;
	document.getElementById('frmPromocode').focus();
	//document.getElementById('promo').focus();
	return false;
 }