var numericExpression = /^[0-9]+$/;
var numericExpression_float = /^[0-9]+\.[0-9]+$/;
var purchaseExpression = /^[0-9a-zA-Z_$]+$/;

function trim(stringToTrim) {
	
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function productCheckregisteration(tweet) {

	var form_name = document.prod_add;
	
	var v_product_name = trim(form_name.product_name.value);
	//var v_product_code = trim(form_name.product_code.value);
	var category = document.getElementById('category').value;
	var description = trim(form_name.desc.value);
	var v_price = trim(form_name.price.value);
	var v_quantity = trim(form_name.quantity.value);
	var upload_check = form_name.dp.checked;
	var upload_content = trim(form_name.dp_upload.value);
	var upload_image = trim(form_name.upload.value);
	var s_cost = trim(form_name.shipping_cost.value);
	var v_purchase_code = trim(form_name.purchase_code.value);
	
	
	var pattern=/(zip|mp3|wav|flac|mov|jpg|png|mpg)/;

	if(v_product_name=="")
	{
		alert("Product Name is a Required Field");
		form_name.product_name.focus();
		return false;
	}
	//gomathi commented 
/*	if(v_product_code == "")
	{
		alert("Product Code is a Required Field");
		form_name.product_code.focus();
		return false;
	}*/
	
	if(category == "0")
	{
		alert("Product Select Category");
		document.getElementById('category').focus();
		return false;
	}
	
	if(description == "")
	{
		alert("Description is a Required Field");
		form_name.desc.focus();
		return false;
	}
	
	if((!document.getElementById("productid")) && upload_image == "")
	{
		alert("Browse product image!");
		document.getElementById("upload").focus();
		return false;
	}
 	else
	{	
		if(upload_image!="")
		{
			var extPos = upload_image.lastIndexOf(".");
			if (extPos == - 1 )    
			{
				alert("Invalid product image!");
				document.getElementById("upload").focus();
				document.getElementById("upload").select();
				return false;
			}  
			else    
			{
				var extn =  upload_image.substring(extPos+1);
				if (extn.toUpperCase() != "JPG" && extn.toUpperCase() != "GIF" && extn.toUpperCase() != "JPEG" && extn.toUpperCase() != "PNG")	
				{
					alert("Invalid product image type!");
					document.getElementById("upload").focus();
					document.getElementById("upload").select();
					return false;
				}
			}
		}
	}
	
	/*gomathi added*/
	if(tweet==1)
	{
		var retweet = document.getElementById("every_hour").value;
		if(retweet == "")
		{
			alert("Hour cannot be empty!");
			document.getElementById("every_hour").focus();
			return false;
		}
		else if(!check_int(retweet))
		{
			alert("Hour should be a number!");
			document.getElementById("every_hour").focus();
			document.getElementById("every_hour").select();
			return false;
		}
		else if(retweet<0 || retweet>24)
		{
			alert("Hour should be between 0 to 24!");
			document.getElementById("every_hour").focus();
			document.getElementById("every_hour").select();
			return false;
		}
		
	}
	
	
	if(upload_check)
	{
		if(upload_content == "")
		{
			if(!document.getElementById("digital_image_buffer") || document.getElementById("digital_image_buffer").value=="" || document.getElementById("digital_image_buffer").value=="exists")
			{
				alert("Please Upload the Digital Content");
				form_name.dp_upload.focus();
				return false;
			}
		}
	
		if(upload_content != "")
		{
			var pict=upload_content;
			var picts=pict.split(".");
			var no=picts.length;
			var pat=picts[no-1];
			pat = pat.toLowerCase();
			var matchval=pat.match(pattern);
			if(matchval==null)
			{
				alert("Invalid file format for Digital Product");
				form_name.dp_upload.focus();
				return false;
			}
			
		}
	}
	
	if(v_price == "")
	{
		alert("Price is a Required Field");
		form_name.price.focus();
		return false;
	}

	if((!v_price.match(numericExpression)) && (!v_price.match(numericExpression_float)))
	{
		alert("Price should be valid");
		form_name.price.focus();
		return false;
	}
	if(parseFloat(v_price) < parseFloat(document.getElementById("min_price").value) || parseFloat(v_price) > parseFloat(document.getElementById("max_price").value))
	{
		alert("Product Price should be between "+document.getElementById("min_price").value+" and "+document.getElementById("max_price").value);
		form_name.price.focus();
		return false;
	}
	
	if(v_price.match(numericExpression_float))
	{
		var v_sprice = v_price.split(".");
		if(v_sprice[1].length>2)
		{
			alert("Price should not go beyond 2 decimal points");
			form_name.price.focus();
			return false;
		}
	}
	
	if(upload_check==false)
	{
		if(v_quantity == "")
		{
			alert("Quantity is a Required Field");
			form_name.quantity.focus();
			return false;
		}
		
		if(!v_quantity.match(numericExpression) || v_quantity<=0)
		{
			alert("Quantity should be valid");
			form_name.quantity.focus();
			return false;
		}
	}
	
	if((s_cost != "") && (!s_cost.match(numericExpression)) && (!s_cost.match(numericExpression_float)))
	{
		alert("Shipping cost should be valid");
		form_name.shipping_cost.focus();
		return false;
	}
	
	if((s_cost != "") && s_cost.match(numericExpression_float))
	{
		var v_s_cost = s_cost.split(".");
		if(v_s_cost[1].length>2)
		{
			alert("Shipping cost should not go beyond 2 decimal points");
			form_name.shipping_cost.focus();
			return false;
		}
	}

		
	if(v_purchase_code == "")
	{
		alert("Purchase Code is a Required Field");
		form_name.purchase_code.focus();
		return false;
	}

	if(v_purchase_code.substr(0,1) != "$") {
		alert("Purchase Code should always preceded by a '$'");
		form_name.purchase_code.focus();
		return false;
	} else {
		if(v_purchase_code.length <= 1) {
			alert("Purchase Code should have atleast one character after '$'");
			form_name.purchase_code.focus();
			return false;
		}
		else
		{
			if(!v_purchase_code.match(purchaseExpression))
			{
				alert("Purchase Code should contain only A-Z,a-z,0-9,_,$ characters");
				form_name.purchase_code.focus();
				return false;
			}
		}
	}
	
	
	xmlHttp=GetXmlHttpObjectOnly();
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return false;
	} 
	var url="./product_return_ajax.php";
	url=url+"?prod_name="+v_product_name+"&prod_cat="+category;
	
	if(document.getElementById("productid"))
		url=url+"&productid="+document.getElementById("productid").value;
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}



