
 
 
function RemoveRow(table, row) {

	if(document.getElementById(table) != null){
		oTable = document.getElementById(table);
	}else if(window.opener.document.getElementById(table) != null){
		oTable = window.opener.document.getElementById(table);
	}else
		return false


	//find row
	found = 0;

	for(i=0; i < oTable.rows.length; i++){

		if(oTable.rows[i].id == row){
			oRow = oTable.deleteRow(i)
			break
		}		
	}
	
}


function RandomNumber() {
    var dt = new Date();
	var strText = new String(dt.getHours() + "" + dt.getMinutes() + "" +  dt.getSeconds() + "" + dt.getMilliseconds())
	return strText + Math.floor(Math.random()*999999999999999);
}

function addReserveDetail(flag){
	oTable = document.getElementById('TABLE_RES');
	row_number = oTable.rows.length-1
	oRow = oTable.insertRow(row_number)
	oRow.id = RandomNumber();

	oCell = oRow.insertCell(0);
	oCell.align = 'center';
	oCell.innerHTML = '<A HREF="javascript:;" onclick="if(confirm(\'Are you sure you want to remove this row\')){ RemoveRow(\'TABLE_RES\', \'' + oRow.id + '\'); price_update();}">Delete</A>';
	
	oCell = oRow.insertCell(1);
	oCell.align = 'center';
	oCell.id = 'cell_ticket_type'+row_number;
	
	if(flag == '1'){
		oCell.innerHTML = '<div align="center"><select name="ticket_type[]" id="ticket_type'+oRow.id+'" onchange="price_update()"><option value="3DA">3D-Adult</option><option value="3DC">3D-Child</option></select></div>';

	}else if(flag == '2'){
		oCell.innerHTML = '<div align="center"><select name="ticket_type[]" id="ticket_type'+oRow.id+'" onchange="price_update()"><option value="SPA">Special Price Adult</option><option value="SPC">Special Price Child</option></select></div>';

	}else{
		oCell.innerHTML = '<div align="center"><select name="ticket_type[]" id="ticket_type'+oRow.id+'" onchange="price_update()"><option value="A">Adult</option><option value="C">Child</option></select></div>';
	}



	oCell = oRow.insertCell(2);
	oCell.id = 'cell_seat_type'+row_number;
	oCell.innerHTML = '<div align="center"><select name="seat_type[]" id="seat_type'+oRow.id+'" onchange="price_update()"><option value="1">Regular</option><option value="2">Box</option></select></div>';
	
	oCell = oRow.insertCell(3);
	oCell.id = 'cell_quantity'+row_number;
	oCell.innerHTML = '<div align="center"><input name="quantity[]" type="text" id="quantity'+oRow.id+'" size="2" maxlength="2" onchange="price_update()"></div>';

	return oRow.id
	
}




