package ads

import (
	"alpha/adDelivery/structure"
	"database/sql"
	"fmt"
	"log"
	"strconv"
	"strings"

	"alpha/adDelivery/helper"
	config "alpha/configuration"

	"alpha/db"
	"crypto/md5"
	"encoding/hex"
	"path"
)

func VideoAdRender(adDetails *AdDetails, zn structure.ZoneDetails) {
	var clickurl string
	impurl := config.GetConfig("protocol", "webpath") + config.GetConfig("delivery", "webpath") + "/lg.php?bannerid=" + strconv.Itoa(adDetails.Ad_id) + "&campaignid=" + strconv.Itoa(adDetails.Placement_id) + "&zoneid=" + strconv.Itoa(zn.Zoneid)
	table_prefix := config.GetConfig("prefix", "table")

	var sitCat_table = "djax_site_categories"
	var client_table = table_prefix + "clients"
	var campaign_table = table_prefix + "campaigns"
	var impression, pricingtype, skip, skip_progress_duration, adVerifications, Is_conditionalad, url_1, url_2, viewableImpression, trackingUrl, iabcategory, adservingid, advertiser, expiretime string
	fc_path := config.GetConfig("protocol", "webpath") + config.GetConfig("root", "webpath") + "/fc.php"

	vidad := VideoAd{}

	adid_str := strconv.Itoa(adDetails.Ad_id)

	redisClients.GetKey("advast"+adid_str, &vidad)

	if vidad.Banner_vast_element_id == 0 {

		fmt.Println("Getting vast elements from mysql")
		DbQuery := "SELECT * from " + table_prefix + "djaxbanner_vast_element where banner_id = %d"
		DbQuery = fmt.Sprintf(DbQuery, adDetails.Ad_id)

		adVast := db.DbQueryRow(DbQuery)
		err := adVast.Scan(&vidad.Banner_vast_element_id, &vidad.Banner_id, &vidad.Vast_element_type, &vidad.Vast_video_id, &vidad.Vast_type, &vidad.Vast_video_duration, &vidad.Vast_video_delivery, &vidad.Get_third_internal_type, &vidad.Vast_video_type, &vidad.Vast_video_bitrate, &vidad.Vast_net_connection_url, &vidad.Vast_video_filename, &vidad.Vast_video_height, &vidad.Vast_video_width, &vidad.Vast_video_outgoing_filename, &vidad.Vast_companion_banner_id, &vidad.Vast_overlay_height, &vidad.Vast_overlay_width, &vidad.Vast_video_clickthrough_url, &vidad.Vast_overlay_action, &vidad.Vast_overlay_format, &vidad.Vast_overlay_text_title, &vidad.Vast_overlay_text_description, &vidad.Vast_overlay_text_call, &vidad.Vast_creative_type, &vidad.Vast_thirdparty_impression, &vidad.Vast_wrapper_url, &vidad.Vast_version, &vidad.Vast_overlay_wrapper, &vidad.Vast_overlay_version, &vidad.Vast_video_skip_duration, &vidad.Vast_video_skip_progress_duration, &vidad.Vast_thirdparty_clicktracking, &vidad.Vast_thirdparty_clickcustom, &vidad.Vast_overlay_expanded_width, &vidad.Vast_overlay_expanded_height, &vidad.Vast_thirdparty_companion_expandedwidth, &vidad.Vast_thirdparty_companion_expandedheight, &vidad.Vast_thirdparty_companion_clicktracking, &vidad.Vast_overlay_expandedminduration, &vidad.Vast_wrapper_followadditional, &vidad.Vast_wrapper_allowmultipleads, &vidad.Vast_wrapper_fallbacknoads, &vidad.Vast_thirdparty_companion_assetwidth, &vidad.Vast_thirdparty_companion_assetheight, &vidad.Vast_thirdparty_companion_pxratio, &vidad.Vast_thirdparty_companion_alttext, &vidad.Vast4_min_bitrate, &vidad.Vast4_max_bitrate, &vidad.Vast4_verificationurl2, &vidad.Vast4_verificationurl1, &vidad.Vast4_adverificationtype2, &vidad.Vast4_adverificationtype1, &vidad.Is_conditionalad, &vidad.Vast_icon_filename, &vidad.Vast_icon_height, &vidad.Vast_icon_width, &vidad.Vast_icon_xposition, &vidad.Vast_icon_yposition, &vidad.Vast_icon_duration, &vidad.Vast_icon_offset, &vidad.Icon_click_url, &vidad.Icon_track_url, &vidad.Iabcategory, &vidad.Vast_video_outgoing_filename1, &vidad.Vast_video_type_1, &vidad.Vast_video_bitrate_1, &vidad.Vast_video_outgoing_filename2, &vidad.Vast_video_type_2, &vidad.Vast_video_bitrate_2, &vidad.Ad_type, &vidad.Audio_type, &vidad.Interactive_mediafile, &vidad.Is_mezzininefile, &vidad.Mezzanine_en, &vidad.Internal_file, &vidad.Url_file, &vidad.Vast_4_1_url, &vidad.Vast_4_1_type_file, &vidad.Vast_4_1_language, &vidad.Vast_4_1_url_1, &vidad.Vast_4_1_type_file_1, &vidad.Vast_4_1_language_1, &vidad.Vast_4_1_url_2, &vidad.Vast_4_1_type_file_2, &vidad.Vast_4_1_language_2, &vidad.Blocked_category, &vidad.Vid_upload_type)
		if err != nil {
			if err == sql.ErrNoRows {
				fmt.Println("No rows found.")
			} else {
				log.Fatal(err)
			}
		}
		redisClients.SetKey("advast"+adid_str, vidad)
	} else {
		fmt.Println("Getting vast elements from redis")
	}

	if vidad.Vast_video_clickthrough_url.String != "" {
		clickurl = config.GetConfig("protocol", "webpath") + config.GetConfig("delivery", "webpath") + "/cl.php?oaparams=2&bannerid=" + strconv.Itoa(adDetails.Ad_id) + "&zoneid=" + strconv.Itoa(zn.Zoneid) + "___oadest=" + vidad.Vast_video_clickthrough_url.String
	} else {
		clickurl = ""
	}

	trackingUrl = fc_path + "?script=rmvideoAds:rmvastEvent&bannerid=" + strconv.Itoa(vidad.Banner_id) + "&zoneid=" + strconv.Itoa(zn.Zoneid)
	adservingid = helper.RandToken(5) + strconv.Itoa(vidad.Banner_id)
	hasher := md5.New()
	hasher.Write([]byte(adservingid))
	adservingid = hex.EncodeToString(hasher.Sum(nil))

	/*Advertiser*/
	type Advertiser struct {
		Clientid   int
		Clientname string
		Clientexp  sql.NullString
		Revenue    float64
	}
	adv := Advertiser{}

	Placement_id_str := strconv.Itoa(adDetails.Placement_id)
	redisClients.GetKey("client_"+Placement_id_str, &adv)

	if adv.Clientid == 0 {
		err := db.DbQueryRow("select cl.clientid as clientid,cl.clientname as name,c.expire_time as expire_time,c.revenue as revenue from "+client_table+" as cl,"+campaign_table+" as c where c.clientid=cl.clientid and c.campaignid=?", adDetails.Placement_id).Scan(&adv.Clientid, &adv.Clientname, &adv.Clientexp, &adv.Revenue)

		if err != nil {
			if err == sql.ErrNoRows {
				fmt.Println("No rows found.")
			} else {
				log.Fatal(err)
			}
		}

		fmt.Println("select cl.clientid as clientid,cl.clientname as name,c.expire_time as expire_time,c.revenue as revenue from "+client_table+" as cl,"+campaign_table+" as c where c.clientid=cl.clientid and c.campaignid=?", adDetails.Placement_id)

		redisClients.SetKey("client_"+Placement_id_str, &adv)
		fmt.Println("75", adv)
	} else {
		fmt.Println("77")
	}

	advertiser = `<Advertiser id="` + strconv.Itoa(adv.Clientid) + `">` + adv.Clientname + `</Advertiser>`
	/*Advertiser*/
	/*Expires*/
	if adv.Clientexp.String != "" {
		fmt.Println("104")
		expiretime = `<Expires>` + adv.Clientexp.String + `</Expires>`
	}
	/*Expires*/
	/*Impression*/
	impression = `<Impression><![CDATA[` + impurl + `]]></Impression>`
	if vidad.Vast_thirdparty_impression != "" {
		impression += `<Impression><![CDATA[` + vidad.Vast_thirdparty_impression + `]]></Impression>`
	}
	/*Impression*/
	/*Adverification for Vast4*/
	if vidad.Vast4_verificationurl1.String != "" || vidad.Vast4_verificationurl2.String != "" {
		if vidad.Vast4_verificationurl1.String == "1" {
			url_1 = `<Verification>
						<JavaScriptResource>
						<![CDATA[` + vidad.Vast4_verificationurl1.String + `]]>
						</JavaScriptResource>
					</Verification>`
		} else if vidad.Vast4_verificationurl1.String == "2" {
			url_1 = `<Verification>
						<FlashResource>
						<![CDATA[` + vidad.Vast4_verificationurl1.String + `]]>
						</FlashResource>
					</Verification>`
		}
		if vidad.Vast4_verificationurl2.String == "1" {
			url_2 = `<Verification>
							<JavaScriptResource>
							<![CDATA[` + vidad.Vast4_verificationurl2.String + `]]>
							</JavaScriptResource>
						</Verification>`
		} else if vidad.Vast4_verificationurl2.String == "2" {
			url_2 = `<Verification>
							<FlashResource>
							<![CDATA[` + vidad.Vast4_verificationurl2.String + `]]>
							</FlashResource>
						</Verification>`
		}
		if url_1 != "" || url_2 != "" {
			adVerifications = `<AdVerifications>
								` + url_1 + `
								` + url_2 + `
							</AdVerifications>`
		}
	}
	/*Adverification for Vast4*/

	/*Viewable Impression*/
	viewableImpression = `<ViewableImpression id="` + strconv.Itoa(helper.RandNumber(10)) + `">
								<Viewable><![CDATA[` + trackingUrl + `&event=viewable]]></Viewable>
								<NotViewable><![CDATA[` + trackingUrl + `&event=notviewable]]></NotViewable>
								<ViewUndetermined><![CDATA[` + trackingUrl + `&event=viewundetermined]]></ViewUndetermined>
							</ViewableImpression>`
	/*Viewable Impression*/

	/*IAB Category in vast response*/
	if vidad.Iabcategory.String != "" {
		category := strings.Split(vidad.Iabcategory.String, ",")
		for _, v := range category {
			var cname string
			redisClients.GetKey("iabcategory"+v, &cname)

			if cname == "" {
				db.DbQueryRow("SELECT category_name FROM `" + sitCat_table + "` where value = '" + v + "'").Scan(&cname)

				redisClients.SetKey("iabcategory"+v, &cname)
				fmt.Println("sitecat table name", v)
				iabcategory += `<Category authority='http://www.iabtechlab.com/categoryauthority'><![CDATA[` + cname + `]]></Category>`
			}
		}
	}
	/*IAB Category in vast response*/

	/* Pricingtype */
	/* if vidad.Revenue_type == 1 {
		pricingtype = "CPM"
	} else if vidad.Revenue_type == 2 {
		pricingtype = "CPC"
	} else if vidad.Revenue_type == 3 {
		pricingtype = "CPA"
	} */
	pricingtype = "CPM"
	/* Pricingtype */

	/*Is_conditionalad*/
	if vidad.Is_conditionalad == 1 {
		Is_conditionalad = "true"
	} else {
		Is_conditionalad = "false"
	}
	/*Is_conditionalad*/
	/*Skip*/
	if vidad.Vast_video_skip_duration.String != "" {
		skip = `skipoffset="` + vidad.Vast_video_skip_duration.String + `"`
	}
	/*Skip*/
	/*Skip Progress*/
	if vidad.Vast_video_skip_progress_duration.String != "" {
		skip_progress_duration = `offset="` + vidad.Vast_video_skip_progress_duration.String + `"`
	} else {
		skip_progress_duration = ""
	}
	/*Skip Progress*/
	if adDetails.Width == -3 && adDetails.Height == -3 {

		var mediafile, mediafile1, mediafile2, maxbitrate, minbitrate, videoClickstrackVast, videocustomClicksVast, videoClicksVast, interactivemediafile, Mezzaninefile, icon, icontype1, resource, iprog, pricing, adType, closedcaption, closedcaption2, closedcaption3, type1, type2, type3, lang, lang1, lang2, companions, companionresource, companionclicks, companionassetheight, companionassetwidth, companionexpandedheight, companionexpandedwidth string

		/*<Clickthrough_url>*/
		if vidad.Vast_video_clickthrough_url.String != "" {
			if vidad.Vast_thirdparty_clicktracking.String != "" {
				videoClickstrackVast = `<ClickTracking><![CDATA[` + vidad.Vast_thirdparty_clicktracking.String + `]]></ClickTracking>`
			}
			if vidad.Vast_thirdparty_clickcustom.String != "" {
				videocustomClicksVast = `<CustomClick><![CDATA[` + vidad.Vast_thirdparty_clickcustom.String + `]]></CustomClick >`
			}
			if clickurl != "" {
				videoClicksVast = `<VideoClicks>
									<ClickThrough><![CDATA[` + clickurl + `]]></ClickThrough> ` + videoClickstrackVast + videocustomClicksVast + `
								</VideoClicks>`
			}
		}
		/*<Clickthrough_url>*/

		/*<InteractiveCreativeFile>*/
		if vidad.Interactive_mediafile.String != "" {
			interactivemediafile = `<InteractiveCreativeFile><![CDATA[` + vidad.Interactive_mediafile.String + `]]></InteractiveCreativeFile>`
		}
		/*<InteractiveCreativeFile>*/

		/*<Mezzanine>*/
		if vidad.Is_mezzininefile.Int64 == 1 {
			if vidad.Mezzanine_en.Int64 == 1 && vidad.Internal_file.String != "" {
				Videofilepath := config.GetConfig("protocol", "webpath") + config.GetConfig("protocol", "admin") + "/assets/transcoded_video/" + vidad.Internal_file.String
				Mezzaninefile = `<Mezzanine><![CDATA[` + Videofilepath + `]]></Mezzanine>`
			} else if vidad.Mezzanine_en.Int64 == 2 {
				Mezzaninefile = `<Mezzanine><![CDATA[` + vidad.Url_file.String + `]]></Mezzanine>`
			}
		}
		/*<Mezzanine>*/

		/*CLosed Captions*/
		if vidad.Vast_4_1_type_file.String == "1" || vidad.Vast_4_1_type_file_1.String == "1" || vidad.Vast_4_1_type_file_2.String == "1" {
			type1 = "text/srt"
		} else if vidad.Vast_4_1_type_file.String == "2" || vidad.Vast_4_1_type_file_1.String == "2" || vidad.Vast_4_1_type_file_2.String == "2" {
			type2 = "text/vtt"
		} else if vidad.Vast_4_1_type_file.String == "3" || vidad.Vast_4_1_type_file_1.String == "3" || vidad.Vast_4_1_type_file_2.String == "3" {
			type3 = "application/ttml+xml"
		}
		if vidad.Vast_4_1_language.String == "1" || vidad.Vast_4_1_language_1.String == "1" || vidad.Vast_4_1_language_2.String == "1" {
			lang = "en"
		} else if vidad.Vast_4_1_language.String == "2" || vidad.Vast_4_1_language_1.String == "2" || vidad.Vast_4_1_language_2.String == "2" {
			lang1 = "zh-TW"
		} else if vidad.Vast_4_1_language.String == "3" || vidad.Vast_4_1_language_1.String == "3" || vidad.Vast_4_1_language_2.String == "3" {
			lang2 = "zh-CH"
		}
		if vidad.Vast_4_1_url.String != "" {
			if vidad.Vast_4_1_url_1.String != "" {
				closedcaption2 = `<ClosedCaptionFile type='` + type2 + `' language='` + lang1 + `'><![CDATA[` + vidad.Vast_4_1_url_1.String + `]]></ClosedCaptionFile>`
			}
			if vidad.Vast_4_1_url_2.String != "" {
				closedcaption3 = `<ClosedCaptionFile type='` + type3 + `' language='` + lang2 + `'><![CDATA[` + vidad.Vast_4_1_url_2.String + `]]></ClosedCaptionFile>`
			}
			closedcaption = `<ClosedCaptionFiles>
									<ClosedCaptionFile type='` + type1 + `' language='` + lang + `'><![CDATA[` + vidad.Vast_4_1_url.String + `]]></ClosedCaptionFile>` + closedcaption2 + closedcaption3 + `
								</ClosedCaptionFiles>`
		}
		/*CLosed Captions*/
		/*Icontype*/
		k := strings.Split(path.Base(vidad.Vast_icon_filename.String), ".")
		icontype1 = string(k[1])
		if icontype1 == "jpg" || icontype1 == "jpeg" {
			icontype1 = "image/jpeg"
		} else if icontype1 == "png" {
			icontype1 = "image/png"
		} else if icontype1 == "gif" {
			icontype1 = "Image/gif"
		} else if icontype1 == "htm" {
			icontype1 = "Image/htm"
		} else {
			icontype1 = ""
		}
		/*Icontype*/
		/*Pricing*/
		pricing = `<Pricing model="` + pricingtype + `" currency="USD"><![CDATA[` + fmt.Sprintf("%.4f", adv.Revenue) + `]]></Pricing>`
		/*Pricing*/

		/*Ad_type*/
		if vidad.Ad_type.Int64 == 1 {
			adType = "audio"
		} else {
			adType = "video"
		}

		/*Ad_type*/
		/*<Icon>*/
		iprog = ""
		if vidad.Vast_icon_filename.String != "" {
			if icontype1 == "image/jpeg" {
				resource = `<StaticResource creativeType="` + icontype1 + `"><![CDATA[` + vidad.Vast_icon_filename.String + `]]></StaticResource>`
			} else {
				resource = `<HTMLResource><![CDATA[` + vidad.Vast_icon_filename.String + `]]></HTMLResource>`
			}
			icon = `<Icons>
							<Icon program="` + iprog + `" height= "` + strconv.Itoa(int(vidad.Vast_icon_height)) + `" width= "` + strconv.Itoa(int(vidad.Vast_icon_width)) + `" xPosition= "` + strconv.Itoa(int(vidad.Vast_icon_xposition.Int64)) + `" yPosition= "` + strconv.Itoa(int(vidad.Vast_icon_yposition.Int64)) + `" apiFramework="" offset= "` + vidad.Vast_icon_offset.String + `" duration= "` + vidad.Vast_icon_duration.String + `">
							` + resource + `
								<IconClicks>
									<IconClickThrough><![CDATA[` + trackingUrl + `&event=iconclick]]> </IconClickThrough>
									<IconClickTracking><![CDATA[` + trackingUrl + `&event=icontrack]]></IconClickTracking>
								</IconClicks>
								<IconViewTracking>
								<![CDATA[` + trackingUrl + `&event=iconimpression]]>
								</IconViewTracking>
							</Icon>
						</Icons>`
		}
		/*<Icon>*/
		/*Mediafile*/

		fmt.Println("302", vidad.Vid_upload_type.String)
		if vidad.Vid_upload_type.String == "Internal" {

			fmt.Println("304")
			vidad.Vast_video_outgoing_filename.String = config.GetConfig("protocol", "webpath") + config.GetConfig("images", "webpath") + "/" + vidad.Vast_video_outgoing_filename.String
		}

		mediafile = `<MediaFile delivery="` + vidad.Vast_video_delivery.String + `" bitrate="` + vidad.Vast_video_bitrate.String + `" width="640" height="480"  ` + maxbitrate + ` ` + minbitrate + ` type="` + vidad.Vast_video_type.String + `" scalable="true" maintainAspectRatio="true"><![CDATA[ ` + vidad.Vast_video_outgoing_filename.String + ` ]]></MediaFile>`

		if vidad.Vast_video_outgoing_filename1.String != "" {
			mediafile1 = `<MediaFile delivery="` + vidad.Vast_video_delivery.String + `" bitrate="` + vidad.Vast_video_bitrate_1.String + `" width="` + strconv.Itoa(adDetails.Width) + `" height="` + strconv.Itoa(adDetails.Height) + `" ` + maxbitrate + ` ` + minbitrate + ` type="` + vidad.Vast_video_type_1.String + `" scalable="true" maintainAspectRatio="true"><![CDATA[ ` + vidad.Vast_video_outgoing_filename1.String + ` ]]></MediaFile>`
		}
		if vidad.Vast_video_outgoing_filename2.String != "" {
			mediafile2 = `<MediaFile delivery="` + vidad.Vast_video_delivery.String + `" bitrate="` + vidad.Vast_video_bitrate_2.String + `" width="` + strconv.Itoa(adDetails.Width) + `" height="` + strconv.Itoa(adDetails.Height) + `" ` + maxbitrate + ` ` + minbitrate + ` type="` + vidad.Vast_video_type_2.String + `" scalable="true" maintainAspectRatio="true"><![CDATA[ ` + vidad.Vast_video_outgoing_filename2.String + ` ]]></MediaFile>`
		}
		/*Mediafile*/
		/*Min Max Bitrate*/
		if vidad.Vast4_max_bitrate.Int64 != 0 {
			maxbitrate = `"maxBitrate="` + `"` + strconv.Itoa(int(vidad.Vast4_max_bitrate.Int64)) + `"`
		}
		if vidad.Vast4_min_bitrate.Int64 != 0 {
			minbitrate = `"minBitrate="` + `"` + strconv.Itoa(int(vidad.Vast4_min_bitrate.Int64)) + `"`
		}
		/*Min Max Bitrate*/

		/*Companion Ads*/
		if vidad.Vast_thirdparty_companion_assetwidth.Int64 != 0 {
			companionassetwidth = `assetWidth="` + strconv.Itoa(int(vidad.Vast_thirdparty_companion_assetwidth.Int64)) + `"`
		}
		if vidad.Vast_thirdparty_companion_assetheight.Int64 != 0 {
			companionassetheight = `assetHeight="` + strconv.Itoa(int(vidad.Vast_thirdparty_companion_assetheight.Int64)) + `"`
		}
		if vidad.Vast_thirdparty_companion_expandedheight != 0 {
			companionexpandedheight = `expandedHeight="` + strconv.Itoa(vidad.Vast_thirdparty_companion_expandedheight) + `"`
		}
		if vidad.Vast_thirdparty_companion_expandedwidth != 0 {
			companionexpandedwidth = `expandedWidth="` + strconv.Itoa(vidad.Vast_thirdparty_companion_expandedwidth) + `"`
		}
		if vidad.Vast_creative_type.String != "" {
			companionresource = `<StaticResource creativeType="` + vidad.Vast_creative_type.String + `">`
		}
		if vidad.Vast_video_clickthrough_url.String != "" {
			companionclicks = `<CompanionClickThrough><![CDATA[` + vidad.Vast_thirdparty_companion_clicktracking + `]]></CompanionClickThrough>
					<CompanionClickTracking><![CDATA[` + vidad.Vast_thirdparty_companion_clicktracking + `]]></CompanionClickTracking>`
		}
		if vidad.Vast_companion_banner_id != 0 {
			companions = `<Companion id="` + strconv.Itoa(vidad.Vast_companion_banner_id) + `"` + companionassetwidth + companionassetheight + companionexpandedwidth + companionexpandedheight + `">
				` + companionresource + `
				` + companionclicks + `
				</Companion>`
		}

		if vidad.Vast_type == 1 {
			if vidad.Get_third_internal_type.Int64 == 1 {

				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<InLine>
							<AdSystem>
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + impression + `
							<Creatives>
								<Creative>
									<Linear>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
												]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
												]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
												]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
												]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
												]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
												]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
												]]>
											</Tracking>
											<Tracking event="fullscreen">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=fullscreen
												]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
												]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
												]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
												]]>
											</Tracking>
										</TrackingEvents>`

				if clickurl != "" {
					adDetails.Html = adDetails.Html + ` <VideoClicks>
											<ClickThrough>
											<![CDATA[` + clickurl + `]]>
											</ClickThrough>
										</VideoClicks>`

				}
				adDetails.Html = adDetails.Html + ` <MediaFiles>
											` + mediafile + `
										</MediaFiles>
									</Linear>
								</Creative>													
							</Creatives>
						</InLine>
					</Ad>
				</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<Wrapper>
							<AdSystem>
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]></AdSystem>
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + impression + `
							<VASTAdTagURI><![CDATA[ ` + strings.Replace(vidad.Vast_wrapper_url, "&", "&", -1) + ` ]]></VASTAdTagURI>
							<Creatives>
								<Creative>
									<Linear>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="fullscreen">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=fullscreen
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
										</TrackingEvents>`
				if clickurl != "" {
					adDetails.Html = adDetails.Html + ` <VideoClicks>
											<ClickThrough>
											<![CDATA[` + clickurl + `]]>
											</ClickThrough>
										</VideoClicks>`

				}
				adDetails.Html = adDetails.Html + ` </Linear>
								</Creative>
							</Creatives>
						</Wrapper>
					</Ad>
				</VAST>`
			}
		} else if vidad.Vast_type == 2 {

			if vidad.Get_third_internal_type.Int64 == 1 {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<InLine>
							<AdSystem>
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							<Pricing>
								<model>
								<![CDATA[ ` + pricingtype + ` ]]>
								</model>
								<currency>
								<![CDATA[ USD ]]>
								</currency>
							</Pricing>
							` + impression + `
							<Creatives>
								<Creative>
									<Linear ` + skip + `>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
											` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
												]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
												]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
												]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
												]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
												]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
												]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
												]]>
											</Tracking>
											<Tracking event="fullscreen">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=fullscreen
												]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
												]]>
											</Tracking>
											<Tracking event="closeLinear">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=closeLinear
												]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
												]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
												]]>
											</Tracking>
											<Tracking event="progress" ` + skip_progress_duration + `>
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
												]]>
											</Tracking>
											<Tracking event="exitFullscreen">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
												]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
												]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
												]]>
											</Tracking>
										</TrackingEvents>
										` + videoClicksVast + `
										<MediaFiles>
											` + mediafile + `
										</MediaFiles>
									</Linear>
								</Creative>
							</Creatives>
						</InLine>
					</Ad>
				</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<Wrapper>
							<AdSystem>
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							<Pricing>
								<model>
								<![CDATA[ ` + pricingtype + ` ]]>
								</model>
								<currency>
								<![CDATA[ USD ]]>
								</currency>
							</Pricing>
							` + impression + `
							<VASTAdTagURI>
							<![CDATA[ ` + strings.Replace(vidad.Vast_wrapper_url, "&", "&", -1) + ` ]]>
							</VASTAdTagURI>
							<Creatives>
								<Creative>
									<Linear>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="fullscreen">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=fullscreen
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
											]]>
											</Tracking>
											<Tracking event="closeLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=closeLinear
											]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
											]]>
											</Tracking>
											<Tracking event="progress">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
											]]>
											</Tracking>
											<Tracking event="exitFullscreen">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
										</TrackingEvents>
										` + videoClicksVast + `
									</Linear>
								</Creative>
							</Creatives>
						</Wrapper>
					</Ad>
				</VAST>`
			}
		} else if vidad.Vast_type == 3 {
			if vidad.Get_third_internal_type.Int64 == 1 {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `" conditionalAd="` + Is_conditionalad + `">
						<InLine>
							<AdSystem version="4.0">
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + adVerifications + `
							` + viewableImpression + `
							` + iabcategory + `
							` + pricing + `
							` + impression + `
							<Creatives>
								<Creative>
									<UniversalAdId idRegistry="unknown" idValue="unknown">unknown</UniversalAdId>
									<Linear ` + skip + `>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
											]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
											]]>
											</Tracking>
											<Tracking event="progress" ` + skip_progress_duration + `>
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
											<Tracking event="timeSpentViewing">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
											]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
											]]>
											</Tracking>
											<Tracking event="playerExpand">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
											]]>
											</Tracking>
											<Tracking event="playerCollapse">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
											]]>
											</Tracking>
										</TrackingEvents>
										` + videoClicksVast + `
										<MediaFiles>
											` + mediafile + `
											` + mediafile1 + `
											` + mediafile2 + `
											` + interactivemediafile + `
											` + Mezzaninefile + `
										</MediaFiles>
										` + icon + `
									</Linear>
								</Creative>
							</Creatives>
						</InLine>
					</Ad>
				</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `" conditionalAd="` + Is_conditionalad + `">
						<Wrapper fallbackOnNoAd="` + strconv.Itoa(vidad.Vast_wrapper_fallbacknoads) + `" allowMultipleAds="` + strconv.Itoa(vidad.Vast_wrapper_allowmultipleads) + `" followAdditionalWrappers="` + strconv.Itoa(vidad.Vast_wrapper_followadditional) + `">
							<AdSystem version="4.0">
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							` + viewableImpression + `
							` + pricing + `
							` + impression + `
							<VASTAdTagURI>
							<![CDATA[ ` + strings.Replace(vidad.Vast_wrapper_url, "&", "&", -1) + ` ]]>
							</VASTAdTagURI>
							<Creatives>
								<Creative>
									<Linear>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
											]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
											]]>
											</Tracking>
											<Tracking event="progress">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
											<Tracking event="timeSpentViewing">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
											]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
											]]>
											</Tracking>
											<Tracking event="playerExpand">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
											]]>
											</Tracking>
											<Tracking event="playerCollapse">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
											]]>
											</Tracking>
										</TrackingEvents>
										` + videoClicksVast + `
										` + icon + `
									</Linear>
								</Creative>
							</Creatives>
						</Wrapper>
					</Ad>
				</VAST>`
			}
		} else {
			if vidad.Ad_type.Int64 == 2 {
				if vidad.Get_third_internal_type.Int64 == 1 {
					adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
							<Ad id="` + strconv.Itoa(vidad.Banner_id) + `"  adType="` + adType + `">
								<InLine>
									<AdSystem version="4.1">
									<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
									</AdSystem>
									<AdServingId>` + adservingid + `</AdServingId>
									` + advertiser + `
									<Description>` + adDetails.Name + `</Description>
									` + expiretime + `
									<AdTitle>
									<![CDATA[ ` + adDetails.Name + ` ]]>
									</AdTitle>
									` + adVerifications + `
									` + viewableImpression + `
									` + iabcategory + `
									` + pricing + `
									` + impression + `
									<Creatives>
										<Creative>
											<UniversalAdId idRegistry="unknown" idValue="unknown">unknown</UniversalAdId>
											<Linear ` + skip + `>
												<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
												<TrackingEvents>
													<Tracking event="start">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
													]]>
													</Tracking>
													<Tracking event="firstQuartile">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
													]]>
													</Tracking>
													<Tracking event="midpoint">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
													]]>
													</Tracking>
													<Tracking event="thirdQuartile">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
													]]>
													</Tracking>
													<Tracking event="complete">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
													]]>
													</Tracking>
													<Tracking event="pause">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
													]]>
													</Tracking>
													<Tracking event="mute">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
													]]>
													</Tracking>
													<Tracking event="unmute">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
													]]>
													</Tracking>
													<Tracking event="acceptInvitationLinear">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
													]]>
													</Tracking>
													<Tracking event="skip">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
													]]>
													</Tracking>
													<Tracking event="progress" ` + skip_progress_duration + `>
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
													]]>
													</Tracking>
													<Tracking event="rewind">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
													]]>
													</Tracking>
													<Tracking event="resume">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
													]]>
													</Tracking>
													<Tracking event="timeSpentViewing">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
													]]>
													</Tracking>
													<Tracking event="otherAdInteraction">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
													]]>
													</Tracking>
													<Tracking event="playerExpand">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
													]]>
													</Tracking>
													<Tracking event="playerCollapse">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
													]]>
													</Tracking>
												</TrackingEvents>
												` + videoClicksVast + `
												<MediaFiles>
													` + closedcaption + `
													` + mediafile + `
													` + mediafile1 + `
													` + mediafile2 + `
													` + interactivemediafile + `
													` + Mezzaninefile + `
												</MediaFiles>
												` + icon + `
											</Linear>
										</Creative>
									</Creatives>
								</InLine>
							</Ad>
						</VAST>`
				} else {
					adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
							<Ad id="` + strconv.Itoa(vidad.Banner_id) + `" conditionalAd="` + Is_conditionalad + `">
								<Wrapper fallbackOnNoAd="` + strconv.Itoa(vidad.Vast_wrapper_fallbacknoads) + `" allowMultipleAds="` + strconv.Itoa(vidad.Vast_wrapper_allowmultipleads) + `" followAdditionalWrappers="` + strconv.Itoa(vidad.Vast_wrapper_followadditional) + `">
									<AdSystem version="4.1">
									<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
									</AdSystem>
									<AdServingId>` + adservingid + `</AdServingId>
									` + advertiser + `
									<Description>` + adDetails.Name + `</Description>
									` + expiretime + `
									` + viewableImpression + `
									` + pricing + `
									` + impression + `
									<VASTAdTagURI>
									<![CDATA[ ` + strings.Replace(vidad.Vast_wrapper_url, "&", "&", -1) + ` ]]>
									</VASTAdTagURI>
									<Creatives>
										<Creative>
											<Linear>
												<TrackingEvents>
													<Tracking event="start">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
													]]>
													</Tracking>
													<Tracking event="firstQuartile">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
													]]>
													</Tracking>
													<Tracking event="midpoint">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
													]]>
													</Tracking>
													<Tracking event="thirdQuartile">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
													]]>
													</Tracking>
													<Tracking event="complete">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
													]]>
													</Tracking>
													<Tracking event="pause">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
													]]>
													</Tracking>
													<Tracking event="mute">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
													]]>
													</Tracking>
													<Tracking event="unmute">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
													]]>
													</Tracking>
													<Tracking event="acceptInvitationLinear">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
													]]>
													</Tracking>
													<Tracking event="skip">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
													]]>
													</Tracking>
													<Tracking event="progress">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
													]]>
													</Tracking>
													<Tracking event="rewind">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
													]]>
													</Tracking>
													<Tracking event="resume">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
													]]>
													</Tracking>
													<Tracking event="timeSpentViewing">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
													]]>
													</Tracking>
													<Tracking event="otherAdInteraction">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
													]]>
													</Tracking>
													<Tracking event="playerExpand">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
													]]>
													</Tracking>
													<Tracking event="playerCollapse">
													<![CDATA[
														` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
													]]>
													</Tracking>
												</TrackingEvents>
												` + videoClicksVast + `
												` + icon + `
											</Linear>
										</Creative>
									</Creatives>
								</Wrapper>
							</Ad>
						</VAST>`
				}

			} else if vidad.Get_third_internal_type.Int64 == 1 && vidad.Ad_type.Int64 == 1 {
				adDetails.Html = `<DAAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `"  adType="` + adType + `">
						<InLine>
							<AdSystem version="4.1">
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdServingId>` + adservingid + `</AdServingId>
							` + advertiser + `
							<Description>` + adDetails.Name + `</Description>
							` + expiretime + `
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + adVerifications + `
							` + viewableImpression + `
							` + iabcategory + `
							` + pricing + `
							` + impression + `
							<Creatives>
								<Creative>
									<UniversalAdId idRegistry="unknown" idValue="unknown">unknown</UniversalAdId>
									<Linear ` + skip + `>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
											]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
											]]>
											</Tracking>
											<Tracking event="progress" ` + skip_progress_duration + `>
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
											<Tracking event="timeSpentViewing">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
											]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
											]]>
											</Tracking>
											<Tracking event="playerExpand">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
											]]>
											</Tracking>
											<Tracking event="playerCollapse">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
											]]>
											</Tracking>
										</TrackingEvents>
										<AudioInteractions>
										
										`
				if clickurl != "" {
					adDetails.Html = adDetails.Html + ` 
											<ClickThrough>
											<![CDATA[` + clickurl + `]]>
											</ClickThrough>
										`

				}
				adDetails.Html = adDetails.Html + videoClickstrackVast + videocustomClicksVast + `
										</AudioInteractions>
										<MediaFiles>
											` + mediafile + `
											` + mediafile1 + `
											` + mediafile2 + `
											` + interactivemediafile + `
											` + Mezzaninefile + `
										</MediaFiles>
										` + icon + `
									</Linear>
								</Creative>
							</Creatives>
							<CompanionAds>
								` + companions + `			
							</CompanionAds>
						</InLine>
					</Ad>
				</DAAST>`
			} else {
				adDetails.Html = `<DAAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `"  adType="` + adType + `">
						<Wrapper>
							<AdSystem version="4.1">
							<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdServingId>` + adservingid + `</AdServingId>
							` + advertiser + `
							<Description>` + adDetails.Name + `</Description>
							` + expiretime + `
							<AdTitle>
							<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + adVerifications + `
							` + viewableImpression + `
							` + iabcategory + `
							` + pricing + `
							` + impression + `
							<Creatives>
								<Creative>
									<UniversalAdId idRegistry="unknown" idValue="unknown">unknown</UniversalAdId>
									<Linear ` + skip + `>
										<Duration>` + helper.SecondsToTime(int(vidad.Vast_video_duration.Int64)) + `</Duration>
										<TrackingEvents>
											<Tracking event="start">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=start
											]]>
											</Tracking>
											<Tracking event="firstQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=firstquartile
											]]>
											</Tracking>
											<Tracking event="midpoint">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=midpoint
											]]>
											</Tracking>
											<Tracking event="thirdQuartile">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=thirdquartile
											]]>
											</Tracking>
											<Tracking event="complete">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=complete
											]]>
											</Tracking>
											<Tracking event="pause">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=pause
											]]>
											</Tracking>
											<Tracking event="mute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=mute
											]]>
											</Tracking>
											<Tracking event="unmute">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=unmute
											]]>
											</Tracking>
											<Tracking event="acceptInvitationLinear">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitationLinear
											]]>
											</Tracking>
											<Tracking event="skip">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=skip
											]]>
											</Tracking>
											<Tracking event="progress" ` + skip_progress_duration + `>
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=progress
											]]>
											</Tracking>
											<Tracking event="rewind">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=rewind
											]]>
											</Tracking>
											<Tracking event="resume">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=resume
											]]>
											</Tracking>
											<Tracking event="timeSpentViewing">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=timeSpentViewing
											]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
											]]>
											</Tracking>
											<Tracking event="playerExpand">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerExpand
											]]>
											</Tracking>
											<Tracking event="playerCollapse">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `&zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=playerCollapse
											]]>
											</Tracking>
										</TrackingEvents>
										<AudioInteractions>
											`
				if clickurl != "" {
					adDetails.Html = adDetails.Html + `
											<ClickThrough>
											<![CDATA[` + clickurl + `]]>
											</ClickThrough>
										`

				}
				adDetails.Html = adDetails.Html + videoClickstrackVast + videocustomClicksVast + `
										</AudioInteractions>
										<MediaFiles>
											` + mediafile + `
											` + mediafile1 + `
											` + mediafile2 + `
											` + interactivemediafile + `
											` + Mezzaninefile + `
										</MediaFiles>
										` + icon + `
									</Linear>
								</Creative>
							</Creatives>
							<CompanionAds>
								` + companions + `			
							</CompanionAds>
						</Wrapper>
					</Ad>
				</DAAST>`
			}
		}
	} else if adDetails.Width == -2 && adDetails.Height == -2 {
		var creativeType, oclickurl, nonLinearClickThrough, nonLinearClickTracking, creativeTypeAttribute, expand_width, expand_height, expand_duration, nonLinear, vpaid_swf, resourceType, elementName, code string
		//~ fmt.Println(nonLinear)
		creativeType = vidad.Vast_creative_type.String
		if vidad.Vast_overlay_format.String == "image_overlay" {
			if creativeType == "" {
				s := adDetails.Filename
				fmt.Println("len of s", s)
				if len(s) > 0 {
					creativeType = s[len(s)-3:]
				}
				if creativeType == "peg" {
					creativeType = "jpeg"
				}

			}
			if creativeType == "jpeg" {
				creativeType = "jpg"
			}
			creativeType = "image/" + creativeType
			code = config.GetConfig("protocol", "webpath") + config.GetConfig("images", "webpath") + "/" + adDetails.Filename
			resourceType = "static"
			elementName = "StaticResource"
		}
		if adDetails.Url != "" {
			oclickurl = config.GetConfig("protocol", "webpath") + config.GetConfig("delivery", "webpath") + "/cl.php?oaparams=2&bannerid=" + strconv.Itoa(vidad.Banner_id) + "&zoneid=" + strconv.Itoa(zn.Zoneid) + "___oadest=" + adDetails.Url
		}

		// config.GetConfig("protocol", "webpath") + config.GetConfig("delivery", "webpath") + "/cl.php?oaparams=2&bannerid=" + strconv.Itoa(adDetails.Ad_id) + "&zoneid=" + strconv.Itoa(zn.Zoneid) + "___oadest=" + vidad.Vast_video_clickthrough_url.String

		if oclickurl != "" {
			nonLinearClickThrough = `<NonLinearClickThrough>
												<![CDATA[` + oclickurl + `]]>
											</NonLinearClickThrough>`
		}
		if vidad.Vast_thirdparty_clicktracking.String != "" {
			nonLinearClickTracking = `<NonLinearClickTracking>
												<![CDATA[` + vidad.Vast_thirdparty_clicktracking.String + `]]>
											</NonLinearClickTracking>`
		}
		if creativeType != "" {
			creativeType = strings.ToLower(creativeType)
			creativeTypeAttribute = `creativeType="` + creativeType + `"`
		}
		if vidad.Vast_overlay_expanded_width.Int64 != 0 {
			expand_width = `expandedWidth="` + strconv.Itoa(int(vidad.Vast_overlay_expanded_width.Int64)) + `"`
		}
		if vidad.Vast_overlay_expanded_height.Int64 != 0 {
			expand_height = `expandedHeight="` + strconv.Itoa(int(vidad.Vast_overlay_expanded_height.Int64)) + `"`
		}
		if vidad.Vast_overlay_expandedminduration.String != "" {
			expand_duration = `minSuggestedDuration="` + vidad.Vast_overlay_expandedminduration.String + `"`
		}
		/*nonLinear*/
		if resourceType == "static" {
			nonLinear = `<NonLinear id="overlay" width="` + strconv.Itoa(int(vidad.Vast_overlay_width.Int64)) + `" height="` + strconv.Itoa(int(vidad.Vast_overlay_height.Int64)) + `" maintainAspectRatio="true" ` + vpaid_swf + ` scalable="true" ` + expand_duration + ` ` + expand_width + ` ` + expand_height + `><` + elementName + ` ` + creativeTypeAttribute + `>
									<![CDATA[` + code + `]]></` + elementName + `>
									` + nonLinearClickThrough + `
									` + nonLinearClickTracking + `
								</NonLinear>`
		} else {
			nonLinear = `<NonLinear id="overlay">
									` + nonLinearClickThrough + `
									` + nonLinearClickTracking + `
								</NonLinear>`
		}
		/*nonLinear*/
		if vidad.Vast_type == 1 {
			if vidad.Vast_overlay_format.String == "image_overlay" {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="vast.xsd">
									<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
										<InLine>
											<AdSystem>
												<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
											</AdSystem>
											<AdTitle>
												<![CDATA[ ` + adDetails.Name + ` ]]>
											</AdTitle>
											` + impression + `
											<Creatives>
												<Creative sequence="1">
													<NonLinearAds>
														<TrackingEvents>
															<Tracking event="creativeView">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
															]]>
															</Tracking>
															<Tracking event="expand">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
															]]>
															</Tracking>
															<Tracking event="collapse">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
															]]>
															</Tracking>
															<Tracking event="acceptInvitation">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
															]]>
															</Tracking>
															<Tracking event="close">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
															]]>
															</Tracking>
														</TrackingEvents>
														` + nonLinear + `
													</NonLinearAds>
												</Creative>
											</Creatives>
										</InLine>
									</Ad>
								</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<Wrapper>
							<AdSystem>
								<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
								<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + impression + `
							<VASTAdTagURI>
								<![CDATA[ ` + strings.Replace(vidad.Vast_overlay_wrapper.String, "&", "&", -1) + ` ]]>
							</VASTAdTagURI>
							<Creatives>
								<Creative sequence="1">
									<NonLinearAds>
										<TrackingEvents>
											<Tracking event="creativeView">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
											]]>
											</Tracking>
											<Tracking event="expand">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
											]]>
											</Tracking>
											<Tracking event="collapse">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
											]]>
											</Tracking>
											<Tracking event="acceptInvitation">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
											]]>
											</Tracking>
											<Tracking event="close">
											<![CDATA[
												` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
											]]>
											</Tracking>
										</TrackingEvents>
										` + nonLinear + `
									</NonLinearAds>
								</Creative>
							</Creatives>
						</Wrapper>
					</Ad>
				</VAST>`
			}
		} else if vidad.Vast_type == 2 {
			if vidad.Vast_overlay_format.String == "image_overlay" {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<InLine>
							<AdSystem>
								<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
								<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							<Pricing>
								<model>
									<![CDATA[ ` + pricingtype + ` ]]>
								</model>
								<currency>
									<![CDATA[ USD ]]>
								</currency>
							</Pricing>
							` + impression + `											
							<Creatives>
								<Creative sequence="1">
									<NonLinearAds>
										<TrackingEvents>
											<Tracking event="creativeView">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
												]]>
											</Tracking>
											<Tracking event="expand">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
												]]>
											</Tracking>
											<Tracking event="collapse">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
												]]>
											</Tracking>
										</TrackingEvents>
										` + nonLinear + `
									</NonLinearAds>
								</Creative>
							</Creatives>
						</InLine>
					</Ad>
				</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:noNamespaceSchemaLocation="vast.xsd">
									<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
									<Wrapper>
										<AdSystem>
											<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
										</AdSystem>
										<AdTitle>
											<![CDATA[ ` + adDetails.Name + ` ]]>
										</AdTitle>
										<Pricing>
											<model>
												<![CDATA[ ` + pricingtype + ` ]]>
											</model>
											<currency>
												<![CDATA[ USD ]]>
											</currency>
										</Pricing>
										` + impression + `
										<VASTAdTagURI>
											<![CDATA[ ` + strings.Replace(vidad.Vast_overlay_wrapper.String, "&", "&", -1) + ` ]]>
										</VASTAdTagURI>
										<Creatives>
											<Creative sequence="1">
												<NonLinearAds>
													<TrackingEvents>
														<Tracking event="creativeView">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
															]]>
														</Tracking>
														<Tracking event="expand">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
															]]>
														</Tracking>
														<Tracking event="collapse">
															<![CDATA[
																` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
															]]>
														</Tracking>
													</TrackingEvents>
													` + nonLinear + `
												</NonLinearAds>
											</Creative>
										</Creatives>
									</Wrapper>
								</Ad>
							</VAST>`
			}
		} else if vidad.Vast_type == 3 {
			if vidad.Vast_overlay_format.String == "image_overlay" {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
						<InLine>
							<AdSystem>
								<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							<AdTitle>
								<![CDATA[ ` + adDetails.Name + ` ]]>
							</AdTitle>
							` + adVerifications + `
							` + viewableImpression + `
							` + iabcategory + `
							<Pricing>
								<model>
									<![CDATA[ ` + pricingtype + ` ]]>
								</model>
								<currency>
									<![CDATA[ USD ]]>
								</currency>
							</Pricing>
							` + impression + `
							<Creatives>
								<Creative sequence="1">
									<UniversalAdId idRegistry="unknown" idValue="unknown">"unknown"</UniversalAdId>
									<NonLinearAds>
										<TrackingEvents>
											<Tracking event="creativeView">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
												]]>
											</Tracking>
											<Tracking event="adExpand">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
												]]>
											</Tracking>
											<Tracking event="adCollapse">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
												]]>
											</Tracking>
											<Tracking event="acceptInvitation">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
												]]>
											</Tracking>
											<Tracking event="close">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
												]]>
											</Tracking>
											<Tracking event="overlayViewDuration">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=overlayViewDuration
												]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
												]]>
											</Tracking>
											<Tracking event="minimize">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
												]]>
											</Tracking>
										</TrackingEvents>
										` + nonLinear + `
									</NonLinearAds>
								</Creative>
							</Creatives>
						</InLine>
					</Ad>
				</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0" xsi:noNamespaceSchemaLocation="vast.xsd">
					<Ad id="` + strconv.Itoa(vidad.Banner_id) + `" conditionalAd="` + Is_conditionalad + `">
						<Wrapper fallbackOnNoAd="` + strconv.Itoa(vidad.Vast_wrapper_fallbacknoads) + `" allowMultipleAds="` + strconv.Itoa(vidad.Vast_wrapper_allowmultipleads) + `" followAdditionalWrappers="` + strconv.Itoa(vidad.Vast_wrapper_followadditional) + `">
							<AdSystem version="4.0">
								<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
							</AdSystem>
							` + viewableImpression + `
							` + iabcategory + `
							<Pricing>
								<model>
									<![CDATA[ ` + pricingtype + ` ]]>
								</model>
								<currency>
									<![CDATA[ USD ]]>
								</currency>
							</Pricing>
							` + impression + `
							<VASTAdTagURI>
								<![CDATA[ ` + strings.Replace(vidad.Vast_overlay_wrapper.String, "&", "&", -1) + ` ]]>
							</VASTAdTagURI>
							<Creatives>
								<Creative sequence="1">
									<NonLinearAds>
										<TrackingEvents>
											<Tracking event="creativeView">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
												]]>
											</Tracking>
											<Tracking event="adExpand">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
												]]>
											</Tracking>
											<Tracking event="adCollapse">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
												]]>
											</Tracking>
											<Tracking event="acceptInvitation">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
												]]>
											</Tracking>
											<Tracking event="close">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
												]]>
											</Tracking>
											<Tracking event="overlayViewDuration">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=overlayViewDuration
												]]>
											</Tracking>
											<Tracking event="otherAdInteraction">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
												]]>
											</Tracking>
											<Tracking event="minimize">
												<![CDATA[
													` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
												]]>
											</Tracking>
										</TrackingEvents>
										` + nonLinear + `
									</NonLinearAds>
								</Creative>
							</Creatives>
						</Wrapper>
					</Ad>
				</VAST>`
			}
		} else {
			if vidad.Vast_overlay_format.String == "image_overlay" {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
										<Ad id="` + strconv.Itoa(vidad.Banner_id) + `">
											<InLine>
												<AdSystem>
													<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
												</AdSystem>
												<AdTitle>
													<![CDATA[ ` + adDetails.Name + ` ]]>
												</AdTitle>
												<AdServingId>` + adservingid + `</AdServingId>
												` + advertiser + `
												<Description>` + adDetails.Name + `</Description>
												` + expiretime + `
												` + adVerifications + `
												` + viewableImpression + `
												` + iabcategory + `
												<Pricing>
													<model>
														<![CDATA[ ` + pricingtype + ` ]]>
													</model>
													<currency>
														<![CDATA[ USD ]]>
													</currency>
												</Pricing>
												` + impression + `
												<Creatives>
													<Creative sequence="1">
														<UniversalAdId idRegistry="unknown" idValue="unknown">"unknown"</UniversalAdId>
														<NonLinearAds>
															<TrackingEvents>
																<Tracking event="creativeView">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
																	]]>
																</Tracking>
																<Tracking event="adExpand">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
																	]]>
																</Tracking>
																<Tracking event="adCollapse">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
																	]]>
																</Tracking>
																<Tracking event="acceptInvitation">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
																	]]>
																</Tracking>
																<Tracking event="close">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
																	]]>
																</Tracking>
																<Tracking event="overlayViewDuration">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=overlayViewDuration
																	]]>
																</Tracking>
																<Tracking event="otherAdInteraction">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
																	]]>
																</Tracking>
																<Tracking event="minimize">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
																	]]>
																</Tracking>
															</TrackingEvents>
															` + nonLinear + `
														</NonLinearAds>
													</Creative>
												</Creatives>
											</InLine>
										</Ad>	
									</VAST>`
			} else {
				adDetails.Html = `<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.1" xsi:noNamespaceSchemaLocation="vast.xsd">
										<Ad id="` + strconv.Itoa(vidad.Banner_id) + `" conditionalAd="` + Is_conditionalad + `">
											<Wrapper fallbackOnNoAd="` + strconv.Itoa(vidad.Vast_wrapper_fallbacknoads) + `" allowMultipleAds="` + strconv.Itoa(vidad.Vast_wrapper_allowmultipleads) + `" followAdditionalWrappers="` + strconv.Itoa(vidad.Vast_wrapper_followadditional) + `">
												<AdSystem version="4.1">
													<![CDATA[ ` + config.GetConfig("name", "app") + ` ]]>
												</AdSystem>
												<AdServingId>` + adservingid + `</AdServingId>
												` + advertiser + `
												<Description>` + adDetails.Name + `</Description>
												` + expiretime + `
												` + viewableImpression + `
												` + iabcategory + `
												<Pricing>
													<model>
														<![CDATA[ ` + pricingtype + ` ]]>
													</model>
													<currency>
														<![CDATA[ USD ]]>
													</currency>
												</Pricing>
												` + impression + `
												<VASTAdTagURI>
													<![CDATA[ ` + strings.Replace(vidad.Vast_overlay_wrapper.String, "&", "&", -1) + ` ]]>
												</VASTAdTagURI>
												<Creatives>
													<Creative sequence="1">
														<NonLinearAds>
															<TrackingEvents>
																<Tracking event="creativeView">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=creativeView
																	]]>
																</Tracking>
																<Tracking event="adExpand">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=expand
																	]]>
																</Tracking>
																<Tracking event="adCollapse">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=collapse
																	]]>
																</Tracking>
																<Tracking event="acceptInvitation">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=acceptInvitation
																	]]>
																</Tracking>
																<Tracking event="close">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=close
																	]]>
																</Tracking>
																<Tracking event="overlayViewDuration">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=overlayViewDuration
																	]]>
																</Tracking>
																<Tracking event="otherAdInteraction">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=otherAdInteraction
																	]]>
																</Tracking>
																<Tracking event="minimize">
																	<![CDATA[
																		` + fc_path + `?script=rmvideoAds:rmvastEvent&bannerid=` + strconv.Itoa(vidad.Banner_id) + `zoneid=` + strconv.Itoa(zn.Zoneid) + `&event=exitfullscreen
																	]]>
																</Tracking>
															</TrackingEvents>
															` + nonLinear + `
														</NonLinearAds>
													</Creative>
												</Creatives>
											</Wrapper>
										</Ad>
									</VAST>`
			}
		}
	}

}