function albumCheckregisteration() {

	var form_name = document.prod_add;
	
	var v_product_name = trim(form_name.product_name.value);
	var category = document.getElementById('category').value;
	var genre = document.getElementById('genre').value;
	var v_label = trim(form_name.label.value);
	var v_price = trim(form_name.price.value);
	var v_discount_rate = trim(form_name.discount_rate.value);
	var v_maximum_discount = trim(form_name.maximum_discount.value);
	var v_purchase_code = trim(form_name.purchase_code.value);
	var upload_content = trim(form_name.dp_upload.value);
	var upload_image = trim(form_name.upload.value);
	
	
	var pattern=/(zip|mp3|wav|flac|mov|jpg|png|mpg)/;

	if(v_product_name=="")
	{
		alert("Album Name is a Required Field");
		form_name.product_name.focus();
		return false;
	}

	if(category == "0")
	{
		alert("Pleas select Category");
		document.getElementById('category').focus();
		return false;
	}
	
	if(genre == "0")
	{
		alert("Please select Genre");
		document.getElementById('genre').focus();
		return false;
	}
	
	if(v_label == "")
	{
		alert("Label is a Required Field");
		form_name.label.focus();
		return false;
	}
	
	if(v_price == "")
	{
		alert("Price is a Required Field");
		form_name.price.focus();
		return false;
	}
	
	if(v_purchase_code == "")
	{
		alert("Purchase Code is a Required Field");
		form_name.purchase_code.focus();
		return false;
	}

	if((!v_price.match(numericExpression)) && (!v_price.match(numericExpression_float)))
	{
		alert("Price should be valid");
		form_name.price.focus();
		return false;
	}
	if(parseFloat(v_price) < parseFloat(document.getElementById("min_price").value) || parseFloat(v_price) > parseFloat(document.getElementById("max_price").value))
	{
		alert("Product Price should be between "+document.getElementById("min_price").value+" and "+document.getElementById("max_price").value);
		form_name.price.focus();
		return false;
	}
	
	if((!v_price.match(numericExpression)) && (!v_price.match(numericExpression_float)))
	{
		alert("Price should be valid");
		form_name.price.focus();
		return false;
	}
	
	if(v_price.match(numericExpression_float))
	{
		var v_sprice = v_price.split(".");
		if(v_sprice[1].length>2)
		{
			alert("Price should not go beyond 2 decimal points");
			form_name.price.focus();
			return false;
		}
	}
	
	if(v_discount_rate != "") {
		if((!v_discount_rate.match(numericExpression)) && (!v_discount_rate.match(numericExpression_float)))
		{
			alert("Twiscount Rate should be valid");
			form_name.discount_rate.focus();
			return false;
		}
		
		if(v_discount_rate.match(numericExpression_float))
		{
			var v_sdiscount_rate = v_discount_rate.split(".");
			if(v_sdiscount_rate[1].length>4)
			{
				alert("Twiscount Rate should not go beyond 4 decimal points");
				form_name.discount_rate.focus();
				return false;
			}
		}
	}
	
	if(v_maximum_discount != "") {
		if((!v_maximum_discount.match(numericExpression)) && (!v_maximum_discount.match(numericExpression_float)))
		{
			alert("Maximum Twiscount should be valid");
			form_name.maximum_discount.focus();
			return false;
		}
		
		if(v_maximum_discount.match(numericExpression_float))
		{
			var v_smaximum_discount = v_maximum_discount.split(".");
			if(v_smaximum_discount[1].length>4)
			{
				alert("Maximum Twiscount should not go beyond 4 decimal points");
				form_name.discount_rate.focus();
				return false;
			}
		}
	}
	
	if(v_purchase_code.substr(0,1) != "$") {
		alert("Purchase Code should always preceded by a '$'");
		form_name.purchase_code.focus();
		return false;
	} else {
		if(v_purchase_code.length <= 1) {
			alert("Purchase Code should have atleast one character after '$'");
			form_name.purchase_code.focus();
			return false;
		}
		else
		{
			if(!v_purchase_code.match(purchaseExpression))
			{
				alert("Purchase Code should contain only A-Z,a-z,0-9,_,$ characters");
				form_name.purchase_code.focus();
				return false;
			}
		}
	}
	
	
	if((!document.getElementById("productid")) && upload_content == "")
	{
		alert("Browse Media Zip File!");
		document.getElementById("upload").focus();
		return false;
	}
 	else
	{	
		if(upload_content != "")
		{
			var pict=upload_content;
			var picts=pict.split(".");
			var no=picts.length;
			var pat=picts[no-1];
			pat = pat.toLowerCase();
			var matchval=pat.match(pattern);
			if(matchval==null)
			{
				alert("Invalid file format for Media Zip Upload");
				form_name.dp_upload.focus();
				return false;
			}
			
		}
	}
	
	if((!document.getElementById("productid")) && upload_image == "")
	{
		alert("Browse Album Art image!");
		document.getElementById("upload").focus();
		return false;
	}
 	else
	{	
		if(upload_image!="")
		{
			var extPos = upload_image.lastIndexOf(".");
			if (extPos == - 1 )    
			{
				alert("Invalid Album Art image!");
				document.getElementById("upload").focus();
				document.getElementById("upload").select();
				return false;
			}  
			else    
			{
				var extn =  upload_image.substring(extPos+1);
				if (extn.toUpperCase() != "JPG" && extn.toUpperCase() != "GIF" && extn.toUpperCase() != "JPEG" && extn.toUpperCase() != "PNG")	
				{
					alert("Invalid Album Art image type!");
					document.getElementById("upload").focus();
					document.getElementById("upload").select();
					return false;
				}
			}
		}
	}
	
	
	
	//if(!validateTrackRow()) {
		//return false;
	//}
	
	xmlHttp=GetXmlHttpObjectOnly();
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return false;
	} 
	var url="./product_return_ajax.php";
	url=url+"?prod_name="+v_product_name+"&prod_cat="+category;
	
	if(document.getElementById("productid"))
		url=url+"&productid="+document.getElementById("productid").value;
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function check_product_code()
{
	v_purchase_code = document.getElementById("purchase_code").value;
	if(v_purchase_code == "")
	{
		alert("Purchase Code is a Required Field");
		document.getElementById("purchase_code").focus();
		return false;
	}

	if(v_purchase_code.substr(0,1) != "$") {
		alert("Purchase Code should always preceded by a '$'");
		document.getElementById("purchase_code").focus();
		return false;
	} else {
		if(v_purchase_code.length <= 1) {
			alert("Purchase Code should have atleast one character after '$'");
			document.getElementById("purchase_code").focus();
			return false;
		}
		else
		{
			if(!v_purchase_code.match(purchaseExpression))
			{
				alert("Purchase Code should contain only A-Z,a-z,0-9,_,$ characters");
				document.getElementById("purchase_code").focus();
				return false;
			}
		}
	}

	xmlHttp=GetXmlHttpObjectOnly();
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return false;
	} 
	var url="../product_purchase_code_ajax.php";
	url=url+"?purchase_code="+v_purchase_code;

	if(document.getElementById("productid"))
		url=url+"&product_id="+document.getElementById("productid").value;
	xmlHttp.onreadystatechange=showPurchaseStatus;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function showPurchaseStatus()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var output = xmlHttp.responseText;
		if(output == "1")
		{
			alert("Purchase Code is not available, Please try with other some other purchase code");
			document.getElementById("purchase_code").focus();
			return false;
		}
		else
		{
			alert("Purchase Code is available");
			return false;
		}
	}
}