function loadReserveDetail(ticket_type, seat_type, quantity, threeD_flag, sp_flag){
	oTable = document.getElementById('TABLE_RES');
	RemoveRow('TABLE_RES', '999999')	
	row_number = oTable.rows.length-1

	oRow = oTable.insertRow(row_number)
	oRow.id = RandomNumber();

	oCell = oRow.insertCell(0);
	oCell.align = 'center';
	if(row_number > 1)
		oCell.innerHTML = '<A HREF="javascript:;" onclick="if(confirm(\'Are you sure you want to remove this row\')){ RemoveRow(\'TABLE_RES\', \'' + oRow.id + '\'); price_update();}">Delete</A>';

	
	oCell = oRow.insertCell(1);
	oCell.align = 'center';
	var inner_HTML = '\n<select name="ticket_type[]" id="ticket_type'+oRow.id+'" onchange="price_update()">';


	if(ticket_type == 'A')
		inner_HTML += '\n<option value="A" selected>Adult</option>';
	else
		inner_HTML += '\n<option value="A">Adult</option>';

	if(ticket_type == 'C')
		inner_HTML += '\n<option value="C" selected>Child</option>';
	else
		inner_HTML += '\n<option value="C">Child</option>';

	if(threeD_flag == '1'){
		if(ticket_type == '3DA')
			inner_HTML += '\n<option value="3DA" selected>3D-Adult</option>';
		else
			inner_HTML += '\n<option value="3DA">3D-Adult</option>';

		if(ticket_type == '3DC')
			inner_HTML += '\n<option value="3DC" selected>3D-Child</option>';
		else
			inner_HTML += '\n<option value="3DC">3D-Child</option>';
	}

	if(sp_flag == '1'){
		if(ticket_type == 'SPA')
			inner_HTML += '\n<option value="SPA" selected>Special Price Adult</option>';
		else
			inner_HTML += '\n<option value="SPA">Special Price Adult</option>';

		if(ticket_type == 'SPC')
			inner_HTML += '\n<option value="SPC" selected>Special Price Child</option>';
		else
			inner_HTML += '\n<option value="SPC">Special Price Child</option>';
	}


	inner_HTML += '\n</select>\n\n';
	oCell.innerHTML = inner_HTML

	oCell = oRow.insertCell(2);
	oCell.align = 'center';
	inner_HTML = '\n<select name="seat_type[]" id="seat_type'+oRow.id+'" onchange="price_update()">';
	
	if(seat_type == '1')
		inner_HTML += '\n<option value="1" selected>Regular</option>';
	else
		inner_HTML += '\n<option value="1">Regular</option>';

	if(seat_type == '2')
		inner_HTML += '\n<option value="2" selected>Box</option>';
	else
		inner_HTML += '\n<option value="2">Box</option>';

	inner_HTML += '\n</select>\n\n';	
	oCell.innerHTML = inner_HTML
	
	oCell = oRow.insertCell(3);
	oCell.align = 'center';
	oCell.innerHTML = '\n<input value="'+quantity+'" name="quantity[]" type="text" id="quantity'+oRow.id+'" size="2" maxlength="2" onchange="price_update()">';
	
	return oRow.id
	
}

 
 
 function GetMovie(MovieURL){
  moviewin = window.open(MovieURL,"MY_WIN","toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=700")
 // moviewin.ScrollTo(170,80);

 }

 function GetActor(ActorURL){
  actwin = window.open(ActorURL,"MY_WIN","toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=700")
 // actwin.ScrollTo(170,80);

 }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}


function y2k(number)
{
  return (number < 1000) ? number + 1900 : number;
}


function isValidDate (day,month,year)
{
  // checks if date passed is valid
 
    var today = new Date();
    year = ((!year) ? y2k(today.getFullYear()):year);
	month = ((!month) ? today.getMonth():month-1);
  

    if (!day) return false


    var test = new Date(year,month,day);
    if ( (y2k(test.getFullYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false

}




function replaceCarriageReturn(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceCarriageReturn(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function trim(strText) { 

    strText = replaceCarriageReturn(replaceCarriageReturn(strText,'\r',''),'\n','');

	// this will get rid of leading spaces 
    while ((strText.substring(0,1) == ' ')||(strText.substring(0,2) == '\r')) 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while ((strText.substring(strText.length-1,strText.length) == ' ')||(strText.substring(strText.length-2,strText.length) == '\r'))
        strText = strText.substring(0, strText.length-1);

   return strText;
} 


function is_empty(form, field)
{
  form.field.value = trim(form.field.value);
  if ( (temp_str == null) || (temp_str == " ") || (temp_str == '\t') || (temp_str == "") )
	return true;
  else
	return false;
}


function mOvr(src,colorOver){ 
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'hand'; 
		src.bgColor = colorOver; 
	} 
} 
function mOut(src,colorIn){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.bgColor = colorIn; 
	} 
} 
function mClk(src){ 
	if(event.srcElement.tagName=='TD')
		src.children.tags('A')[0].click();
}

function confirmLogout()
{
  if (confirm("Are you sure you want to log out?"))
  {
	  document.location.href = "logout.dti"
  }
}