function stateChanged1() 
{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
var output = xmlHttp.responseText;

if(output == "1")
{
	alert("The Product Name Already Exists");
	document.prod_add.product_name.focus();
	return false;
}
document.prod_add.submit();
} 
} 




//
function GetXmlHttpObjectOnly()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function storeOrders(selorder)
{
	var order_c = ReadCookie("order_ids");
	var order_sp = order_c.split(",");
	var order_i = 0;
	var matched = false;
	while(order_i < order_sp.length)
	{
		if(selorder.value == order_sp[order_i])
			matched = true;
			
		order_i++;
	}
	var order_s = "";
	
	if(matched == true)
	{
		if(selorder.checked == false)	
		{
			var order_c = ReadCookie("order_ids");
			var order_sp = order_c.split(",");
			var order_i = 0;
			
			while(order_i < order_sp.length)
			{
				if(selorder.value != order_sp[order_i])
				{
					if(order_s=="")
						order_s = order_sp[order_i];
					else
						order_s += ","+order_sp[order_i];
				}
				order_i++;
			}
		}
	}
	else
	{
		if(selorder.checked == true)	
		{
			var order_s = ReadCookie("order_ids");
			if(order_s=="")
				order_s = selorder.value;
			else
				order_s += ","+selorder.value;
		}
	}
	WriteCookie("order_ids",order_s,null,null,"/");	
		
}
function checkOrders()
{	
	if(ReadCookie("order_ids")!="" && ReadCookie("order_ids")!="0")
	{
		document.orders.download_order.value = ReadCookie("order_ids");
		document.orders.submit();
	}
	else
		alert("Please select the order(s) to download");
	
}


function checkAllOrders()
{	
	if(document.orders.checkAllBox.checked)
	{
		for(k=1;k<=document.orders.download_count.value;k++)
		{
			
			var checkbox_name1 = "order_"+k;
			document.getElementById(checkbox_name1).checked = true;	
			
		}	
		WriteCookie("order_all","1",null,null,"/");
		WriteCookie("order_ids",document.orders.sorders.value,null,null,"/");	
	}
	else
	{
		for(k=1;k<=document.orders.download_count.value;k++)
		{
		
			var checkbox_name1 = "order_"+k;
			document.getElementById(checkbox_name1).checked = false;				
		}		
		WriteCookie("order_all","0",null,null,"/");
		WriteCookie("order_ids","0",null,null,"/");	
	}
}

function clearorders()
{
	WriteCookie("order_all","0",null,null,"/");
	WriteCookie("order_ids","0",null,null,"/");	
}
function loadorders()
{
	if(document.orders.firstload.value=="")
	{
		WriteCookie("order_all","0",null,null,"/");
		WriteCookie("order_ids","0",null,null,"/");	
	}
	
	var order_all = ReadCookie("order_all");
	if(order_all=="1")
	{
		document.orders.checkAllBox.checked = true;
		/*for(k=1;k<=document.orders.download_count.value;k++)
		{
			var checkbox_name1 = "order_"+k;
			document.getElementById(checkbox_name1).checked = true;	
		}	*/
	}
	var ar_up = ReadCookie("order_ids");
	if(ar_up!="")
	{
		for(k=1;k<=document.orders.download_count.value;k++)
		{
			var checkbox_name1 = "order_"+k;
			var ar_up_sp = ar_up.split(",");
			var ar_i = 0;
			while(ar_i < ar_up_sp.length)
			{
				if(document.getElementById(checkbox_name1).value == ar_up_sp[ar_i])
					document.getElementById(checkbox_name1).checked = true;	
				ar_i++;
			}
		}	
	}
}

function updateTweetText()
{
	//var product_name = document.getElementById("product_name").value;
	//var desc = document.getElementById("desc").value;
	if (document.getElementById("message"))
	 var message = document.getElementById("message").value;
	else
	 var message = '';

	var id = "id";
	if(document.getElementById("productid") && document.getElementById("productid").value!="")
		id = document.getElementById("productid").value;
		
	var product_url = document.getElementById("product_url").value+id;
	var price = document.getElementById("price").value;
	//alert(price);
	//var shipping_cost = document.getElementById("shipping_cost").value;
	//var htwitter_name = document.getElementById("htwitter_name").value;
	//desc = desc.substr(0,50);
	if((!price.match(numericExpression)) && (!price.match(numericExpression_float)))
		price = 0;
	//if((!shipping_cost.match(numericExpression)) && (!shipping_cost.match(numericExpression_float)))
		//shipping_cost = 0;
	
	//price = parseFloat(price) + parseFloat(shipping_cost);
	price = parseFloat(price);
	
	if(document.getElementById("purchase_code") && document.getElementById("purchase_code").value!="")
		var purchase_code = document.getElementById("purchase_code").value;
	else
		var purchase_code = "";

	var vendorname = document.getElementById("twitter_username").value;
	
	if((price.toString()).indexOf(".")!=-1)
		price = formatNumber(price,2,'','.','','','','');

	var tweetmessage = product_url+" or tweet "+purchase_code+" @"+vendorname+" $"+price;
	
	
	var dlen = tweetmessage.length;
	if(dlen<=80)
	{
		dlen = 80-dlen;
		dlen = dlen+52;
		if(message.length>dlen)
			message = message.substr(0,dlen-2)+"..";
		else
			message = message.substr(0,dlen);
	}
	else
	{					
		var elen = 125 - dlen;
		if(message.length>elen)
		{
			dlen = 123 - dlen;
			message = message.substr(0,dlen)+"..";
		}
		else
			message = message.substr(0,elen)+"..";
	}  	
	
	
	tweetmessage = message+" "+tweetmessage;
	
	//if(purchase_code != "")
	//tweetmessage = tweetmessage+" "+purchase_code;
	
	//if(price != "")
	document.getElementById("tweet_text").innerHTML = tweetmessage;
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}




function checkDigital()
{
	if(document.getElementById("digital_image_buffer").value!=="")
	{
		document.getElementById("dp").checked=true;
		chk();
	}
}


function ReadCookie(name){
    var allCookie, CookieVal, length,start,end;
    cookieVal="";
    name=name+"="; //append equals to avoid false matches.
    allCookie=document.cookie;
    length=allCookie.length;
    if (length>0) {//no cookies - user is probably incinerating cookies.
        start=allCookie.indexOf(name,0)
        if (start!=-1) {//if string appeared - otherwise cookie wasn't set.
            start+=name.length;
            end=allCookie.indexOf(";",start);
            if (end==-1) {end=length;}
            cookieVal=unescape(allCookie.substring(start,end));
        }
    }
    return(cookieVal);
}

// Write cookie - send to browser
function WriteCookie(name,value,expires,domain,path,secure){
    var CookieVal,CookError;
    CookieVal=CookError="";
    if (name) {
        CookieVal=CookieVal+escape(name)+"=";
        if (value) {
            CookieVal=CookieVal+escape(value);
            if (expires) {
                CookieVal=CookieVal+"; expires="+expires.toGMTString();
            }
            //if (domain){
                //CookieVal=CookieVal+"; domain=twotweet.com";
            //}
            if (path) {
                CookieVal=CookieVal+"; path="+path;
            }
            if (secure) {
                CookieVal=CookieVal+"; secure";
            }
        }
        else {CookError=CookError+"Value failure";}//need valid value
    }
    else {CookError=CookError+"Name failure";}//need valid name
    if (!CookError) {
        document.cookie=CookieVal;//sets cookie
        if (value != ReadCookie(name)) //checks to make sure it worked
        {CookError="Write failure";}
    }
    return CookError;
}


function createLI(create_UL, content, className)
{
  var create_LI = document.createElement("LI");
  var create_TN = document.createTextNode(content);
  create_LI.className = className;
  create_LI.appendChild(create_TN);
  create_UL.appendChild(create_LI);
}

function createINPUT(create_UL, name, value)
{
  var create_IN = document.createElement("INPUT");
  create_IN.value = value;
  create_IN.name = name;
  create_IN.id = name;
  create_IN.setAttribute("type", "hidden");
  create_UL.appendChild(create_IN);
}

function createLISpan(create_UL, content, className)
{
  var create_LI = document.createElement("LI");
  var create_SP = document.createElement("SPAN");
  create_LI.className = className;
  create_SP.innerHTML = content;
  create_LI.appendChild(create_SP);
  create_UL.appendChild(create_LI);
}
// Last updated 2006-02-21
function addRowToTable(tname, tisrc, ttime)
{

  var container = document.getElementById("trackmanage");
  var create_UL = document.createElement("UL");

  var id = document.getElementById("last_track_no").value;

  if(typeof(tname) == "undefined")
  {
	var tname = trim(document.getElementById("track_title").value);
	var tisrc = trim(document.getElementById("track_isrc").value);
	var ttime = trim(document.getElementById("track_time").value);
  }

  if(tname == "")
  {
	  alert("Please enter track title");
	  document.getElementById("track_title").focus();
	  return false;
  }
  /**
  if(tisrc == "")
  {
	  alert("Please enter track isrc");
	  document.getElementById("track_isrc").focus();
	  return false;
  }

  if(ttime == "")
  {
	  alert("Please enter track time");
	  document.getElementById("track_time").focus();
	  return false;
  }**/

  createINPUT(create_UL, "track_title"+id, tname);
  createINPUT(create_UL, "track_isrc"+id, tisrc);
  createINPUT(create_UL, "track_time"+id, ttime);

  create_UL.id = "track_"+id;
  createLISpan(create_UL, id+".", "number1_s");
  createLISpan(create_UL, tname, "title1_s");
  createLISpan(create_UL, tisrc, "isrc1_s");
  createLISpan(create_UL, ttime, "time1_s");
  createLISpan(create_UL, '<a href="#" onclick="return removeRowFromTable('+id+');"><img src="../images/del_icon.png" border="0" /></a>', "del1_s");

  create_UL.className = "table_row_s";

  container.insertBefore(create_UL, document.getElementById("trackaction"));
  document.getElementById("last_track_no").value = ++id;

  document.getElementById("licount").innerHTML = id;
  document.getElementById("track_title").value = "";
  document.getElementById("track_isrc").value = "";
  document.getElementById("track_time").value = "";

  var ttrack = document.getElementById("tot_track").value-0;
  document.getElementById("tot_track").value =  ttrack+1;

  return false;
}

function removeRowFromTable(id)
{
	/**
  var tbl = document.getElementById('tblTrack');
  var lastRow = tbl.rows.length;
  var last_track_no = document.getElementById('last_track_no').value;
  var last_track_no = eval(last_track_no)+1;
  if (lastRow > last_track_no) tbl.deleteRow(lastRow - 1);
	
  var lastRow = tbl.rows.length;
  document.getElementById('tot_track').value = lastRow-1;**/
  var container = document.getElementById("track_"+id);
  container.parentNode.removeChild(container);

  var nid = document.getElementById("last_track_no").value;

  id++;
  while(id < nid)
  {
      if(document.getElementById("track_"+id))
	  {
		  var ele = document.getElementById("track_"+id);
		  eid = id-1;
		  ele.id = "track_"+eid;
		  ele.childNodes[3].childNodes[0].innerHTML = eid+".";
  		  document.getElementById("track_title"+id).name = "track_title"+eid;
  		  document.getElementById("track_isrc"+id).name = "track_isrc"+eid;
  		  document.getElementById("track_time"+id).name = "track_time"+eid;
		  document.getElementById("track_title"+id).id = "track_title"+eid;
  		  document.getElementById("track_isrc"+id).id = "track_isrc"+eid;
  		  document.getElementById("track_time"+id).id = "track_time"+eid;
		  ele.childNodes[7].childNodes[0].innerHTML = '<a href="#" onclick="return removeRowFromTable('+eid+');"><img src="../images/del_icon.png" border="0" /></a>';
			
      }
      id++;
  }



  document.getElementById("last_track_no").value = --nid;
  document.getElementById("licount").innerHTML = nid;

  var ttrack = document.getElementById("tot_track").value-0;
  document.getElementById("tot_track").value =  ttrack-1;

  return false;
}

function validateTrackRow(frm)
{
	var tbl = document.getElementById('tblTrack');
	var lastRow = tbl.rows.length - 1;
	var i;
	for (i=1; i<=lastRow; i++) {
	  var aRow = document.getElementById('track_title' + i);
	  if (aRow.value.length <= 0) {
		alert('Track Information Row ' + i + ' Title is empty!');
		return false;
	  }
	  var aRow1 = document.getElementById('track_isrc' + i);
	  if (aRow1.value.length <= 0) {
		alert('Track Information Row ' + i + ' ISRC is empty!');
		return false;
	  }
	  var aRow2 = document.getElementById('track_time' + i);
	  if (aRow2.value.length <= 0) {
		alert('Track Information Row ' + i + ' Time is empty!');
		return false;
	  }
	}
	return true;
}

